Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ea4ad55

Browse files
committed
Introduce #[rustc_dummy] attribute and use it in tests
Unlike other built-in attributes, this attribute accepts any input
1 parent 74a6d1c commit ea4ad55

25 files changed

+458
-482
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
13361336
"internal implementation detail",
13371337
cfg_fn!(rustc_attrs))),
13381338

1339+
(sym::rustc_dummy, Normal, template!(Word /* doesn't matter*/), Gated(Stability::Unstable,
1340+
sym::rustc_attrs,
1341+
"used by the test suite",
1342+
cfg_fn!(rustc_attrs))),
1343+
13391344
// FIXME: #14408 whitelist docs since rustdoc looks at them
13401345
(
13411346
sym::doc,
@@ -1962,12 +1967,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
19621967
}
19631968

19641969
match attr_info {
1965-
Some(&(name, _, template, _)) => self.check_builtin_attribute(
1966-
attr,
1967-
name,
1968-
template
1969-
),
1970-
None => if let Some(TokenTree::Token(token)) = attr.tokens.trees().next() {
1970+
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
1971+
Some(&(name, _, template, _)) if name != sym::rustc_dummy =>
1972+
self.check_builtin_attribute(attr, name, template),
1973+
_ => if let Some(TokenTree::Token(token)) = attr.tokens.trees().next() {
19711974
if token == token::Eq {
19721975
// All key-value attributes are restricted to meta-item syntax.
19731976
attr.parse_meta(self.context.parse_sess).map_err(|mut err| err.emit()).ok();

src/libsyntax_pos/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ symbols! {
527527
rustc_diagnostic_macros,
528528
rustc_dirty,
529529
rustc_doc_only_macro,
530+
rustc_dummy,
530531
rustc_dump_env_program_clauses,
531532
rustc_dump_program_clauses,
532533
rustc_dump_user_substs,

src/test/pretty/attr-fn-inner.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
// pp-exact
21
// Testing that both the inner item and next outer item are
32
// preserved, and that the first outer item parsed in main is not
43
// accidentally carried over to each inner function
54

6-
#![feature(custom_attribute)]
5+
// pp-exact
6+
7+
#![feature(rustc_attrs)]
78

89
fn main() {
9-
#![inner_attr]
10-
#[outer_attr]
10+
#![rustc_dummy]
11+
#[rustc_dummy]
1112
fn f() { }
1213

13-
#[outer_attr]
14+
#[rustc_dummy]
1415
fn g() { }
1516
}

src/test/pretty/attr-literals.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
// pp-exact
21
// Tests literals in attributes.
32

4-
#![feature(custom_attribute)]
3+
// pp-exact
4+
5+
#![feature(rustc_attrs)]
56

67
fn main() {
7-
#![hello("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))]
8-
#[align = 8]
8+
#![rustc_dummy("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))]
9+
#[rustc_dummy = 8]
910
fn f() { }
1011

11-
#[vector(1, 2, 3)]
12+
#[rustc_dummy(1, 2, 3)]
1213
fn g() { }
1314
}

0 commit comments

Comments
 (0)