Skip to content

Commit 5146c0c

Browse files
committed
Gate tool_attributes feature
1 parent f2b4234 commit 5146c0c

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

src/libsyntax/attr.rs

+10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ pub fn is_known(attr: &Attribute) -> bool {
108108
})
109109
}
110110

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

256266
impl MetaItem {

src/libsyntax/diagnostic_list.rs

+1
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,5 @@ register_diagnostics! {
366366
E0589, // invalid `repr(align)` attribute
367367
E0629, // missing 'feature' (rustc_const_unstable)
368368
E0630, // rustc_const_unstable attribute must be paired with stable/unstable attribute
369+
E0693, // an unknown tool name found in scoped attributes
369370
}

src/libsyntax/ext/expand.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -857,12 +857,16 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
857857
fn check_attributes(&mut self, attrs: &[ast::Attribute]) {
858858
let features = self.cx.ecfg.features.unwrap();
859859
for attr in attrs.iter() {
860-
feature_gate::check_attribute(attr, self.cx.parse_sess, features);
860+
self.check_attribute_inner(attr, features);
861861
}
862862
}
863863

864864
fn check_attribute(&mut self, at: &ast::Attribute) {
865865
let features = self.cx.ecfg.features.unwrap();
866+
self.check_attribute_inner(at, features);
867+
}
868+
869+
fn check_attribute_inner(&mut self, at: &ast::Attribute, features: &Features) {
866870
feature_gate::check_attribute(at, self.cx.parse_sess, features);
867871
}
868872
}

src/libsyntax/feature_gate.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ declare_features! (
449449

450450
// Use `?` as the Kleene "at most one" operator
451451
(active, macro_at_most_once_rep, "1.25.0", Some(48075)),
452+
453+
// Scoped attributes
454+
(active, tool_attributes, "1.25.0", Some(44690)),
452455
);
453456

454457
declare_features! (
@@ -1114,12 +1117,28 @@ impl<'a> Context<'a> {
11141117
// before the plugin attributes are registered
11151118
// so we skip this then
11161119
if !is_macro {
1117-
gate_feature!(self, custom_attribute, attr.span,
1118-
&format!("The attribute `{}` is currently \
1119-
unknown to the compiler and \
1120-
may have meaning \
1121-
added to it in the future",
1122-
attr.path));
1120+
if attr.is_scoped() {
1121+
gate_feature!(self, tool_attributes, attr.span,
1122+
&format!("scoped attribute `{}` is experimental", attr.path));
1123+
if attr::is_known_tool(attr) {
1124+
attr::mark_used(attr);
1125+
} else {
1126+
span_err!(
1127+
self.parse_sess.span_diagnostic,
1128+
attr.span,
1129+
E0693,
1130+
"An unkown tool name found in scoped attributes: `{}`.",
1131+
attr.path
1132+
);
1133+
}
1134+
} else {
1135+
gate_feature!(self, custom_attribute, attr.span,
1136+
&format!("The attribute `{}` is currently \
1137+
unknown to the compiler and \
1138+
may have meaning \
1139+
added to it in the future",
1140+
attr.path));
1141+
}
11231142
}
11241143
}
11251144
}

0 commit comments

Comments
 (0)