Skip to content

Commit 6c28f84

Browse files
topecongiroflip1995
authored andcommitted
Gate tool_attributes feature
1 parent 9b3aea6 commit 6c28f84

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/libsyntax/attr.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ pub fn is_known(attr: &Attribute) -> bool {
107107
})
108108
}
109109

110+
const RUST_KNOWN_TOOL: &[&str] = &["clippy", "rustfmt"];
111+
112+
pub fn is_known_tool(attr: &Attribute) -> bool {
113+
RUST_KNOWN_TOOL.contains(&attr.name().as_str().as_ref())
114+
}
115+
110116
impl NestedMetaItem {
111117
/// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
112118
pub fn meta_item(&self) -> Option<&MetaItem> {
@@ -250,6 +256,10 @@ impl Attribute {
250256
pub fn is_value_str(&self) -> bool {
251257
self.value_str().is_some()
252258
}
259+
260+
pub fn is_scoped(&self) -> bool {
261+
self.path.segments.len() > 1
262+
}
253263
}
254264

255265
impl MetaItem {

src/libsyntax/diagnostic_list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,5 @@ register_diagnostics! {
325325
E0629, // missing 'feature' (rustc_const_unstable)
326326
E0630, // rustc_const_unstable attribute must be paired with stable/unstable attribute
327327
E0693, // incorrect `repr(align)` attribute format
328+
E0694, // an unknown tool name found in scoped attributes
328329
}

src/libsyntax/ext/expand.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10171017
fn check_attributes(&mut self, attrs: &[ast::Attribute]) {
10181018
let features = self.cx.ecfg.features.unwrap();
10191019
for attr in attrs.iter() {
1020-
feature_gate::check_attribute(attr, self.cx.parse_sess, features);
1020+
self.check_attribute_inner(attr, features);
10211021

10221022
// macros are expanded before any lint passes so this warning has to be hardcoded
10231023
if attr.path == "derive" {
@@ -1030,6 +1030,10 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10301030

10311031
fn check_attribute(&mut self, at: &ast::Attribute) {
10321032
let features = self.cx.ecfg.features.unwrap();
1033+
self.check_attribute_inner(at, features);
1034+
}
1035+
1036+
fn check_attribute_inner(&mut self, at: &ast::Attribute, features: &Features) {
10331037
feature_gate::check_attribute(at, self.cx.parse_sess, features);
10341038
}
10351039
}

src/libsyntax/feature_gate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ declare_features! (
460460

461461
// Access to crate names passed via `--extern` through prelude
462462
(active, extern_prelude, "1.27.0", Some(44660), Some(Edition::Edition2018)),
463+
464+
// Scoped attributes
465+
(active, tool_attributes, "1.25.0", Some(44690)),
463466
);
464467

465468
declare_features! (
@@ -1079,7 +1082,7 @@ pub struct GatedCfg {
10791082

10801083
impl GatedCfg {
10811084
pub fn gate(cfg: &ast::MetaItem) -> Option<GatedCfg> {
1082-
let name = cfg.ident.name.as_str();
1085+
let name = cfg.name().as_str();
10831086
GATED_CFGS.iter()
10841087
.position(|info| info.0 == name)
10851088
.map(|idx| {

0 commit comments

Comments
 (0)