提交 38542cca 编写于 作者: M Manish Goregaokar

Feature gate custom attributes (fixes #22203)

上级 531a06e5
...@@ -134,6 +134,9 @@ ...@@ -134,6 +134,9 @@
// Allows using the unsafe_no_drop_flag attribute (unlikely to // Allows using the unsafe_no_drop_flag attribute (unlikely to
// switch to Accepted; see RFC 320) // switch to Accepted; see RFC 320)
("unsafe_no_drop_flag", "1.0.0", Active), ("unsafe_no_drop_flag", "1.0.0", Active),
// Allows the use of custom attributes; RFC 572
("custom_attribute", "1.0.0", Active)
]; ];
// (changing above list without updating src/doc/reference.md makes @cmr sad) // (changing above list without updating src/doc/reference.md makes @cmr sad)
...@@ -155,6 +158,43 @@ enum Status { ...@@ -155,6 +158,43 @@ enum Status {
// Attributes that have a special meaning to rustc or rustdoc // Attributes that have a special meaning to rustc or rustdoc
pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
// Normal attributes
("warn", Normal),
("allow", Normal),
("forbid", Normal),
("deny", Normal),
("macro_reexport", Normal),
("macro_use", Normal),
("plugin", Normal),
("macro_export", Normal),
("plugin_registrar", Normal),
("cfg", Normal),
("main", Normal),
("lang", Normal),
("start", Normal),
("test", Normal),
("bench", Normal),
("simd", Normal),
("repr", Normal),
("path", Normal),
("staged_api", Normal),
("abi", Normal),
("rustc_move_fragments", Normal),
("rustc_variance", Normal),
("unsafe_destructor", Normal),
("automatically_derived", Normal),
("no_mangle", Normal),
("no_link", Normal),
("derive", Normal),
("should_fail", Normal),
("ignore", Normal),
("no_implicit_prelude", Normal),
("reexport_test_harness_main", Normal),
("link_args", Normal),
("macro_escape", Normal),
// FIXME: #14408 whitelist docs since rustdoc looks at them // FIXME: #14408 whitelist docs since rustdoc looks at them
("doc", Whitelisted), ("doc", Whitelisted),
...@@ -199,11 +239,13 @@ enum Status { ...@@ -199,11 +239,13 @@ enum Status {
// Crate level attributes // Crate level attributes
("crate_name", CrateLevel), ("crate_name", CrateLevel),
("crate_type", CrateLevel), ("crate_type", CrateLevel),
("crate_id", CrateLevel),
("feature", CrateLevel), ("feature", CrateLevel),
("no_start", CrateLevel), ("no_start", CrateLevel),
("no_main", CrateLevel), ("no_main", CrateLevel),
("no_std", CrateLevel), ("no_std", CrateLevel),
("no_builtins", CrateLevel), ("no_builtins", CrateLevel),
("recursion_limit", CrateLevel),
]; ];
#[derive(PartialEq, Copy)] #[derive(PartialEq, Copy)]
...@@ -557,6 +599,18 @@ fn visit_attribute(&mut self, attr: &ast::Attribute) { ...@@ -557,6 +599,18 @@ fn visit_attribute(&mut self, attr: &ast::Attribute) {
"unsafe_no_drop_flag has unstable semantics \ "unsafe_no_drop_flag has unstable semantics \
and may be removed in the future"); and may be removed in the future");
} }
// Custom attribute check
let name = attr.name();
if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) {
self.gate_feature("custom_attribute", attr.span,
format!("The attribute `{}` is currently \
unknown to the the compiler and \
may have meaning \
added to it in the future",
attr.name()).as_slice());
}
} }
fn visit_pat(&mut self, pattern: &ast::Pat) { fn visit_pat(&mut self, pattern: &ast::Pat) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册