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