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