@@ -207,6 +207,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
207
207
Attribute :: Parsed ( AttributeKind :: ConstContinue ( attr_span) ) => {
208
208
self . check_const_continue ( hir_id, * attr_span, target)
209
209
}
210
+ Attribute :: Parsed ( AttributeKind :: AllowInternalUnsafe ( attr_span) ) => {
211
+ self . check_allow_internal_unsafe ( hir_id, * attr_span, span, target, attrs)
212
+ }
210
213
Attribute :: Parsed ( AttributeKind :: AllowInternalUnstable ( _, first_span) ) => {
211
214
self . check_allow_internal_unstable ( hir_id, * first_span, span, target, attrs)
212
215
}
@@ -415,7 +418,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
415
418
// internal
416
419
| sym:: prelude_import
417
420
| sym:: panic_handler
418
- | sym:: allow_internal_unsafe
419
421
| sym:: lang
420
422
| sym:: needs_allocator
421
423
| sym:: default_lib_allocator
@@ -2214,14 +2216,49 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2214
2216
2215
2217
/// Outputs an error for `#[allow_internal_unstable]` which can only be applied to macros.
2216
2218
/// (Allows proc_macro functions)
2217
- // FIXME(jdonszelmann): if possible, move to attr parsing
2218
2219
fn check_allow_internal_unstable (
2219
2220
& self ,
2220
2221
hir_id : HirId ,
2221
2222
attr_span : Span ,
2222
2223
span : Span ,
2223
2224
target : Target ,
2224
2225
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 ,
2225
2262
) {
2226
2263
match target {
2227
2264
Target :: Fn => {
@@ -2240,18 +2277,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2240
2277
// erroneously allowed it and some crates used it accidentally, to be compatible
2241
2278
// with crates depending on them, we can't throw an error here.
2242
2279
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) ;
2248
2281
return ;
2249
2282
}
2250
2283
// otherwise continue out of the match
2251
2284
_ => { }
2252
2285
}
2253
2286
2254
- self . tcx . dcx ( ) . emit_err ( errors:: AllowInternalUnstable { attr_span, span } ) ;
2287
+ self . tcx . dcx ( ) . emit_err ( errors:: MacroOnlyAttribute { attr_span, span } ) ;
2255
2288
}
2256
2289
2257
2290
/// Checks if the items on the `#[debugger_visualizer]` attribute are valid.
0 commit comments