Skip to content

Commit 0668ae9

Browse files
Port #[ignore] to the new attribute parsing infrastructure
1 parent 1b61d43 commit 0668ae9

File tree

12 files changed

+88
-39
lines changed

12 files changed

+88
-39
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
@@ -23,6 +23,7 @@ impl AttributeKind {
2323
Deprecation { .. } => Yes,
2424
DocComment { .. } => Yes,
2525
ExportName { .. } => Yes,
26+
Ignore { .. } => No,
2627
Inline(..) => No,
2728
LinkSection { .. } => No,
2829
MacroTransparency(..) => Yes,

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub(crate) mod repr;
4040
pub(crate) mod rustc_internal;
4141
pub(crate) mod semantics;
4242
pub(crate) mod stability;
43+
pub(crate) mod test_attrs;
4344
pub(crate) mod traits;
4445
pub(crate) mod transparency;
4546
pub(crate) mod util;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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) => name_value.value_as_str(),
24+
ArgParser::List(_) => {
25+
let suggestions =
26+
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "ignore");
27+
let span = cx.attr_span;
28+
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
29+
return None;
30+
}
31+
},
32+
})
33+
}
34+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::attributes::semantics::MayDangleParser;
3636
use crate::attributes::stability::{
3737
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
3838
};
39+
use crate::attributes::test_attrs::IgnoreParser;
3940
use crate::attributes::traits::SkipDuringMethodDispatchParser;
4041
use crate::attributes::transparency::TransparencyParser;
4142
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -125,6 +126,7 @@ attribute_parsers!(
125126
// tidy-alphabetical-start
126127
Single<DeprecationParser>,
127128
Single<ExportNameParser>,
129+
Single<IgnoreParser>,
128130
Single<InlineParser>,
129131
Single<LinkNameParser>,
130132
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
@@ -302,6 +302,7 @@ fn emit_malformed_attribute(
302302
| sym::rustc_allow_const_fn_unstable
303303
| sym::naked
304304
| sym::no_mangle
305+
| sym::ignore
305306
| sym::must_use
306307
| sym::track_caller
307308
| sym::link_name
@@ -317,8 +318,7 @@ fn emit_malformed_attribute(
317318

318319
// Some of previously accepted forms were used in practice,
319320
// report them as warnings for now.
320-
let should_warn =
321-
|name| matches!(name, sym::doc | sym::ignore | sym::link | sym::test | sym::bench);
321+
let should_warn = |name| matches!(name, sym::doc | sym::link | sym::test | sym::bench);
322322

323323
let error_msg = format!("malformed `{name}` attribute input");
324324
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
@@ -212,6 +212,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
212212
Attribute::Parsed(AttributeKind::MayDangle(attr_span)) => {
213213
self.check_may_dangle(hir_id, *attr_span)
214214
}
215+
Attribute::Parsed(AttributeKind::Ignore { span, .. }) => {
216+
self.check_generic_attr(hir_id, sym::ignore, *span, target, Target::Fn)
217+
}
215218
Attribute::Parsed(AttributeKind::MustUse { span, .. }) => {
216219
self.check_must_use(hir_id, *span, target)
217220
}
@@ -299,7 +302,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
299302
}
300303
[sym::path, ..] => self.check_generic_attr_unparsed(hir_id, attr, target, Target::Mod),
301304
[sym::macro_export, ..] => self.check_macro_export(hir_id, attr, target),
302-
[sym::ignore, ..] | [sym::should_panic, ..] => {
305+
[sym::should_panic, ..] => {
303306
self.check_generic_attr_unparsed(hir_id, attr, target, Target::Fn)
304307
}
305308
[sym::automatically_derived, ..] => {

tests/ui/attributes/malformed-attrs.stderr

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

318-
error: valid forms for the attribute are `#[ignore]` and `#[ignore = "reason"]`
319-
--> $DIR/malformed-attrs.rs:93:1
320-
|
321-
LL | #[ignore()]
322-
| ^^^^^^^^^^^
323-
|
324-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
325-
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
326-
327318
error: invalid argument
328319
--> $DIR/malformed-attrs.rs:187:1
329320
|
@@ -597,6 +588,15 @@ LL | #[inline = 5]
597588
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
598589
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
599590

591+
error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]`
592+
--> $DIR/malformed-attrs.rs:93:1
593+
|
594+
LL | #[ignore()]
595+
| ^^^^^^^^^^^
596+
|
597+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
598+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
599+
600600
error[E0308]: mismatched types
601601
--> $DIR/malformed-attrs.rs:110:23
602602
|

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
|
@@ -177,6 +165,18 @@ note: attribute also specified here
177165
LL | #[macro_export]
178166
| ^^^^^^^^^^^^^^^
179167

168+
error: unused attribute
169+
--> $DIR/unused-attr-duplicate.rs:53:1
170+
|
171+
LL | #[ignore = "some text"]
172+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
173+
|
174+
note: attribute also specified here
175+
--> $DIR/unused-attr-duplicate.rs:52:1
176+
|
177+
LL | #[ignore]
178+
| ^^^^^^^^^
179+
180180
error: unused attribute
181181
--> $DIR/unused-attr-duplicate.rs:60:1
182182
|

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)