Skip to content

Commit 38542cc

Browse files
committed
Feature gate custom attributes (fixes rust-lang#22203)
1 parent 531a06e commit 38542cc

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ static KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
134134
// Allows using the unsafe_no_drop_flag attribute (unlikely to
135135
// switch to Accepted; see RFC 320)
136136
("unsafe_no_drop_flag", "1.0.0", Active),
137+
138+
// Allows the use of custom attributes; RFC 572
139+
("custom_attribute", "1.0.0", Active)
137140
];
138141
// (changing above list without updating src/doc/reference.md makes @cmr sad)
139142

@@ -155,6 +158,43 @@ enum Status {
155158

156159
// Attributes that have a special meaning to rustc or rustdoc
157160
pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
161+
// Normal attributes
162+
163+
("warn", Normal),
164+
("allow", Normal),
165+
("forbid", Normal),
166+
("deny", Normal),
167+
168+
("macro_reexport", Normal),
169+
("macro_use", Normal),
170+
("plugin", Normal),
171+
("macro_export", Normal),
172+
("plugin_registrar", Normal),
173+
174+
("cfg", Normal),
175+
("main", Normal),
176+
("lang", Normal),
177+
("start", Normal),
178+
("test", Normal),
179+
("bench", Normal),
180+
("simd", Normal),
181+
("repr", Normal),
182+
("path", Normal),
183+
("staged_api", Normal),
184+
("abi", Normal),
185+
("rustc_move_fragments", Normal),
186+
("rustc_variance", Normal),
187+
("unsafe_destructor", Normal),
188+
("automatically_derived", Normal),
189+
("no_mangle", Normal),
190+
("no_link", Normal),
191+
("derive", Normal),
192+
("should_fail", Normal),
193+
("ignore", Normal),
194+
("no_implicit_prelude", Normal),
195+
("reexport_test_harness_main", Normal),
196+
("link_args", Normal),
197+
("macro_escape", Normal),
158198

159199
// FIXME: #14408 whitelist docs since rustdoc looks at them
160200
("doc", Whitelisted),
@@ -199,11 +239,13 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
199239
// Crate level attributes
200240
("crate_name", CrateLevel),
201241
("crate_type", CrateLevel),
242+
("crate_id", CrateLevel),
202243
("feature", CrateLevel),
203244
("no_start", CrateLevel),
204245
("no_main", CrateLevel),
205246
("no_std", CrateLevel),
206247
("no_builtins", CrateLevel),
248+
("recursion_limit", CrateLevel),
207249
];
208250

209251
#[derive(PartialEq, Copy)]
@@ -557,6 +599,18 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
557599
"unsafe_no_drop_flag has unstable semantics \
558600
and may be removed in the future");
559601
}
602+
603+
// Custom attribute check
604+
let name = attr.name();
605+
606+
if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) {
607+
self.gate_feature("custom_attribute", attr.span,
608+
format!("The attribute `{}` is currently \
609+
unknown to the the compiler and \
610+
may have meaning \
611+
added to it in the future",
612+
attr.name()).as_slice());
613+
}
560614
}
561615

562616
fn visit_pat(&mut self, pattern: &ast::Pat) {

0 commit comments

Comments
 (0)