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