Skip to content

Commit 23e2734

Browse files
Rollup merge of #153300 - fmease:test-attrs-tweaks, r=JonathanBrouwer
Tweak some of our internal `#[rustc_*]` TEST attributes I think I might be the one who's used the internal TEST attrs `#[rustc_{dump_predicates,object_lifetime_default,outlives,variance}]` the most in recent times, I might even be the only one. As such I've noticed some recent-ish issues that haven't been fixed so far and which keep bothering me. Moreover I have a longstanding urge to rename several of these attributes which I couldn't contain anymore. [`#[rustc_*]` TEST attributes](https://rustc-dev-guide.rust-lang.org/compiler-debugging.html#rustc_-test-attributes) are internal attributes that basically allow you to dump the output of specific queries for use in UI tests or for debugging purposes. 1. When some of these attributes were ported over to the new parsing API, their targets were unnecessarily restricted. I've kept encountering these incorrect "attribute cannot be used" errors all the while HIR analysis happily & correctly dumped the requested data below it. I've now relaxed their targets. 2. Since we now have target checking for the internal attributes I figured that it's unhelpful if we still intentionally crashed on invalid targets, so I've got rid of that. 3. I've always been annoyed that most of these (very old) attributes don't contain the word `dump` in their name (rendering their purpose non-obvious) and that some of their names diverge quite a bit from the corresponding query name. I've now rectified that. The new names take longer to type but it's still absolutely acceptable imo. --- I haven't renamed all of the TEST attributes to follow the `rustc_dump_` scheme since that's quite tedious. If it's okay with you I'd like to postpone that (e.g., `rustc_{def_path,hidden_type…,layout,regions,symbol_name}`). I've noticed that the parsers for TEST attrs are spread across `rustc_dump.rs`, `rustc_internal.rs` & `test_attrs.rs` which is a bit confusing. Since the new names are prefixed with `rustc_dump_` I've moved their parsers into `rustc_dump.rs` but of course they are still TEST attrs. IIRC, `test_attrs.rs` also contains non-`rustc_`-TEST attrs, so we can't just merge these two files. I guess that'll sort itself out in the future when I tackle the other internal TEST attrs. r\? Jana || Jonathan
2 parents fdb18d9 + 722fcbb commit 23e2734

68 files changed

Lines changed: 278 additions & 296 deletions

File tree

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/rustc_dump.rs

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use rustc_hir::Target;
21
use rustc_hir::attrs::AttributeKind;
2+
use rustc_hir::{MethodKind, Target};
33
use rustc_span::{Span, Symbol, sym};
44

55
use crate::attributes::prelude::Allow;
@@ -25,6 +25,20 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpDefParentsParser {
2525
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpDefParents;
2626
}
2727

28+
pub(crate) struct RustcDumpInferredOutlivesParser;
29+
30+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpInferredOutlivesParser {
31+
const PATH: &[Symbol] = &[sym::rustc_dump_inferred_outlives];
32+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
33+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
34+
Allow(Target::Struct),
35+
Allow(Target::Enum),
36+
Allow(Target::Union),
37+
Allow(Target::TyAlias),
38+
]);
39+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpInferredOutlives;
40+
}
41+
2842
pub(crate) struct RustcDumpItemBoundsParser;
2943

3044
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpItemBoundsParser {
@@ -34,21 +48,88 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpItemBoundsParser {
3448
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpItemBounds;
3549
}
3650

51+
pub(crate) struct RustcDumpObjectLifetimeDefaultsParser;
52+
53+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpObjectLifetimeDefaultsParser {
54+
const PATH: &[Symbol] = &[sym::rustc_dump_object_lifetime_defaults];
55+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
56+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
57+
Allow(Target::AssocConst),
58+
Allow(Target::AssocTy),
59+
Allow(Target::Const),
60+
Allow(Target::Enum),
61+
Allow(Target::Fn),
62+
Allow(Target::ForeignFn),
63+
Allow(Target::Impl { of_trait: false }),
64+
Allow(Target::Impl { of_trait: true }),
65+
Allow(Target::Method(MethodKind::Inherent)),
66+
Allow(Target::Method(MethodKind::Trait { body: false })),
67+
Allow(Target::Method(MethodKind::Trait { body: true })),
68+
Allow(Target::Method(MethodKind::TraitImpl)),
69+
Allow(Target::Struct),
70+
Allow(Target::Trait),
71+
Allow(Target::TraitAlias),
72+
Allow(Target::TyAlias),
73+
Allow(Target::Union),
74+
]);
75+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpObjectLifetimeDefaults;
76+
}
77+
3778
pub(crate) struct RustcDumpPredicatesParser;
3879

3980
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpPredicatesParser {
4081
const PATH: &[Symbol] = &[sym::rustc_dump_predicates];
4182
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
4283
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
43-
Allow(Target::Struct),
84+
Allow(Target::AssocConst),
85+
Allow(Target::AssocTy),
86+
Allow(Target::Const),
87+
Allow(Target::Delegation { mac: false }),
88+
Allow(Target::Delegation { mac: true }),
4489
Allow(Target::Enum),
45-
Allow(Target::Union),
90+
Allow(Target::Fn),
91+
Allow(Target::Impl { of_trait: false }),
92+
Allow(Target::Impl { of_trait: true }),
93+
Allow(Target::Method(MethodKind::Inherent)),
94+
Allow(Target::Method(MethodKind::Trait { body: false })),
95+
Allow(Target::Method(MethodKind::Trait { body: true })),
96+
Allow(Target::Method(MethodKind::TraitImpl)),
97+
Allow(Target::Struct),
4698
Allow(Target::Trait),
47-
Allow(Target::AssocTy),
99+
Allow(Target::TraitAlias),
100+
Allow(Target::TyAlias),
101+
Allow(Target::Union),
48102
]);
49103
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpPredicates;
50104
}
51105

106+
pub(crate) struct RustcDumpVariancesParser;
107+
108+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpVariancesParser {
109+
const PATH: &[Symbol] = &[sym::rustc_dump_variances];
110+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
111+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
112+
Allow(Target::Enum),
113+
Allow(Target::Fn),
114+
Allow(Target::Method(MethodKind::Inherent)),
115+
Allow(Target::Method(MethodKind::Trait { body: false })),
116+
Allow(Target::Method(MethodKind::Trait { body: true })),
117+
Allow(Target::Method(MethodKind::TraitImpl)),
118+
Allow(Target::Struct),
119+
Allow(Target::Union),
120+
]);
121+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpVariances;
122+
}
123+
124+
pub(crate) struct RustcDumpVariancesOfOpaquesParser;
125+
126+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpVariancesOfOpaquesParser {
127+
const PATH: &[Symbol] = &[sym::rustc_dump_variances_of_opaques];
128+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
129+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
130+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpVariancesOfOpaques;
131+
}
132+
52133
pub(crate) struct RustcDumpVtableParser;
53134

54135
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpVtableParser {

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,15 +588,6 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcLintUntrackedQueryInformationPa
588588
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcLintUntrackedQueryInformation;
589589
}
590590

591-
pub(crate) struct RustcObjectLifetimeDefaultParser;
592-
593-
impl<S: Stage> NoArgsAttributeParser<S> for RustcObjectLifetimeDefaultParser {
594-
const PATH: &[Symbol] = &[sym::rustc_object_lifetime_default];
595-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
596-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Struct)]);
597-
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcObjectLifetimeDefault;
598-
}
599-
600591
pub(crate) struct RustcSimdMonomorphizeLaneLimitParser;
601592

602593
impl<S: Stage> SingleAttributeParser<S> for RustcSimdMonomorphizeLaneLimitParser {

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,6 @@ impl<S: Stage> SingleAttributeParser<S> for ShouldPanicParser {
9393
}
9494
}
9595

96-
pub(crate) struct RustcVarianceParser;
97-
98-
impl<S: Stage> NoArgsAttributeParser<S> for RustcVarianceParser {
99-
const PATH: &[Symbol] = &[sym::rustc_variance];
100-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
101-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
102-
Allow(Target::Struct),
103-
Allow(Target::Enum),
104-
Allow(Target::Union),
105-
]);
106-
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcVariance;
107-
}
108-
109-
pub(crate) struct RustcVarianceOfOpaquesParser;
110-
111-
impl<S: Stage> NoArgsAttributeParser<S> for RustcVarianceOfOpaquesParser {
112-
const PATH: &[Symbol] = &[sym::rustc_variance_of_opaques];
113-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
114-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
115-
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcVarianceOfOpaques;
116-
}
117-
11896
pub(crate) struct ReexportTestHarnessMainParser;
11997

12098
impl<S: Stage> SingleAttributeParser<S> for ReexportTestHarnessMainParser {
@@ -215,20 +193,6 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcEvaluateWhereClausesParser {
215193
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcEvaluateWhereClauses;
216194
}
217195

218-
pub(crate) struct RustcOutlivesParser;
219-
220-
impl<S: Stage> NoArgsAttributeParser<S> for RustcOutlivesParser {
221-
const PATH: &[Symbol] = &[sym::rustc_outlives];
222-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
223-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
224-
Allow(Target::Struct),
225-
Allow(Target::Enum),
226-
Allow(Target::Union),
227-
Allow(Target::TyAlias),
228-
]);
229-
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcOutlives;
230-
}
231-
232196
pub(crate) struct TestRunnerParser;
233197

234198
impl<S: Stage> SingleAttributeParser<S> for TestRunnerParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,13 @@ attribute_parsers!(
281281
Single<WithoutArgs<RustcDenyExplicitImplParser>>,
282282
Single<WithoutArgs<RustcDoNotConstCheckParser>>,
283283
Single<WithoutArgs<RustcDumpDefParentsParser>>,
284+
Single<WithoutArgs<RustcDumpInferredOutlivesParser>>,
284285
Single<WithoutArgs<RustcDumpItemBoundsParser>>,
286+
Single<WithoutArgs<RustcDumpObjectLifetimeDefaultsParser>>,
285287
Single<WithoutArgs<RustcDumpPredicatesParser>>,
286288
Single<WithoutArgs<RustcDumpUserArgsParser>>,
289+
Single<WithoutArgs<RustcDumpVariancesOfOpaquesParser>>,
290+
Single<WithoutArgs<RustcDumpVariancesParser>>,
287291
Single<WithoutArgs<RustcDumpVtableParser>>,
288292
Single<WithoutArgs<RustcDynIncompatibleTraitParser>>,
289293
Single<WithoutArgs<RustcEffectiveVisibilityParser>>,
@@ -306,9 +310,7 @@ attribute_parsers!(
306310
Single<WithoutArgs<RustcNonConstTraitMethodParser>>,
307311
Single<WithoutArgs<RustcNonnullOptimizationGuaranteedParser>>,
308312
Single<WithoutArgs<RustcNounwindParser>>,
309-
Single<WithoutArgs<RustcObjectLifetimeDefaultParser>>,
310313
Single<WithoutArgs<RustcOffloadKernelParser>>,
311-
Single<WithoutArgs<RustcOutlivesParser>>,
312314
Single<WithoutArgs<RustcParenSugarParser>>,
313315
Single<WithoutArgs<RustcPassByValueParser>>,
314316
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
@@ -323,8 +325,6 @@ attribute_parsers!(
323325
Single<WithoutArgs<RustcStrictCoherenceParser>>,
324326
Single<WithoutArgs<RustcTrivialFieldReadsParser>>,
325327
Single<WithoutArgs<RustcUnsafeSpecializationMarkerParser>>,
326-
Single<WithoutArgs<RustcVarianceOfOpaquesParser>>,
327-
Single<WithoutArgs<RustcVarianceParser>>,
328328
Single<WithoutArgs<ThreadLocalParser>>,
329329
Single<WithoutArgs<TrackCallerParser>>,
330330
// tidy-alphabetical-end
Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,2 @@
11
#### This error code is internal to the compiler and will not be emitted with normal Rust code.
22
#### Note: this error code is no longer emitted by the compiler.
3-
4-
This error code shows the variance of a type's generic parameters.
5-
6-
Erroneous code example:
7-
8-
```compile_fail
9-
// NOTE: this feature is perma-unstable and should *only* be used for
10-
// testing purposes.
11-
#![allow(internal_features)]
12-
#![feature(rustc_attrs)]
13-
14-
#[rustc_variance]
15-
struct Foo<'a, T> { // error: deliberate error to display type's variance
16-
t: &'a mut T,
17-
}
18-
```
19-
20-
which produces the following error:
21-
22-
```text
23-
error: [-, o]
24-
--> <anon>:4:1
25-
|
26-
4 | struct Foo<'a, T> {
27-
| ^^^^^^^^^^^^^^^^^
28-
```
29-
30-
*Note that while `#[rustc_variance]` still exists and is used within the*
31-
*compiler, it no longer is marked as `E0208` and instead has no error code.*
32-
33-
This error is deliberately triggered with the `#[rustc_variance]` attribute
34-
(`#![feature(rustc_attrs)]` must be enabled) and helps to show you the variance
35-
of the type's generic parameters. You can read more about variance and
36-
subtyping in [this section of the Rustonomicon]. For a more in depth look at
37-
variance (including a more complete list of common variances) see
38-
[this section of the Reference]. For information on how variance is implemented
39-
in the compiler, see [this section of `rustc-dev-guide`].
40-
41-
This error can be easily fixed by removing the `#[rustc_variance]` attribute,
42-
the compiler's suggestion to comment it out can be applied automatically with
43-
`rustfix`.
44-
45-
[this section of the Rustonomicon]: https://doc.rust-lang.org/nomicon/subtyping.html
46-
[this section of the Reference]: https://doc.rust-lang.org/reference/subtyping.html#variance
47-
[this section of `rustc-dev-guide`]: https://rustc-dev-guide.rust-lang.org/variance.html

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
14191419

14201420
rustc_attr!(TEST, rustc_effective_visibility, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes),
14211421
rustc_attr!(
1422-
TEST, rustc_outlives, Normal, template!(Word),
1422+
TEST, rustc_dump_inferred_outlives, Normal, template!(Word),
14231423
WarnFollowing, EncodeCrossCrate::No
14241424
),
14251425
rustc_attr!(
@@ -1439,11 +1439,11 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
14391439
WarnFollowing, EncodeCrossCrate::Yes
14401440
),
14411441
rustc_attr!(
1442-
TEST, rustc_variance, Normal, template!(Word),
1442+
TEST, rustc_dump_variances, Normal, template!(Word),
14431443
WarnFollowing, EncodeCrossCrate::No
14441444
),
14451445
rustc_attr!(
1446-
TEST, rustc_variance_of_opaques, Normal, template!(Word),
1446+
TEST, rustc_dump_variances_of_opaques, Normal, template!(Word),
14471447
WarnFollowing, EncodeCrossCrate::No
14481448
),
14491449
rustc_attr!(
@@ -1531,7 +1531,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
15311531
WarnFollowing, EncodeCrossCrate::No
15321532
),
15331533
rustc_attr!(
1534-
TEST, rustc_object_lifetime_default, Normal, template!(Word),
1534+
TEST, rustc_dump_object_lifetime_defaults, Normal, template!(Word),
15351535
WarnFollowing, EncodeCrossCrate::No
15361536
),
15371537
rustc_attr!(

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,15 +1366,27 @@ pub enum AttributeKind {
13661366
/// Represents `#[rustc_dump_def_parents]`
13671367
RustcDumpDefParents,
13681368

1369+
/// Represents `#[rustc_dump_inferred_outlives]`
1370+
RustcDumpInferredOutlives,
1371+
13691372
/// Represents `#[rustc_dump_item_bounds]`
13701373
RustcDumpItemBounds,
13711374

1375+
/// Represents `#[rustc_dump_object_lifetime_defaults]`.
1376+
RustcDumpObjectLifetimeDefaults,
1377+
13721378
/// Represents `#[rustc_dump_predicates]`
13731379
RustcDumpPredicates,
13741380

13751381
/// Represents `#[rustc_dump_user_args]`
13761382
RustcDumpUserArgs,
13771383

1384+
/// Represents `#[rustc_dump_variances]`
1385+
RustcDumpVariances,
1386+
1387+
/// Represents `#[rustc_dump_variances_of_opaques]`
1388+
RustcDumpVariancesOfOpaques,
1389+
13781390
/// Represents `#[rustc_dump_vtable]`
13791391
RustcDumpVtable(Span),
13801392

@@ -1493,15 +1505,9 @@ pub enum AttributeKind {
14931505
span: Span,
14941506
},
14951507

1496-
/// Represents `#[rustc_object_lifetime_default]`.
1497-
RustcObjectLifetimeDefault,
1498-
14991508
/// Represents `#[rustc_offload_kernel]`
15001509
RustcOffloadKernel,
15011510

1502-
/// Represents `#[rustc_outlives]`
1503-
RustcOutlives,
1504-
15051511
/// Represents `#[rustc_paren_sugar]`.
15061512
RustcParenSugar(Span),
15071513

@@ -1574,12 +1580,6 @@ pub enum AttributeKind {
15741580
/// Represents `#[rustc_unsafe_specialization_marker]`.
15751581
RustcUnsafeSpecializationMarker(Span),
15761582

1577-
/// Represents `#[rustc_variance]`
1578-
RustcVariance,
1579-
1580-
/// Represents `#[rustc_variance_of_opaques]`
1581-
RustcVarianceOfOpaques,
1582-
15831583
/// Represents `#[sanitize]`
15841584
///
15851585
/// the on set and off set are distjoint since there's a third option: unset.

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,13 @@ impl AttributeKind {
124124
RustcDocPrimitive(..) => Yes,
125125
RustcDummy => No,
126126
RustcDumpDefParents => No,
127+
RustcDumpInferredOutlives => No,
127128
RustcDumpItemBounds => No,
129+
RustcDumpObjectLifetimeDefaults => No,
128130
RustcDumpPredicates => No,
129131
RustcDumpUserArgs => No,
132+
RustcDumpVariances => No,
133+
RustcDumpVariancesOfOpaques => No,
130134
RustcDumpVtable(..) => No,
131135
RustcDynIncompatibleTrait(..) => No,
132136
RustcEffectiveVisibility => Yes,
@@ -161,9 +165,7 @@ impl AttributeKind {
161165
RustcNounwind => No,
162166
RustcObjcClass { .. } => No,
163167
RustcObjcSelector { .. } => No,
164-
RustcObjectLifetimeDefault => No,
165168
RustcOffloadKernel => Yes,
166-
RustcOutlives => No,
167169
RustcParenSugar(..) => No,
168170
RustcPassByValue(..) => Yes,
169171
RustcPassIndirectlyInNonRusticAbis(..) => No,
@@ -185,8 +187,6 @@ impl AttributeKind {
185187
RustcThenThisWouldNeed(..) => No,
186188
RustcTrivialFieldReads => Yes,
187189
RustcUnsafeSpecializationMarker(..) => No,
188-
RustcVariance => No,
189-
RustcVarianceOfOpaques => No,
190190
Sanitize { .. } => No,
191191
ShouldPanic { .. } => No,
192192
Stability { .. } => Yes,

0 commit comments

Comments
 (0)