Skip to content

Commit 695af63

Browse files
authored
Unrolled build for #140372
Rollup merge of #140372 - mejrs:attrs, r=jdonszelmann Exhaustively handle parsed attributes in CheckAttr This pr - Deletes the unused `DiagnosticAttribute ` struct and variant - Comments the `AttributeKind ` enum - The match in `CheckAttrVisitor` is now exhaustive for `AttributeKind::Parsed`. - Moved some checks around after that change I did *not* thoroughly check that there's no duplicated logic between this pass and the attribute parsing but I think it's OK. r? ````@jdonszelmann````
2 parents c6a9554 + 5fdacfe commit 695af63

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ impl OptimizeAttr {
5757
}
5858
}
5959

60-
#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic, PrintAttribute)]
61-
pub enum DiagnosticAttribute {
62-
// tidy-alphabetical-start
63-
DoNotRecommend,
64-
OnUnimplemented,
65-
// tidy-alphabetical-end
66-
}
67-
6860
#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone, HashStable_Generic, PrintAttribute)]
6961
pub enum ReprAttr {
7062
ReprInt(IntType),
@@ -160,40 +152,52 @@ impl Deprecation {
160152
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
161153
pub enum AttributeKind {
162154
// tidy-alphabetical-start
155+
/// Represents `#[rustc_allow_const_fn_unstable]`.
163156
AllowConstFnUnstable(ThinVec<Symbol>),
157+
158+
/// Represents `#[allow_internal_unstable]`.
164159
AllowInternalUnstable(ThinVec<(Symbol, Span)>),
160+
161+
/// Represents `#[rustc_default_body_unstable]`.
165162
BodyStability {
166163
stability: DefaultBodyStability,
167164
/// Span of the `#[rustc_default_body_unstable(...)]` attribute
168165
span: Span,
169166
},
167+
168+
/// Represents `#[rustc_confusables]`.
170169
Confusables {
171170
symbols: ThinVec<Symbol>,
172171
// FIXME(jdonszelmann): remove when target validation code is moved
173172
first_span: Span,
174173
},
174+
175+
/// Represents `#[rustc_const_stable]` and `#[rustc_const_unstable]`.
175176
ConstStability {
176177
stability: PartialConstStability,
177178
/// Span of the `#[rustc_const_stable(...)]` or `#[rustc_const_unstable(...)]` attribute
178179
span: Span,
179180
},
181+
182+
/// Represents `#[rustc_const_stable_indirect]`.
180183
ConstStabilityIndirect,
181-
Deprecation {
182-
deprecation: Deprecation,
183-
span: Span,
184-
},
185-
Diagnostic(DiagnosticAttribute),
186-
DocComment {
187-
style: AttrStyle,
188-
kind: CommentKind,
189-
span: Span,
190-
comment: Symbol,
191-
},
184+
185+
/// Represents [`#[deprecated]`](https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html#the-deprecated-attribute).
186+
Deprecation { deprecation: Deprecation, span: Span },
187+
188+
/// Represents [`#[doc]`](https://doc.rust-lang.org/stable/rustdoc/write-documentation/the-doc-attribute.html).
189+
DocComment { style: AttrStyle, kind: CommentKind, span: Span, comment: Symbol },
190+
191+
/// Represents `#[rustc_macro_transparency]`.
192192
MacroTransparency(Transparency),
193+
194+
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
193195
Repr(ThinVec<(ReprAttr, Span)>),
196+
197+
/// Represents `#[stable]`, `#[unstable]` and `#[rustc_allowed_through_unstable_modules]`.
194198
Stability {
195199
stability: Stability,
196-
/// Span of the `#[stable(...)]` or `#[unstable(...)]` attribute
200+
/// Span of the attribute.
197201
span: Span,
198202
},
199203
// tidy-alphabetical-end

compiler/rustc_passes/src/check_attr.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,22 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
132132
target,
133133
attrs,
134134
),
135-
_ => {
135+
Attribute::Parsed(AttributeKind::AllowConstFnUnstable { .. }) => {
136+
self.check_rustc_allow_const_fn_unstable(hir_id, attr, span, target)
137+
}
138+
Attribute::Parsed(AttributeKind::Deprecation { .. }) => {
139+
self.check_deprecated(hir_id, attr, span, target)
140+
}
141+
Attribute::Parsed(AttributeKind::DocComment { .. }) => { /* `#[doc]` is actually a lot more than just doc comments, so is checked below*/
142+
}
143+
Attribute::Parsed(AttributeKind::Repr(_)) => { /* handled below this loop and elsewhere */
144+
}
145+
Attribute::Parsed(
146+
AttributeKind::BodyStability { .. }
147+
| AttributeKind::ConstStabilityIndirect
148+
| AttributeKind::MacroTransparency(_),
149+
) => { /* do nothing */ }
150+
Attribute::Unparsed(_) => {
136151
match attr.path().as_slice() {
137152
[sym::diagnostic, sym::do_not_recommend, ..] => {
138153
self.check_do_not_recommend(attr.span(), hir_id, target, attr, item)
@@ -169,9 +184,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
169184
self.check_rustc_layout_scalar_valid_range(attr, span, target)
170185
}
171186
[sym::debugger_visualizer, ..] => self.check_debugger_visualizer(attr, target),
172-
[sym::rustc_allow_const_fn_unstable, ..] => {
173-
self.check_rustc_allow_const_fn_unstable(hir_id, attr, span, target)
174-
}
175187
[sym::rustc_std_internal_symbol, ..] => {
176188
self.check_rustc_std_internal_symbol(attr, span, target)
177189
}
@@ -229,7 +241,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
229241
[sym::link_name, ..] => self.check_link_name(hir_id, attr, span, target),
230242
[sym::link_section, ..] => self.check_link_section(hir_id, attr, span, target),
231243
[sym::no_mangle, ..] => self.check_no_mangle(hir_id, attr, span, target),
232-
[sym::deprecated, ..] => self.check_deprecated(hir_id, attr, span, target),
233244
[sym::macro_use, ..] | [sym::macro_escape, ..] => {
234245
self.check_macro_use(hir_id, attr, target)
235246
}
@@ -283,7 +294,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
283294
| sym::pointee // FIXME(derive_coerce_pointee)
284295
| sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
285296
| sym::used // handled elsewhere to restrict to static items
286-
| sym::repr // handled elsewhere to restrict to type decls items
287297
| sym::instruction_set // broken on stable!!!
288298
| sym::windows_subsystem // broken on stable!!!
289299
| sym::patchable_function_entry // FIXME(patchable_function_entry)

0 commit comments

Comments
 (0)