@@ -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                } 
@@ -413,7 +416,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
413416                            // internal 
414417                            | sym:: prelude_import
415418                            | sym:: panic_handler
416-                             | sym:: allow_internal_unsafe
417419                            | sym:: lang
418420                            | sym:: needs_allocator
419421                            | sym:: default_lib_allocator
@@ -2211,14 +2213,49 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22112213
22122214    /// Outputs an error for `#[allow_internal_unstable]` which can only be applied to macros. 
22132215/// (Allows proc_macro functions) 
2214- // FIXME(jdonszelmann): if possible, move to attr parsing 
22152216fn  check_allow_internal_unstable ( 
22162217        & self , 
22172218        hir_id :  HirId , 
22182219        attr_span :  Span , 
22192220        span :  Span , 
22202221        target :  Target , 
22212222        attrs :  & [ Attribute ] , 
2223+     )  { 
2224+         self . check_macro_only_attr ( 
2225+             hir_id, 
2226+             attr_span, 
2227+             span, 
2228+             target, 
2229+             attrs, 
2230+             "allow_internal_unstable" , 
2231+         ) 
2232+     } 
2233+ 
2234+     /// Outputs an error for `#[allow_internal_unsafe]` which can only be applied to macros. 
2235+ /// (Allows proc_macro functions) 
2236+ fn  check_allow_internal_unsafe ( 
2237+         & self , 
2238+         hir_id :  HirId , 
2239+         attr_span :  Span , 
2240+         span :  Span , 
2241+         target :  Target , 
2242+         attrs :  & [ Attribute ] , 
2243+     )  { 
2244+         self . check_macro_only_attr ( hir_id,  attr_span,  span,  target,  attrs,  "allow_internal_unsafe" ) 
2245+     } 
2246+ 
2247+     /// Outputs an error for attributes that can only be applied to macros, such as 
2248+ /// `#[allow_internal_unsafe]` and `#[allow_internal_unstable]`. 
2249+ /// (Allows proc_macro functions) 
2250+ // FIXME(jdonszelmann): if possible, move to attr parsing 
2251+     fn  check_macro_only_attr ( 
2252+         & self , 
2253+         hir_id :  HirId , 
2254+         attr_span :  Span , 
2255+         span :  Span , 
2256+         target :  Target , 
2257+         attrs :  & [ Attribute ] , 
2258+         attr_name :  & str , 
22222259    )  { 
22232260        match  target { 
22242261            Target :: Fn  => { 
@@ -2237,18 +2274,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22372274            // erroneously allowed it and some crates used it accidentally, to be compatible 
22382275            // with crates depending on them, we can't throw an error here. 
22392276            Target :: Field  | Target :: Arm  => { 
2240-                 self . inline_attr_str_error_without_macro_def ( 
2241-                     hir_id, 
2242-                     attr_span, 
2243-                     "allow_internal_unstable" , 
2244-                 ) ; 
2277+                 self . inline_attr_str_error_without_macro_def ( hir_id,  attr_span,  attr_name) ; 
22452278                return ; 
22462279            } 
22472280            // otherwise continue out of the match 
22482281            _ => { } 
22492282        } 
22502283
2251-         self . tcx . dcx ( ) . emit_err ( errors:: AllowInternalUnstable  {  attr_span,  span } ) ; 
2284+         self . tcx . dcx ( ) . emit_err ( errors:: MacroOnlyAttribute  {  attr_span,  span } ) ; 
22522285    } 
22532286
22542287    /// Checks if the items on the `#[debugger_visualizer]` attribute are valid. 
0 commit comments