@@ -10,7 +10,7 @@ use std::collections::hash_map::Entry;
10
10
11
11
use rustc_abi:: { Align , ExternAbi , Size } ;
12
12
use rustc_ast:: { AttrStyle , LitKind , MetaItemInner , MetaItemKind , MetaItemLit , ast} ;
13
- use rustc_attr_parsing:: { AttributeKind , ReprAttr , find_attr} ;
13
+ use rustc_attr_parsing:: { AttributeKind , InlineAttr , ReprAttr , find_attr} ;
14
14
use rustc_data_structures:: fx:: FxHashMap ;
15
15
use rustc_errors:: { Applicability , DiagCtxtHandle , IntoDiagArg , MultiSpan , StashKey } ;
16
16
use rustc_feature:: { AttributeDuplicates , AttributeType , BUILTIN_ATTRIBUTE_MAP , BuiltinAttribute } ;
@@ -124,6 +124,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
124
124
AttributeKind :: Stability { span, .. }
125
125
| AttributeKind :: ConstStability { span, .. } ,
126
126
) => self . check_stability_promotable ( * span, target) ,
127
+ Attribute :: Parsed ( AttributeKind :: Inline ( _, attr_span) ) => {
128
+ self . check_inline ( hir_id, * attr_span, span, target)
129
+ }
127
130
Attribute :: Parsed ( AttributeKind :: AllowInternalUnstable ( syms) ) => self
128
131
. check_allow_internal_unstable (
129
132
hir_id,
@@ -140,7 +143,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
140
143
[ sym:: diagnostic, sym:: on_unimplemented, ..] => {
141
144
self . check_diagnostic_on_unimplemented ( attr. span ( ) , hir_id, target)
142
145
}
143
- [ sym:: inline, ..] => self . check_inline ( hir_id, attr, span, target) ,
144
146
[ sym:: coverage, ..] => self . check_coverage ( attr, span, target) ,
145
147
[ sym:: optimize, ..] => self . check_optimize ( hir_id, attr, span, target) ,
146
148
[ sym:: no_sanitize, ..] => {
@@ -351,11 +353,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
351
353
self . check_rustc_force_inline ( hir_id, attrs, span, target) ;
352
354
}
353
355
354
- fn inline_attr_str_error_with_macro_def ( & self , hir_id : HirId , attr : & Attribute , sym : & str ) {
356
+ fn inline_attr_str_error_with_macro_def ( & self , hir_id : HirId , attr_span : Span , sym : & str ) {
355
357
self . tcx . emit_node_span_lint (
356
358
UNUSED_ATTRIBUTES ,
357
359
hir_id,
358
- attr . span ( ) ,
360
+ attr_span ,
359
361
errors:: IgnoredAttrWithMacro { sym } ,
360
362
) ;
361
363
}
@@ -415,7 +417,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
415
417
}
416
418
417
419
/// Checks if an `#[inline]` is applied to a function or a closure.
418
- fn check_inline ( & self , hir_id : HirId , attr : & Attribute , span : Span , target : Target ) {
420
+ fn check_inline ( & self , hir_id : HirId , attr_span : Span , defn_span : Span , target : Target ) {
419
421
match target {
420
422
Target :: Fn
421
423
| Target :: Closure
@@ -424,7 +426,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
424
426
self . tcx . emit_node_span_lint (
425
427
UNUSED_ATTRIBUTES ,
426
428
hir_id,
427
- attr . span ( ) ,
429
+ attr_span ,
428
430
errors:: IgnoredInlineAttrFnProto ,
429
431
)
430
432
}
@@ -435,18 +437,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
435
437
Target :: AssocConst => self . tcx . emit_node_span_lint (
436
438
UNUSED_ATTRIBUTES ,
437
439
hir_id,
438
- attr . span ( ) ,
440
+ attr_span ,
439
441
errors:: IgnoredInlineAttrConstants ,
440
442
) ,
441
443
// FIXME(#80564): Same for fields, arms, and macro defs
442
444
Target :: Field | Target :: Arm | Target :: MacroDef => {
443
- self . inline_attr_str_error_with_macro_def ( hir_id, attr , "inline" )
445
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr_span , "inline" )
444
446
}
445
447
_ => {
446
- self . dcx ( ) . emit_err ( errors:: InlineNotFnOrClosure {
447
- attr_span : attr. span ( ) ,
448
- defn_span : span,
449
- } ) ;
448
+ self . dcx ( ) . emit_err ( errors:: InlineNotFnOrClosure { attr_span, defn_span } ) ;
450
449
}
451
450
}
452
451
}
@@ -640,7 +639,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
640
639
// erroneously allowed it and some crates used it accidentally, to be compatible
641
640
// with crates depending on them, we can't throw an error here.
642
641
Target :: Field | Target :: Arm | Target :: MacroDef => {
643
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "naked" )
642
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr. span ( ) , "naked" )
644
643
}
645
644
_ => {
646
645
self . dcx ( ) . emit_err ( errors:: AttrShouldBeAppliedToFn {
@@ -718,7 +717,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
718
717
// with crates depending on them, we can't throw an error here.
719
718
Target :: Field | Target :: Arm | Target :: MacroDef => {
720
719
for attr in attrs {
721
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "track_caller" ) ;
720
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr. span ( ) , "track_caller" ) ;
722
721
}
723
722
}
724
723
_ => {
@@ -761,7 +760,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
761
760
// erroneously allowed it and some crates used it accidentally, to be compatible
762
761
// with crates depending on them, we can't throw an error here.
763
762
Target :: Field | Target :: Arm | Target :: MacroDef => {
764
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "non_exhaustive" ) ;
763
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr. span ( ) , "non_exhaustive" ) ;
765
764
}
766
765
_ => {
767
766
self . dcx ( ) . emit_err ( errors:: NonExhaustiveWrongLocation {
@@ -781,7 +780,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
781
780
// erroneously allowed it and some crates used it accidentally, to be compatible
782
781
// with crates depending on them, we can't throw an error here.
783
782
Target :: Field | Target :: Arm | Target :: MacroDef => {
784
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "marker" ) ;
783
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr. span ( ) , "marker" ) ;
785
784
}
786
785
_ => {
787
786
self . dcx ( ) . emit_err ( errors:: AttrShouldBeAppliedToTrait {
@@ -835,7 +834,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
835
834
// erroneously allowed it and some crates used it accidentally, to be compatible
836
835
// with crates depending on them, we can't throw an error here.
837
836
Target :: Field | Target :: Arm | Target :: MacroDef => {
838
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "target_feature" ) ;
837
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr. span ( ) , "target_feature" ) ;
839
838
}
840
839
_ => {
841
840
self . dcx ( ) . emit_err ( errors:: AttrShouldBeAppliedToFn {
@@ -1546,7 +1545,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1546
1545
// erroneously allowed it and some crates used it accidentally, to be compatible
1547
1546
// with crates depending on them, we can't throw an error here.
1548
1547
Target :: Field | Target :: Arm | Target :: MacroDef => {
1549
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "cold" ) ;
1548
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr. span ( ) , "cold" ) ;
1550
1549
}
1551
1550
_ => {
1552
1551
// FIXME: #[cold] was previously allowed on non-functions and some crates used
@@ -1588,7 +1587,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1588
1587
// erroneously allowed it and some crates used it accidentally, to be compatible
1589
1588
// with crates depending on them, we can't throw an error here.
1590
1589
Target :: Field | Target :: Arm | Target :: MacroDef => {
1591
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "link_name" ) ;
1590
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr. span ( ) , "link_name" ) ;
1592
1591
}
1593
1592
_ => {
1594
1593
// FIXME: #[cold] was previously allowed on non-functions/statics and some crates
@@ -1622,7 +1621,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1622
1621
// erroneously allowed it and some crates used it accidentally, to be compatible
1623
1622
// with crates depending on them, we can't throw an error here.
1624
1623
Target :: Field | Target :: Arm | Target :: MacroDef => {
1625
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "no_link" ) ;
1624
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr. span ( ) , "no_link" ) ;
1626
1625
}
1627
1626
_ => {
1628
1627
self . dcx ( ) . emit_err ( errors:: NoLink { attr_span : attr. span ( ) , span } ) ;
@@ -1644,7 +1643,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1644
1643
// erroneously allowed it and some crates used it accidentally, to be compatible
1645
1644
// with crates depending on them, we can't throw an error here.
1646
1645
Target :: Field | Target :: Arm | Target :: MacroDef => {
1647
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "export_name" ) ;
1646
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr. span ( ) , "export_name" ) ;
1648
1647
}
1649
1648
_ => {
1650
1649
self . dcx ( ) . emit_err ( errors:: ExportName { attr_span : attr. span ( ) , span } ) ;
@@ -1818,7 +1817,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1818
1817
// erroneously allowed it and some crates used it accidentally, to be compatible
1819
1818
// with crates depending on them, we can't throw an error here.
1820
1819
Target :: Field | Target :: Arm | Target :: MacroDef => {
1821
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "link_section" ) ;
1820
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr. span ( ) , "link_section" ) ;
1822
1821
}
1823
1822
_ => {
1824
1823
// FIXME: #[link_section] was previously allowed on non-functions/statics and some
@@ -1843,7 +1842,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1843
1842
// erroneously allowed it and some crates used it accidentally, to be compatible
1844
1843
// with crates depending on them, we can't throw an error here.
1845
1844
Target :: Field | Target :: Arm | Target :: MacroDef => {
1846
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "no_mangle" ) ;
1845
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr. span ( ) , "no_mangle" ) ;
1847
1846
}
1848
1847
// FIXME: #[no_mangle] was previously allowed on non-functions/statics, this should be an error
1849
1848
// The error should specify that the item that is wrong is specifically a *foreign* fn/static
@@ -2190,9 +2189,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2190
2189
// `#[allow_internal_unstable]` attribute with just a lint, because we previously
2191
2190
// erroneously allowed it and some crates used it accidentally, to be compatible
2192
2191
// with crates depending on them, we can't throw an error here.
2193
- Target :: Field | Target :: Arm | Target :: MacroDef => {
2194
- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "allow_internal_unstable" )
2195
- }
2192
+ Target :: Field | Target :: Arm | Target :: MacroDef => self
2193
+ . inline_attr_str_error_with_macro_def (
2194
+ hir_id,
2195
+ attr. span ( ) ,
2196
+ "allow_internal_unstable" ,
2197
+ ) ,
2196
2198
_ => {
2197
2199
self . tcx
2198
2200
. dcx ( )
@@ -2568,8 +2570,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2568
2570
span : Span ,
2569
2571
target : Target ,
2570
2572
) {
2571
- let force_inline_attr = attrs. iter ( ) . find ( |attr| attr. has_name ( sym:: rustc_force_inline) ) ;
2572
- match ( target, force_inline_attr) {
2573
+ match (
2574
+ target,
2575
+ find_attr ! ( attrs, AttributeKind :: Inline ( InlineAttr :: Force { attr_span, .. } , _) => * attr_span) ,
2576
+ ) {
2573
2577
( Target :: Closure , None ) => {
2574
2578
let is_coro = matches ! (
2575
2579
self . tcx. hir( ) . expect_expr( hir_id) . kind,
@@ -2581,20 +2585,19 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2581
2585
) ;
2582
2586
let parent_did = self . tcx . hir_get_parent_item ( hir_id) . to_def_id ( ) ;
2583
2587
let parent_span = self . tcx . def_span ( parent_did) ;
2584
- let parent_force_inline_attr =
2585
- self . tcx . get_attr ( parent_did, sym:: rustc_force_inline) ;
2586
- if let Some ( attr) = parent_force_inline_attr
2587
- && is_coro
2588
+
2589
+ if let Some ( attr_span) = find_attr ! (
2590
+ self . tcx. get_all_attrs( parent_did) ,
2591
+ AttributeKind :: Inline ( InlineAttr :: Force { attr_span, .. } , _) => * attr_span
2592
+ ) && is_coro
2588
2593
{
2589
- self . dcx ( ) . emit_err ( errors:: RustcForceInlineCoro {
2590
- attr_span : attr. span ( ) ,
2591
- span : parent_span,
2592
- } ) ;
2594
+ self . dcx ( )
2595
+ . emit_err ( errors:: RustcForceInlineCoro { attr_span, span : parent_span } ) ;
2593
2596
}
2594
2597
}
2595
2598
( Target :: Fn , _) => ( ) ,
2596
- ( _, Some ( attr ) ) => {
2597
- self . dcx ( ) . emit_err ( errors:: RustcForceInline { attr_span : attr . span ( ) , span } ) ;
2599
+ ( _, Some ( attr_span ) ) => {
2600
+ self . dcx ( ) . emit_err ( errors:: RustcForceInline { attr_span, span } ) ;
2598
2601
}
2599
2602
( _, None ) => ( ) ,
2600
2603
}
@@ -2816,10 +2819,8 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
2816
2819
fn check_non_exported_macro_for_invalid_attrs ( tcx : TyCtxt < ' _ > , item : & Item < ' _ > ) {
2817
2820
let attrs = tcx. hir ( ) . attrs ( item. hir_id ( ) ) ;
2818
2821
2819
- for attr in attrs {
2820
- if attr. has_name ( sym:: inline) {
2821
- tcx. dcx ( ) . emit_err ( errors:: NonExportedMacroInvalidAttrs { attr_span : attr. span ( ) } ) ;
2822
- }
2822
+ if let Some ( attr_span) = find_attr ! ( attrs, AttributeKind :: Inline ( _, span) => * span) {
2823
+ tcx. dcx ( ) . emit_err ( errors:: NonExportedMacroInvalidAttrs { attr_span } ) ;
2823
2824
}
2824
2825
}
2825
2826
@@ -2839,6 +2840,7 @@ pub(crate) fn provide(providers: &mut Providers) {
2839
2840
* providers = Providers { check_mod_attrs, ..* providers } ;
2840
2841
}
2841
2842
2843
+ // FIXME(jdonszelmann): remove, check during parsing
2842
2844
fn check_duplicates (
2843
2845
tcx : TyCtxt < ' _ > ,
2844
2846
attr : & Attribute ,
0 commit comments