Skip to content

Commit 0ffb643

Browse files
committed
Make sure #[rustc_doc_only_macro] and other rustc attributes are registered
1 parent 3467e21 commit 0ffb643

25 files changed

+127
-185
lines changed

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#![feature(concat_idents)]
7575
#![feature(const_fn)]
7676
#![feature(const_fn_union)]
77+
#![feature(custom_inner_attributes)]
7778
#![feature(doc_cfg)]
7879
#![feature(doc_spotlight)]
7980
#![feature(extern_types)]

src/librustc_resolve/macros.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,21 +323,13 @@ impl<'a> Resolver<'a> {
323323
let features = self.session.features_untracked();
324324
if attr_kind == NonMacroAttrKind::Custom {
325325
assert!(path.segments.len() == 1);
326-
let name = path.segments[0].ident.as_str();
327-
if name.starts_with("rustc_") {
328-
if !features.rustc_attrs {
329-
let msg = "unless otherwise specified, attributes with the prefix \
330-
`rustc_` are reserved for internal compiler diagnostics";
331-
self.report_unknown_attribute(path.span, &name, msg,
332-
sym::rustc_attrs);
333-
}
334-
} else if !features.custom_attribute {
326+
if !features.custom_attribute {
335327
let msg = format!("The attribute `{}` is currently unknown to the \
336328
compiler and may have meaning added to it in the \
337329
future", path);
338330
self.report_unknown_attribute(
339331
path.span,
340-
&name,
332+
&path.segments[0].ident.as_str(),
341333
&msg,
342334
sym::custom_attribute,
343335
);

src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,9 +1525,7 @@ impl<'feat> ExpansionConfig<'feat> {
15251525
}
15261526

15271527
fn enable_custom_inner_attributes(&self) -> bool {
1528-
self.features.map_or(false, |features| {
1529-
features.custom_inner_attributes || features.custom_attribute || features.rustc_attrs
1530-
})
1528+
self.features.map_or(false, |features| features.custom_inner_attributes)
15311529
}
15321530
}
15331531

src/libsyntax/feature_gate.rs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,18 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
12901290
attribute is just used for rustc unit \
12911291
tests and will never be stable",
12921292
cfg_fn!(rustc_attrs))),
1293+
(sym::rustc_dump_env_program_clauses, Whitelisted, template!(Word), Gated(Stability::Unstable,
1294+
sym::rustc_attrs,
1295+
"the `#[rustc_dump_env_program_clauses]` \
1296+
attribute is just used for rustc unit \
1297+
tests and will never be stable",
1298+
cfg_fn!(rustc_attrs))),
1299+
(sym::rustc_object_lifetime_default, Whitelisted, template!(Word), Gated(Stability::Unstable,
1300+
sym::rustc_attrs,
1301+
"the `#[rustc_object_lifetime_default]` \
1302+
attribute is just used for rustc unit \
1303+
tests and will never be stable",
1304+
cfg_fn!(rustc_attrs))),
12931305
(sym::rustc_test_marker, Normal, template!(Word), Gated(Stability::Unstable,
12941306
sym::rustc_attrs,
12951307
"the `#[rustc_test_marker]` attribute \
@@ -1351,6 +1363,26 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
13511363
"internal implementation detail",
13521364
cfg_fn!(rustc_attrs))),
13531365

1366+
(sym::rustc_allocator_nounwind, Whitelisted, template!(Word), Gated(Stability::Unstable,
1367+
sym::rustc_attrs,
1368+
"internal implementation detail",
1369+
cfg_fn!(rustc_attrs))),
1370+
1371+
(sym::rustc_doc_only_macro, Whitelisted, template!(Word), Gated(Stability::Unstable,
1372+
sym::rustc_attrs,
1373+
"internal implementation detail",
1374+
cfg_fn!(rustc_attrs))),
1375+
1376+
(sym::rustc_promotable, Whitelisted, template!(Word), Gated(Stability::Unstable,
1377+
sym::rustc_attrs,
1378+
"internal implementation detail",
1379+
cfg_fn!(rustc_attrs))),
1380+
1381+
(sym::rustc_allow_const_fn_ptr, Whitelisted, template!(Word), Gated(Stability::Unstable,
1382+
sym::rustc_attrs,
1383+
"internal implementation detail",
1384+
cfg_fn!(rustc_attrs))),
1385+
13541386
(sym::rustc_dummy, Normal, template!(Word /* doesn't matter*/), Gated(Stability::Unstable,
13551387
sym::rustc_attrs,
13561388
"used by the test suite",
@@ -1647,19 +1679,13 @@ impl<'a> Context<'a> {
16471679
return;
16481680
}
16491681
}
1650-
if !attr::is_known(attr) {
1651-
if attr.name_or_empty().as_str().starts_with("rustc_") {
1652-
let msg = "unless otherwise specified, attributes with the prefix `rustc_` \
1653-
are reserved for internal compiler diagnostics";
1654-
gate_feature!(self, rustc_attrs, attr.span, msg);
1655-
} else if !is_macro {
1656-
// Only run the custom attribute lint during regular feature gate
1657-
// checking. Macro gating runs before the plugin attributes are
1658-
// registered, so we skip this in that case.
1659-
let msg = format!("The attribute `{}` is currently unknown to the compiler and \
1660-
may have meaning added to it in the future", attr.path);
1661-
gate_feature!(self, custom_attribute, attr.span, &msg);
1662-
}
1682+
if !is_macro && !attr::is_known(attr) {
1683+
// Only run the custom attribute lint during regular feature gate
1684+
// checking. Macro gating runs before the plugin attributes are
1685+
// registered, so we skip this in that case.
1686+
let msg = format!("The attribute `{}` is currently unknown to the compiler and \
1687+
may have meaning added to it in the future", attr.path);
1688+
gate_feature!(self, custom_attribute, attr.span, &msg);
16631689
}
16641690
}
16651691
}

src/test/run-pass-fulldeps/issue-15778-pass.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// ignore-stage1
33
// compile-flags: -D crate-not-okay
44

5-
#![feature(plugin, rustc_attrs)]
5+
#![feature(plugin, custom_attribute, custom_inner_attributes)]
6+
67
#![plugin(lint_for_crate)]
78
#![rustc_crate_okay]
89
#![rustc_crate_blue]
910
#![rustc_crate_red]
1011
#![rustc_crate_grey]
1112
#![rustc_crate_green]
1213

13-
pub fn main() { }
14+
fn main() {}

src/test/run-pass/attr-on-generic-formals.rs

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/test/ui/attributes/attrs-with-no-formal-in-generics-1.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
struct RefIntPair<'a, 'b>(&'a u32, &'b u32);
88

9-
impl<#[rustc_1] 'a, 'b, #[oops]> RefIntPair<'a, 'b> {
9+
impl<#[rustc_dummy] 'a, 'b, #[oops]> RefIntPair<'a, 'b> {
1010
//~^ ERROR trailing attribute after generic parameter
1111
}
1212

13-
fn main() {
14-
15-
}
13+
fn main() {}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: trailing attribute after generic parameter
2-
--> $DIR/attrs-with-no-formal-in-generics-1.rs:9:25
2+
--> $DIR/attrs-with-no-formal-in-generics-1.rs:9:29
33
|
4-
LL | impl<#[rustc_1] 'a, 'b, #[oops]> RefIntPair<'a, 'b> {
5-
| ^^^^^^^ attributes must go before parameters
4+
LL | impl<#[rustc_dummy] 'a, 'b, #[oops]> RefIntPair<'a, 'b> {
5+
| ^^^^^^^ attributes must go before parameters
66

77
error: aborting due to previous error
88

src/test/ui/attributes/attrs-with-no-formal-in-generics-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
struct RefAny<'a, T>(&'a T);
88

9-
impl<#[rustc_1] 'a, #[rustc_2] T, #[oops]> RefAny<'a, T> {}
9+
impl<#[rustc_dummy] 'a, #[rustc_dummy] T, #[oops]> RefAny<'a, T> {}
1010
//~^ ERROR trailing attribute after generic parameter
1111

1212
fn main() {}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: trailing attribute after generic parameter
2-
--> $DIR/attrs-with-no-formal-in-generics-2.rs:9:35
2+
--> $DIR/attrs-with-no-formal-in-generics-2.rs:9:43
33
|
4-
LL | impl<#[rustc_1] 'a, #[rustc_2] T, #[oops]> RefAny<'a, T> {}
5-
| ^^^^^^^ attributes must go before parameters
4+
LL | impl<#[rustc_dummy] 'a, #[rustc_dummy] T, #[oops]> RefAny<'a, T> {}
5+
| ^^^^^^^ attributes must go before parameters
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)