提交 5ffb7db4 编写于 作者: M Manish Goregaokar

Add `Gated` attribute type

上级 d5c3194c
...@@ -642,8 +642,12 @@ fn get_lints(&self) -> LintArray { ...@@ -642,8 +642,12 @@ fn get_lints(&self) -> LintArray {
fn check_attribute(&mut self, cx: &Context, attr: &ast::Attribute) { fn check_attribute(&mut self, cx: &Context, attr: &ast::Attribute) {
for &(ref name, ty) in KNOWN_ATTRIBUTES { for &(ref name, ty) in KNOWN_ATTRIBUTES {
if ty == AttributeType::Whitelisted && attr.check_name(name) { match ty {
AttributeType::Whitelisted
| AttributeType::Gated(_, _) if attr.check_name(name) => {
break; break;
},
_ => ()
} }
} }
......
...@@ -166,20 +166,17 @@ enum Status { ...@@ -166,20 +166,17 @@ enum Status {
("macro_reexport", Normal), ("macro_reexport", Normal),
("macro_use", Normal), ("macro_use", Normal),
("plugin", Normal),
("macro_export", Normal), ("macro_export", Normal),
("plugin_registrar", Normal), ("plugin_registrar", Normal),
("cfg", Normal), ("cfg", Normal),
("main", Normal), ("main", Normal),
("lang", Normal),
("start", Normal), ("start", Normal),
("test", Normal), ("test", Normal),
("bench", Normal), ("bench", Normal),
("simd", Normal), ("simd", Normal),
("repr", Normal), ("repr", Normal),
("path", Normal), ("path", Normal),
("staged_api", Normal),
("abi", Normal), ("abi", Normal),
("rustc_move_fragments", Normal), ("rustc_move_fragments", Normal),
("rustc_variance", Normal), ("rustc_variance", Normal),
...@@ -195,6 +192,17 @@ enum Status { ...@@ -195,6 +192,17 @@ enum Status {
("link_args", Normal), ("link_args", Normal),
("macro_escape", Normal), ("macro_escape", Normal),
("staged_api", Gated("staged_api",
"staged_api is for use by rustc only")),
("plugin", Gated("plugin",
"compiler plugins are experimental \
and possibly buggy")),
("no_std", Gated("no_std",
"no_std is experimental")),
("lang", Gated("lang_items",
"language items are subject to change")),
// FIXME: #14408 whitelist docs since rustdoc looks at them // FIXME: #14408 whitelist docs since rustdoc looks at them
("doc", Whitelisted), ("doc", Whitelisted),
...@@ -242,7 +250,6 @@ enum Status { ...@@ -242,7 +250,6 @@ enum Status {
("feature", CrateLevel), ("feature", CrateLevel),
("no_start", CrateLevel), ("no_start", CrateLevel),
("no_main", CrateLevel), ("no_main", CrateLevel),
("no_std", CrateLevel),
("no_builtins", CrateLevel), ("no_builtins", CrateLevel),
("recursion_limit", CrateLevel), ("recursion_limit", CrateLevel),
]; ];
...@@ -258,6 +265,10 @@ pub enum AttributeType { ...@@ -258,6 +265,10 @@ pub enum AttributeType {
/// will be ignored by the unused_attribute lint /// will be ignored by the unused_attribute lint
Whitelisted, Whitelisted,
/// Is gated by a given feature gate and reason
/// These get whitelisted too
Gated(&'static str, &'static str),
/// Builtin attribute that is only allowed at the crate level /// Builtin attribute that is only allowed at the crate level
CrateLevel, CrateLevel,
} }
...@@ -573,33 +584,22 @@ fn visit_expr(&mut self, e: &ast::Expr) { ...@@ -573,33 +584,22 @@ fn visit_expr(&mut self, e: &ast::Expr) {
} }
fn visit_attribute(&mut self, attr: &ast::Attribute) { fn visit_attribute(&mut self, attr: &ast::Attribute) {
match &*attr.name() { let name = &*attr.name();
"staged_api" => self.gate_feature("staged_api", attr.span, for &(n, ty) in KNOWN_ATTRIBUTES {
"staged_api is for use by rustc only"), if n == name {
"plugin" => self.gate_feature("plugin", attr.span, if let Gated(gate, desc) = ty {
"compiler plugins are experimental \ self.gate_feature(gate, attr.span, desc);
and possibly buggy"), }
"no_std" => self.gate_feature("no_std", attr.span, return;
"no_std is experimental"), }
"unsafe_no_drop_flag" => self.gate_feature("unsafe_no_drop_flag", attr.span,
"unsafe_no_drop_flag has unstable \ }
semantics and may be removed \
in the future"),
"lang" => self.gate_feature("lang_items",
attr.span,
"language items are subject to change"),
name => {
// Custom attribute check
if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) {
self.gate_feature("custom_attribute", attr.span, self.gate_feature("custom_attribute", attr.span,
format!("The attribute `{}` is currently \ format!("The attribute `{}` is currently \
unknown to the the compiler and \ unknown to the the compiler and \
may have meaning \ may have meaning \
added to it in the future", added to it in the future",
attr.name()).as_slice()); 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.
先完成此消息的编辑!
想要评论请 注册