@@ -207,6 +207,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
207207 Attribute :: Parsed ( AttributeKind :: ConstContinue ( attr_span) ) => {
208208 self . check_const_continue ( hir_id, * attr_span, target)
209209 }
210+ Attribute :: Parsed ( AttributeKind :: AllowInternalUnsafe ( attr_span) ) => {
211+ self . check_allow_internal_unsafe ( hir_id, * attr_span, span, target, attrs)
212+ }
210213 Attribute :: Parsed ( AttributeKind :: AllowInternalUnstable ( _, first_span) ) => {
211214 self . check_allow_internal_unstable ( hir_id, * first_span, span, target, attrs)
212215 }
@@ -415,7 +418,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
415418 // internal
416419 | sym:: prelude_import
417420 | sym:: panic_handler
418- | sym:: allow_internal_unsafe
419421 | sym:: lang
420422 | sym:: needs_allocator
421423 | sym:: default_lib_allocator
@@ -2214,14 +2216,49 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22142216
22152217 /// Outputs an error for `#[allow_internal_unstable]` which can only be applied to macros.
22162218 /// (Allows proc_macro functions)
2217- // FIXME(jdonszelmann): if possible, move to attr parsing
22182219 fn check_allow_internal_unstable (
22192220 & self ,
22202221 hir_id : HirId ,
22212222 attr_span : Span ,
22222223 span : Span ,
22232224 target : Target ,
22242225 attrs : & [ Attribute ] ,
2226+ ) {
2227+ self . check_macro_only_attr (
2228+ hir_id,
2229+ attr_span,
2230+ span,
2231+ target,
2232+ attrs,
2233+ "allow_internal_unstable" ,
2234+ )
2235+ }
2236+
2237+ /// Outputs an error for `#[allow_internal_unsafe]` which can only be applied to macros.
2238+ /// (Allows proc_macro functions)
2239+ fn check_allow_internal_unsafe (
2240+ & self ,
2241+ hir_id : HirId ,
2242+ attr_span : Span ,
2243+ span : Span ,
2244+ target : Target ,
2245+ attrs : & [ Attribute ] ,
2246+ ) {
2247+ self . check_macro_only_attr ( hir_id, attr_span, span, target, attrs, "allow_internal_unsafe" )
2248+ }
2249+
2250+ /// Outputs an error for attributes that can only be applied to macros, such as
2251+ /// `#[allow_internal_unsafe]` and `#[allow_internal_unstable]`.
2252+ /// (Allows proc_macro functions)
2253+ // FIXME(jdonszelmann): if possible, move to attr parsing
2254+ fn check_macro_only_attr (
2255+ & self ,
2256+ hir_id : HirId ,
2257+ attr_span : Span ,
2258+ span : Span ,
2259+ target : Target ,
2260+ attrs : & [ Attribute ] ,
2261+ attr_name : & str ,
22252262 ) {
22262263 match target {
22272264 Target :: Fn => {
@@ -2240,18 +2277,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22402277 // erroneously allowed it and some crates used it accidentally, to be compatible
22412278 // with crates depending on them, we can't throw an error here.
22422279 Target :: Field | Target :: Arm => {
2243- self . inline_attr_str_error_without_macro_def (
2244- hir_id,
2245- attr_span,
2246- "allow_internal_unstable" ,
2247- ) ;
2280+ self . inline_attr_str_error_without_macro_def ( hir_id, attr_span, attr_name) ;
22482281 return ;
22492282 }
22502283 // otherwise continue out of the match
22512284 _ => { }
22522285 }
22532286
2254- self . tcx . dcx ( ) . emit_err ( errors:: AllowInternalUnstable { attr_span, span } ) ;
2287+ self . tcx . dcx ( ) . emit_err ( errors:: MacroOnlyAttribute { attr_span, span } ) ;
22552288 }
22562289
22572290 /// Checks if the items on the `#[debugger_visualizer]` attribute are valid.
0 commit comments