Skip to content

Commit dae5bce

Browse files
Rollup merge of rust-lang#158223 - JonathanBrouwer:lang-target, r=mejrs
Move target checking for #[lang] to the attribute parser Work towards removing the `ALL_TARGETS` list. r? @mejrs
2 parents e677674 + 9ad6dbf commit dae5bce

59 files changed

Lines changed: 286 additions & 278 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl CombineAttributeParser for AllowInternalUnstableParser {
1111
type Item = (Symbol, Span);
1212
const CONVERT: ConvertFn<Self::Item> =
1313
|items, span| AttributeKind::AllowInternalUnstable(items, span);
14-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
14+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
1515
Allow(Target::MacroDef),
1616
Allow(Target::Fn),
1717
Warn(Target::Field),
@@ -36,7 +36,7 @@ impl CombineAttributeParser for UnstableFeatureBoundParser {
3636
type Item = (Symbol, Span);
3737
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::UnstableFeatureBound(items);
3838
const STABILITY: AttributeStability = unstable!(staged_api);
39-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
39+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
4040
Allow(Target::Fn),
4141
Allow(Target::Impl { of_trait: true }),
4242
Allow(Target::Trait),
@@ -59,7 +59,7 @@ impl CombineAttributeParser for RustcAllowConstFnUnstableParser {
5959
type Item = Symbol;
6060
const CONVERT: ConvertFn<Self::Item> =
6161
|items, first_span| AttributeKind::RustcAllowConstFnUnstable(items, first_span);
62-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
62+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
6363
Allow(Target::Fn),
6464
Allow(Target::Method(MethodKind::Inherent)),
6565
Allow(Target::Method(MethodKind::Trait { body: true })),

compiler/rustc_attr_parsing/src/attributes/autodiff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) struct RustcAutodiffParser;
1919

2020
impl SingleAttributeParser for RustcAutodiffParser {
2121
const PATH: &[Symbol] = &[sym::rustc_autodiff];
22-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
22+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
2323
Allow(Target::Fn),
2424
Allow(Target::Method(MethodKind::Inherent)),
2525
Allow(Target::Method(MethodKind::Trait { body: true })),

compiler/rustc_attr_parsing/src/attributes/body.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ pub(crate) struct CoroutineParser;
88

99
impl NoArgsAttributeParser for CoroutineParser {
1010
const PATH: &[Symbol] = &[sym::coroutine];
11-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Closure)]);
11+
const ALLOWED_TARGETS: AllowedTargets<'_> =
12+
AllowedTargets::AllowList(&[Allow(Target::Closure)]);
1213
const STABILITY: AttributeStability = unstable!(coroutines);
1314
const CREATE: fn(rustc_span::Span) -> AttributeKind = |_| AttributeKind::Coroutine;
1415
}

compiler/rustc_attr_parsing/src/attributes/cfi_encoding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::prelude::*;
44
pub(crate) struct CfiEncodingParser;
55
impl SingleAttributeParser for CfiEncodingParser {
66
const PATH: &[Symbol] = &[sym::cfi_encoding];
7-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
7+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
88
Allow(Target::Struct),
99
Allow(Target::ForeignTy),
1010
Allow(Target::Enum),

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(crate) struct OptimizeParser;
1818

1919
impl SingleAttributeParser for OptimizeParser {
2020
const PATH: &[Symbol] = &[sym::optimize];
21-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
21+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
2222
Allow(Target::Fn),
2323
Allow(Target::Closure),
2424
Allow(Target::Method(MethodKind::Trait { body: true })),
@@ -51,7 +51,7 @@ pub(crate) struct ColdParser;
5151
impl NoArgsAttributeParser for ColdParser {
5252
const PATH: &[Symbol] = &[sym::cold];
5353
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
54-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
54+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
5555
Allow(Target::Fn),
5656
Allow(Target::Method(MethodKind::Trait { body: true })),
5757
Allow(Target::Method(MethodKind::TraitImpl)),
@@ -67,7 +67,7 @@ pub(crate) struct CoverageParser;
6767

6868
impl SingleAttributeParser for CoverageParser {
6969
const PATH: &[Symbol] = &[sym::coverage];
70-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
70+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
7171
Allow(Target::Fn),
7272
Allow(Target::Closure),
7373
Allow(Target::Method(MethodKind::Trait { body: true })),
@@ -114,7 +114,7 @@ impl SingleAttributeParser for ExportNameParser {
114114
note: "the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them",
115115
unsafe_since: Some(Edition2024),
116116
};
117-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
117+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
118118
Allow(Target::Static),
119119
Allow(Target::Fn),
120120
Allow(Target::Method(MethodKind::Inherent)),
@@ -151,7 +151,7 @@ pub(crate) struct RustcObjcClassParser;
151151

152152
impl SingleAttributeParser for RustcObjcClassParser {
153153
const PATH: &[rustc_span::Symbol] = &[sym::rustc_objc_class];
154-
const ALLOWED_TARGETS: AllowedTargets =
154+
const ALLOWED_TARGETS: AllowedTargets<'_> =
155155
AllowedTargets::AllowList(&[Allow(Target::ForeignStatic)]);
156156
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "ClassName");
157157
const STABILITY: AttributeStability = unstable!(rustc_attrs);
@@ -179,7 +179,7 @@ pub(crate) struct RustcObjcSelectorParser;
179179

180180
impl SingleAttributeParser for RustcObjcSelectorParser {
181181
const PATH: &[rustc_span::Symbol] = &[sym::rustc_objc_selector];
182-
const ALLOWED_TARGETS: AllowedTargets =
182+
const ALLOWED_TARGETS: AllowedTargets<'_> =
183183
AllowedTargets::AllowList(&[Allow(Target::ForeignStatic)]);
184184
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "methodName");
185185
const STABILITY: AttributeStability = unstable!(rustc_attrs);
@@ -226,7 +226,7 @@ impl AttributeParser for NakedParser {
226226
note: "the `#[naked]` attribute adds the safety obligation that the function's body must respect the function’s calling convention, uphold its signature, and either return or diverge (i.e., not fall through past the end of the assembly code).",
227227
unsafe_since: None,
228228
};
229-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
229+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
230230
Allow(Target::Fn),
231231
Allow(Target::Method(MethodKind::Inherent)),
232232
Allow(Target::Method(MethodKind::Trait { body: true })),
@@ -334,7 +334,7 @@ pub(crate) struct TrackCallerParser;
334334
impl NoArgsAttributeParser for TrackCallerParser {
335335
const PATH: &[Symbol] = &[sym::track_caller];
336336
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
337-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
337+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
338338
Allow(Target::Fn),
339339
Allow(Target::Method(MethodKind::Inherent)),
340340
Allow(Target::Method(MethodKind::Trait { body: true })),
@@ -359,7 +359,7 @@ impl NoArgsAttributeParser for NoMangleParser {
359359
note: "the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them",
360360
unsafe_since: Some(Edition2024),
361361
};
362-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
362+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
363363
Allow(Target::Fn),
364364
Allow(Target::Static),
365365
Allow(Target::Method(MethodKind::Inherent)),
@@ -462,7 +462,7 @@ impl AttributeParser for UsedParser {
462462
}
463463
},
464464
)];
465-
const ALLOWED_TARGETS: AllowedTargets =
465+
const ALLOWED_TARGETS: AllowedTargets<'_> =
466466
AllowedTargets::AllowList(&[Allow(Target::Static), Warn(Target::MacroCall)]);
467467

468468
fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
@@ -533,7 +533,7 @@ impl CombineAttributeParser for TargetFeatureParser {
533533
parse_tf_attribute(cx, args)
534534
}
535535

536-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
536+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
537537
Allow(Target::Fn),
538538
Allow(Target::Method(MethodKind::Inherent)),
539539
Allow(Target::Method(MethodKind::Trait { body: true })),
@@ -561,7 +561,7 @@ impl CombineAttributeParser for ForceTargetFeatureParser {
561561
was_forced: true,
562562
};
563563
const TEMPLATE: AttributeTemplate = template!(List: &["enable = \"feat1, feat2\""]);
564-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
564+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
565565
Allow(Target::Fn),
566566
Allow(Target::Method(MethodKind::Inherent)),
567567
Allow(Target::Method(MethodKind::Trait { body: true })),
@@ -581,7 +581,7 @@ pub(crate) struct InstrumentFnParser;
581581

582582
impl SingleAttributeParser for InstrumentFnParser {
583583
const PATH: &[Symbol] = &[sym::instrument_fn];
584-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
584+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
585585
Allow(Target::Fn),
586586
Allow(Target::Method(MethodKind::Inherent)),
587587
Allow(Target::Method(MethodKind::Trait { body: true })),
@@ -619,7 +619,7 @@ pub(crate) struct SanitizeParser;
619619

620620
impl SingleAttributeParser for SanitizeParser {
621621
const PATH: &[Symbol] = &[sym::sanitize];
622-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
622+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
623623
Allow(Target::Fn),
624624
Allow(Target::Closure),
625625
Allow(Target::Method(MethodKind::Inherent)),
@@ -751,7 +751,7 @@ pub(crate) struct ThreadLocalParser;
751751

752752
impl NoArgsAttributeParser for ThreadLocalParser {
753753
const PATH: &[Symbol] = &[sym::thread_local];
754-
const ALLOWED_TARGETS: AllowedTargets =
754+
const ALLOWED_TARGETS: AllowedTargets<'_> =
755755
AllowedTargets::AllowList(&[Allow(Target::Static), Allow(Target::ForeignStatic)]);
756756
const STABILITY: AttributeStability = unstable!(thread_local);
757757
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ThreadLocal;
@@ -761,7 +761,7 @@ pub(crate) struct RustcPassIndirectlyInNonRusticAbisParser;
761761

762762
impl NoArgsAttributeParser for RustcPassIndirectlyInNonRusticAbisParser {
763763
const PATH: &[Symbol] = &[sym::rustc_pass_indirectly_in_non_rustic_abis];
764-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Struct)]);
764+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Struct)]);
765765
const STABILITY: AttributeStability = unstable!(rustc_attrs);
766766
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcPassIndirectlyInNonRusticAbis;
767767
}
@@ -770,7 +770,7 @@ pub(crate) struct RustcEiiForeignItemParser;
770770

771771
impl NoArgsAttributeParser for RustcEiiForeignItemParser {
772772
const PATH: &[Symbol] = &[sym::rustc_eii_foreign_item];
773-
const ALLOWED_TARGETS: AllowedTargets =
773+
const ALLOWED_TARGETS: AllowedTargets<'_> =
774774
AllowedTargets::AllowList(&[Allow(Target::ForeignFn), Allow(Target::ForeignStatic)]);
775775
const STABILITY: AttributeStability = unstable!(eii_internals);
776776
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcEiiForeignItem;
@@ -780,7 +780,7 @@ pub(crate) struct PatchableFunctionEntryParser;
780780

781781
impl SingleAttributeParser for PatchableFunctionEntryParser {
782782
const PATH: &[Symbol] = &[sym::patchable_function_entry];
783-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
783+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
784784
const TEMPLATE: AttributeTemplate = template!(List: &["prefix_nops = m, entry_nops = n"]);
785785
const STABILITY: AttributeStability = unstable!(patchable_function_entry);
786786

compiler/rustc_attr_parsing/src/attributes/confusables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl AttributeParser for ConfusablesParser {
3232
this.first_span.get_or_insert(cx.attr_span);
3333
},
3434
)];
35-
const ALLOWED_TARGETS: AllowedTargets =
35+
const ALLOWED_TARGETS: AllowedTargets<'_> =
3636
AllowedTargets::AllowList(&[Allow(Target::Method(MethodKind::Inherent))]);
3737

3838
fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {

0 commit comments

Comments
 (0)