From 38542cca29a0ed6f62b18d543386852e5a544adc Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 13 Feb 2015 20:40:24 +0530 Subject: [PATCH] Feature gate custom attributes (fixes #22203) --- src/libsyntax/feature_gate.rs | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index d2eb2126f0f..5af9ca307de 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -134,6 +134,9 @@ // Allows using the unsafe_no_drop_flag attribute (unlikely to // switch to Accepted; see RFC 320) ("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) @@ -155,6 +158,43 @@ enum Status { // Attributes that have a special meaning to rustc or rustdoc 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 ("doc", Whitelisted), @@ -199,11 +239,13 @@ enum Status { // Crate level attributes ("crate_name", CrateLevel), ("crate_type", CrateLevel), + ("crate_id", CrateLevel), ("feature", CrateLevel), ("no_start", CrateLevel), ("no_main", CrateLevel), ("no_std", CrateLevel), ("no_builtins", CrateLevel), + ("recursion_limit", CrateLevel), ]; #[derive(PartialEq, Copy)] @@ -557,6 +599,18 @@ fn visit_attribute(&mut self, attr: &ast::Attribute) { "unsafe_no_drop_flag has unstable semantics \ 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) { -- GitLab