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

+1
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

+2-10
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

+1-3
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

+39-13
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

+3-2
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

-52
This file was deleted.

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

+2-4
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() {}
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

+1-1
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() {}
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

src/test/ui/consts/min_const_fn/allow_const_fn_ptr_feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const fn error(_: fn()) {}
55

66
#[stable(feature = "rust1", since = "1.0.0")]
77
#[rustc_allow_const_fn_ptr]
8-
//~^ ERROR unless otherwise specified, attributes with the prefix `rustc_` are reserved
8+
//~^ ERROR internal implementation detail
99
const fn compiles(_: fn()) {}
1010

1111
fn main() {}

src/test/ui/consts/min_const_fn/allow_const_fn_ptr_feature_gate.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0658]: unless otherwise specified, attributes with the prefix `rustc_` are reserved for internal compiler diagnostics
2-
--> $DIR/allow_const_fn_ptr_feature_gate.rs:7:3
1+
error[E0658]: internal implementation detail
2+
--> $DIR/allow_const_fn_ptr_feature_gate.rs:7:1
33
|
44
LL | #[rustc_allow_const_fn_ptr]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/29642
88
= help: add #![feature(rustc_attrs)] to the crate attributes to enable
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test that `#[rustc_*]` attributes are gated by `rustc_attrs` feature gate.
22

3-
#[rustc_foo]
4-
//~^ ERROR unless otherwise specified, attributes with the prefix `rustc_` are reserved
3+
#[rustc_dummy]
4+
//~^ ERROR used by the test suite
55

66
fn main() {}

src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0658]: unless otherwise specified, attributes with the prefix `rustc_` are reserved for internal compiler diagnostics
2-
--> $DIR/feature-gate-rustc-attrs.rs:3:3
1+
error[E0658]: used by the test suite
2+
--> $DIR/feature-gate-rustc-attrs.rs:3:1
33
|
4-
LL | #[rustc_foo]
5-
| ^^^^^^^^^
4+
LL | #[rustc_dummy]
5+
| ^^^^^^^^^^^^^^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/29642
88
= help: add #![feature(rustc_attrs)] to the crate attributes to enable
+19-25
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
11
// This test previously ensured that attributes on formals in generic parameter
22
// lists are rejected without a feature gate.
3-
//
4-
// (We are prefixing all tested features with `rustc_`, to ensure that
5-
// the attributes themselves won't be rejected by the compiler when
6-
// using `rustc_attrs` feature. There is a separate compile-fail/ test
7-
// ensuring that the attribute feature-gating works in this context.)
83

94
// compile-pass
105

116
#![feature(rustc_attrs)]
12-
#![allow(dead_code)]
13-
14-
struct StLt<#[rustc_lt_struct] 'a>(&'a u32);
15-
struct StTy<#[rustc_ty_struct] I>(I);
16-
enum EnLt<#[rustc_lt_enum] 'b> { A(&'b u32), B }
17-
enum EnTy<#[rustc_ty_enum] J> { A(J), B }
18-
trait TrLt<#[rustc_lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; }
19-
trait TrTy<#[rustc_ty_trait] K> { fn foo(&self, _: K); }
20-
type TyLt<#[rustc_lt_type] 'd> = &'d u32;
21-
type TyTy<#[rustc_ty_type] L> = (L, );
22-
23-
impl<#[rustc_lt_inherent] 'e> StLt<'e> { }
24-
impl<#[rustc_ty_inherent] M> StTy<M> { }
25-
impl<#[rustc_lt_impl_for] 'f> TrLt<'f> for StLt<'f> {
7+
8+
struct StLt<#[rustc_dummy] 'a>(&'a u32);
9+
struct StTy<#[rustc_dummy] I>(I);
10+
enum EnLt<#[rustc_dummy] 'b> { A(&'b u32), B }
11+
enum EnTy<#[rustc_dummy] J> { A(J), B }
12+
trait TrLt<#[rustc_dummy] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; }
13+
trait TrTy<#[rustc_dummy] K> { fn foo(&self, _: K); }
14+
type TyLt<#[rustc_dummy] 'd> = &'d u32;
15+
type TyTy<#[rustc_dummy] L> = (L, );
16+
17+
impl<#[rustc_dummy] 'e> StLt<'e> { }
18+
impl<#[rustc_dummy] M> StTy<M> { }
19+
impl<#[rustc_dummy] 'f> TrLt<'f> for StLt<'f> {
2620
fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } }
2721
}
28-
impl<#[rustc_ty_impl_for] N> TrTy<N> for StTy<N> {
22+
impl<#[rustc_dummy] N> TrTy<N> for StTy<N> {
2923
fn foo(&self, _: N) { }
3024
}
3125

32-
fn f_lt<#[rustc_lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } }
33-
fn f_ty<#[rustc_ty_fn] O>(_: O) { }
26+
fn f_lt<#[rustc_dummy] 'g>(_: &'g [u32]) -> &'g u32 { loop { } }
27+
fn f_ty<#[rustc_dummy] O>(_: O) { }
3428

3529
impl<I> StTy<I> {
36-
fn m_lt<#[rustc_lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } }
37-
fn m_ty<#[rustc_ty_meth] P>(_: P) { }
30+
fn m_lt<#[rustc_dummy] 'h>(_: &'h [u32]) -> &'h u32 { loop { } }
31+
fn m_ty<#[rustc_dummy] P>(_: P) { }
3832
}
3933

4034
fn hof_lt<Q>(_: Q)
41-
where Q: for <#[rustc_lt_hof] 'i> Fn(&'i [u32]) -> &'i u32
35+
where Q: for <#[rustc_dummy] 'i> Fn(&'i [u32]) -> &'i u32
4236
{}
4337

4438
fn main() {}

src/test/ui/nll/ty-outlives/projection-implied-bounds.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
// compile-flags:-Zborrowck=mir -Zverbose
2-
31
// Test that we can deduce when projections like `T::Item` outlive the
42
// function body. Test that this does not imply that `T: 'a` holds.
53

6-
#![allow(warnings)]
7-
#![feature(rustc_attrs)]
4+
// compile-flags:-Zborrowck=mir -Zverbose
85

96
use std::cell::Cell;
107

@@ -18,7 +15,6 @@ where
1815
f(&value, Cell::new(&n));
1916
}
2017

21-
#[rustc_errors]
2218
fn generic1<T: Iterator>(value: T) {
2319
// No error here:
2420
twice(value, |value_ref, item| invoke1(item));
@@ -30,7 +26,6 @@ where
3026
{
3127
}
3228

33-
#[rustc_errors]
3429
fn generic2<T: Iterator>(value: T) {
3530
twice(value, |value_ref, item| invoke2(value_ref, item));
3631
//~^ ERROR the parameter type `T` may not live long enough

src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0310]: the parameter type `T` may not live long enough
2-
--> $DIR/projection-implied-bounds.rs:35:18
2+
--> $DIR/projection-implied-bounds.rs:30:18
33
|
44
LL | twice(value, |value_ref, item| invoke2(value_ref, item));
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/test/ui/nll/ty-outlives/ty-param-implied-bounds.rs

-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
// Test that we assume that universal types like `T` outlive the
55
// function body.
66

7-
#![allow(warnings)]
8-
#![feature(rustc_attrs)]
9-
107
use std::cell::Cell;
118

129
fn twice<F, T>(value: T, mut f: F)
@@ -17,7 +14,6 @@ where
1714
f(Cell::new(&value));
1815
}
1916

20-
#[rustc_errors]
2117
fn generic<T>(value: T) {
2218
// No error here:
2319
twice(value, |r| invoke(r));

0 commit comments

Comments
 (0)