Skip to content

Commit 2d8ffff

Browse files
Port #[ignore] to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent 733b47e commit 2d8ffff

File tree

13 files changed

+117
-40
lines changed

13 files changed

+117
-40
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ pub enum AttributeKind {
250250
span: Span,
251251
},
252252

253+
/// Represents `#[ignore]`
254+
Ignore {
255+
span: Span,
256+
/// ignore can optionally have a reason: `#[ignore = "reason this is ignored"]`
257+
reason: Option<Symbol>,
258+
},
259+
253260
/// Represents `#[inline]` and `#[rustc_force_inline]`.
254261
Inline(InlineAttr, Span),
255262

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl AttributeKind {
2626
Deprecation { .. } => Yes,
2727
DocComment { .. } => Yes,
2828
ExportName { .. } => Yes,
29+
Ignore { .. } => No,
2930
Inline(..) => No,
3031
LinkName { .. } => Yes,
3132
LinkSection { .. } => No,

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub(crate) mod repr;
4141
pub(crate) mod rustc_internal;
4242
pub(crate) mod semantics;
4343
pub(crate) mod stability;
44+
pub(crate) mod test_attrs;
4445
pub(crate) mod traits;
4546
pub(crate) mod transparency;
4647
pub(crate) mod util;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use rustc_attr_data_structures::AttributeKind;
2+
use rustc_attr_data_structures::lints::AttributeLintKind;
3+
use rustc_feature::{AttributeTemplate, template};
4+
use rustc_span::{Symbol, sym};
5+
6+
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
7+
use crate::context::{AcceptContext, Stage};
8+
use crate::parser::ArgParser;
9+
10+
pub(crate) struct IgnoreParser;
11+
12+
impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
13+
const PATH: &[Symbol] = &[sym::ignore];
14+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
15+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
16+
const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason");
17+
18+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
19+
Some(AttributeKind::Ignore {
20+
span: cx.attr_span,
21+
reason: match args {
22+
ArgParser::NoArgs => None,
23+
ArgParser::NameValue(name_value) => {
24+
let Some(str_value) = name_value.value_as_str() else {
25+
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
26+
.suggestions(false, "ignore");
27+
let span = cx.attr_span;
28+
cx.emit_lint(
29+
AttributeLintKind::IllFormedAttributeInput { suggestions },
30+
span,
31+
);
32+
return None;
33+
};
34+
Some(str_value)
35+
}
36+
ArgParser::List(_) => {
37+
let suggestions =
38+
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "ignore");
39+
let span = cx.attr_span;
40+
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
41+
return None;
42+
}
43+
},
44+
})
45+
}
46+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::attributes::semantics::MayDangleParser;
3737
use crate::attributes::stability::{
3838
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
3939
};
40+
use crate::attributes::test_attrs::IgnoreParser;
4041
use crate::attributes::traits::SkipDuringMethodDispatchParser;
4142
use crate::attributes::transparency::TransparencyParser;
4243
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -126,6 +127,7 @@ attribute_parsers!(
126127
// tidy-alphabetical-start
127128
Single<DeprecationParser>,
128129
Single<ExportNameParser>,
130+
Single<IgnoreParser>,
129131
Single<InlineParser>,
130132
Single<LinkNameParser>,
131133
Single<LinkSectionParser>,

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ impl AttributeExt for Attribute {
13031303
Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span,
13041304
Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span,
13051305
Attribute::Parsed(AttributeKind::MayDangle(span)) => *span,
1306+
Attribute::Parsed(AttributeKind::Ignore { span, .. }) => *span,
13061307
a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"),
13071308
}
13081309
}

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ fn emit_malformed_attribute(
304304
| sym::naked
305305
| sym::no_mangle
306306
| sym::non_exhaustive
307+
| sym::ignore
307308
| sym::must_use
308309
| sym::track_caller
309310
| sym::link_name
@@ -319,8 +320,7 @@ fn emit_malformed_attribute(
319320

320321
// Some of previously accepted forms were used in practice,
321322
// report them as warnings for now.
322-
let should_warn =
323-
|name| matches!(name, sym::doc | sym::ignore | sym::link | sym::test | sym::bench);
323+
let should_warn = |name| matches!(name, sym::doc | sym::link | sym::test | sym::bench);
324324

325325
let error_msg = format!("malformed `{name}` attribute input");
326326
let mut suggestions = vec![];

compiler/rustc_passes/src/check_attr.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
215215
Attribute::Parsed(AttributeKind::MayDangle(attr_span)) => {
216216
self.check_may_dangle(hir_id, *attr_span)
217217
}
218+
Attribute::Parsed(AttributeKind::Ignore { span, .. }) => {
219+
self.check_generic_attr(hir_id, sym::ignore, *span, target, Target::Fn)
220+
}
218221
Attribute::Parsed(AttributeKind::MustUse { span, .. }) => {
219222
self.check_must_use(hir_id, *span, target)
220223
}
@@ -303,7 +306,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
303306
}
304307
[sym::path, ..] => self.check_generic_attr_unparsed(hir_id, attr, target, Target::Mod),
305308
[sym::macro_export, ..] => self.check_macro_export(hir_id, attr, target),
306-
[sym::ignore, ..] | [sym::should_panic, ..] => {
309+
[sym::should_panic, ..] => {
307310
self.check_generic_attr_unparsed(hir_id, attr, target, Target::Fn)
308311
}
309312
[sym::automatically_derived, ..] => {

tests/ui/attributes/malformed-attrs.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,11 @@ macro_rules! slump {
219219
() => {}
220220
}
221221

222+
#[ignore = 1]
223+
//~^ ERROR valid forms for the attribute are
224+
//~| WARN this was previously accepted by the compiler
225+
fn thing() {
226+
227+
}
228+
222229
fn main() {}

tests/ui/attributes/malformed-attrs.stderr

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,6 @@ LL | #[link]
309309
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
310310
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
311311

312-
error: valid forms for the attribute are `#[ignore]` and `#[ignore = "reason"]`
313-
--> $DIR/malformed-attrs.rs:93:1
314-
|
315-
LL | #[ignore()]
316-
| ^^^^^^^^^^^
317-
|
318-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
319-
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
320-
321312
error: invalid argument
322313
--> $DIR/malformed-attrs.rs:187:1
323314
|
@@ -600,6 +591,24 @@ LL | #[inline = 5]
600591
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
601592
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
602593

594+
error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]`
595+
--> $DIR/malformed-attrs.rs:93:1
596+
|
597+
LL | #[ignore()]
598+
| ^^^^^^^^^^^
599+
|
600+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
601+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
602+
603+
error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]`
604+
--> $DIR/malformed-attrs.rs:222:1
605+
|
606+
LL | #[ignore = 1]
607+
| ^^^^^^^^^^^^^
608+
|
609+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
610+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
611+
603612
error[E0308]: mismatched types
604613
--> $DIR/malformed-attrs.rs:110:23
605614
|
@@ -611,7 +620,7 @@ LL | #[coroutine = 63] || {}
611620
= note: expected unit type `()`
612621
found coroutine `{coroutine@$DIR/malformed-attrs.rs:110:23: 110:25}`
613622

614-
error: aborting due to 73 previous errors; 3 warnings emitted
623+
error: aborting due to 74 previous errors; 3 warnings emitted
615624

616625
Some errors have detailed explanations: E0308, E0463, E0539, E0565, E0658, E0805.
617626
For more information about an error, try `rustc --explain E0308`.

tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,6 @@ warning: `#[should_panic]` only has an effect on functions
367367
LL | #![should_panic]
368368
| ^^^^^^^^^^^^^^^^
369369

370-
warning: `#[ignore]` only has an effect on functions
371-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:54:1
372-
|
373-
LL | #![ignore]
374-
| ^^^^^^^^^^
375-
376370
warning: `#[proc_macro_derive]` only has an effect on functions
377371
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:60:1
378372
|
@@ -387,6 +381,12 @@ LL | #![link()]
387381
|
388382
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
389383

384+
warning: `#[ignore]` only has an effect on functions
385+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:54:1
386+
|
387+
LL | #![ignore]
388+
| ^^^^^^^^^^
389+
390390
warning: attribute should be applied to a foreign function or static
391391
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:66:1
392392
|

tests/ui/lint/unused/unused-attr-duplicate.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,6 @@ LL | #[path = "auxiliary/lint_unused_extern_crate.rs"]
4040
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4141
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4242

43-
error: unused attribute
44-
--> $DIR/unused-attr-duplicate.rs:53:1
45-
|
46-
LL | #[ignore = "some text"]
47-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
48-
|
49-
note: attribute also specified here
50-
--> $DIR/unused-attr-duplicate.rs:52:1
51-
|
52-
LL | #[ignore]
53-
| ^^^^^^^^^
54-
5543
error: unused attribute
5644
--> $DIR/unused-attr-duplicate.rs:55:1
5745
|
@@ -165,6 +153,18 @@ note: attribute also specified here
165153
LL | #[macro_export]
166154
| ^^^^^^^^^^^^^^^
167155

156+
error: unused attribute
157+
--> $DIR/unused-attr-duplicate.rs:53:1
158+
|
159+
LL | #[ignore = "some text"]
160+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
161+
|
162+
note: attribute also specified here
163+
--> $DIR/unused-attr-duplicate.rs:52:1
164+
|
165+
LL | #[ignore]
166+
| ^^^^^^^^^
167+
168168
error: unused attribute
169169
--> $DIR/unused-attr-duplicate.rs:60:1
170170
|

tests/ui/malformed/malformed-regressions.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ LL | #[doc]
88
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
99
= note: `#[deny(ill_formed_attribute_input)]` on by default
1010

11-
error: valid forms for the attribute are `#[ignore]` and `#[ignore = "reason"]`
12-
--> $DIR/malformed-regressions.rs:3:1
13-
|
14-
LL | #[ignore()]
15-
| ^^^^^^^^^^^
16-
|
17-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18-
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
19-
2011
error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated")]`
2112
--> $DIR/malformed-regressions.rs:7:1
2213
|
@@ -35,6 +26,15 @@ LL | #[link = ""]
3526
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3627
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
3728

29+
error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]`
30+
--> $DIR/malformed-regressions.rs:3:1
31+
|
32+
LL | #[ignore()]
33+
| ^^^^^^^^^^^
34+
|
35+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
36+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
37+
3838
error: valid forms for the attribute are `#[inline(always|never)]` and `#[inline]`
3939
--> $DIR/malformed-regressions.rs:5:1
4040
|

0 commit comments

Comments
 (0)