From 0129002d3afa2edb2dad4f2b4f615e73c60c68cc Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 17 Feb 2015 01:46:36 +0530 Subject: [PATCH] Add gating for rustc_* attrs --- src/libcore/lib.rs | 1 + src/libsyntax/feature_gate.rs | 43 ++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 7243bd4f0cb..f1808bc1fb5 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -67,6 +67,7 @@ #![feature(simd, unsafe_destructor)] #![feature(staged_api)] #![feature(unboxed_closures)] +#![feature(rustc_attrs)] #[macro_use] mod macros; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 8aab41baeb5..f6424167bde 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -135,7 +135,10 @@ static KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[ ("unsafe_no_drop_flag", "1.0.0", Active), // Allows the use of custom attributes; RFC 572 - ("custom_attribute", "1.0.0", Active) + ("custom_attribute", "1.0.0", Active), + + // Allows the use of rustc_* attributes; RFC 572 + ("rustc_attrs", "1.0.0", Active), ]; // (changing above list without updating src/doc/reference.md makes @cmr sad) @@ -178,8 +181,6 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ ("repr", Normal), ("path", Normal), ("abi", Normal), - ("rustc_move_fragments", Normal), - ("rustc_variance", Normal), ("unsafe_destructor", Normal), ("automatically_derived", Normal), ("no_mangle", Normal), @@ -202,9 +203,6 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ "no_std is experimental")), ("lang", Gated("lang_items", "language items are subject to change")), - ("rustc_on_unimplemented", Gated("on_unimplemented", - "the `#[rustc_on_unimplemented]` attribute \ - is an experimental feature")), ("linkage", Gated("linkage", "the `linkage` attribute is experimental \ and not portable across platforms")), @@ -213,6 +211,19 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ currently handle destructors. There is no corresponding \ `#[task_local]` mapping to the task model")), + ("rustc_on_unimplemented", Gated("on_unimplemented", + "the `#[rustc_on_unimplemented]` attribute \ + is an experimental feature")), + ("rustc_variance", Gated("rustc_attrs", + "the `#[rustc_variance]` attribute \ + is an experimental feature")), + ("rustc_error", Gated("rustc_attrs", + "the `#[rustc_error]` attribute \ + is an experimental feature")), + ("rustc_move_fragments", Gated("rustc_attrs", + "the `#[rustc_move_fragments]` attribute \ + is an experimental feature")), + // FIXME: #14408 whitelist docs since rustdoc looks at them ("doc", Whitelisted), @@ -243,7 +254,6 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ ("must_use", Whitelisted), ("stable", Whitelisted), ("unstable", Whitelisted), - ("rustc_error", Whitelisted), // FIXME: #19470 this shouldn't be needed forever ("old_orphan_check", Whitelisted), @@ -584,12 +594,19 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { return; } } - 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", - name).as_slice()); + if name.starts_with("rustc_") { + self.gate_feature("rustc_attrs", attr.span, + "unless otherwise specified, attributes \ + with the prefix `rustc_` \ + are reserved for internal compiler diagnostics"); + } else { + 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", + name).as_slice()); + } } fn visit_pat(&mut self, pattern: &ast::Pat) {