Skip to content
Permalink
Browse files

Introduce `#[rustc_dummy]` attribute and use it in tests

Unlike other built-in attributes, this attribute accepts any input
  • Loading branch information...
petrochenkov committed Jun 8, 2019
1 parent 74a6d1c commit ea4ad555d76d2eb8e6eb749e1b4c163e16077985
@@ -1336,6 +1336,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
"internal implementation detail",
cfg_fn!(rustc_attrs))),

(sym::rustc_dummy, Normal, template!(Word /* doesn't matter*/), Gated(Stability::Unstable,
sym::rustc_attrs,
"used by the test suite",
cfg_fn!(rustc_attrs))),

// FIXME: #14408 whitelist docs since rustdoc looks at them
(
sym::doc,
@@ -1962,12 +1967,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}

match attr_info {
Some(&(name, _, template, _)) => self.check_builtin_attribute(
attr,
name,
template
),
None => if let Some(TokenTree::Token(token)) = attr.tokens.trees().next() {
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
Some(&(name, _, template, _)) if name != sym::rustc_dummy =>
self.check_builtin_attribute(attr, name, template),
_ => if let Some(TokenTree::Token(token)) = attr.tokens.trees().next() {
if token == token::Eq {
// All key-value attributes are restricted to meta-item syntax.
attr.parse_meta(self.context.parse_sess).map_err(|mut err| err.emit()).ok();
@@ -527,6 +527,7 @@ symbols! {
rustc_diagnostic_macros,
rustc_dirty,
rustc_doc_only_macro,
rustc_dummy,
rustc_dump_env_program_clauses,
rustc_dump_program_clauses,
rustc_dump_user_substs,
@@ -1,15 +1,16 @@
// pp-exact
// Testing that both the inner item and next outer item are
// preserved, and that the first outer item parsed in main is not
// accidentally carried over to each inner function

#![feature(custom_attribute)]
// pp-exact

#![feature(rustc_attrs)]

fn main() {
#![inner_attr]
#[outer_attr]
#![rustc_dummy]
#[rustc_dummy]
fn f() { }

#[outer_attr]
#[rustc_dummy]
fn g() { }
}
@@ -1,13 +1,14 @@
// pp-exact
// Tests literals in attributes.

#![feature(custom_attribute)]
// pp-exact

#![feature(rustc_attrs)]

fn main() {
#![hello("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))]
#[align = 8]
#![rustc_dummy("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))]
#[rustc_dummy = 8]
fn f() { }

#[vector(1, 2, 3)]
#[rustc_dummy(1, 2, 3)]
fn g() { }
}

0 comments on commit ea4ad55

Please sign in to comment.
You can’t perform that action at this time.