Skip to content

Commit 3d0976a

Browse files
authored
Rollup merge of #70364 - petrochenkov:nofrustc, r=Centril
resolve: Remove `rustc_attrs` as a standalone feature gate Now it only gates specific built-in attributes. So if you want to make a rustc attribute, make it a built-in (this was already the case in practice for some time).
2 parents 3cced91 + 1fa6be0 commit 3d0976a

10 files changed

+75
-98
lines changed

src/librustc_resolve/macros.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_feature::is_builtin_attr_name;
2020
use rustc_hir::def::{self, DefKind, NonMacroAttrKind};
2121
use rustc_hir::def_id;
2222
use rustc_session::lint::builtin::UNUSED_MACROS;
23-
use rustc_session::parse::feature_err;
2423
use rustc_session::Session;
2524
use rustc_span::edition::Edition;
2625
use rustc_span::hygiene::{self, ExpnData, ExpnId, ExpnKind};
@@ -397,20 +396,16 @@ impl<'a> Resolver<'a> {
397396
Err(Determinacy::Undetermined) => return Err(Indeterminate),
398397
};
399398

400-
// Report errors and enforce feature gates for the resolved macro.
401-
let features = self.session.features_untracked();
399+
// Report errors for the resolved macro.
402400
for segment in &path.segments {
403401
if let Some(args) = &segment.args {
404402
self.session.span_err(args.span(), "generic arguments in macro path");
405403
}
406-
if kind == MacroKind::Attr
407-
&& !features.rustc_attrs
408-
&& segment.ident.as_str().starts_with("rustc")
409-
{
410-
let msg =
411-
"attributes starting with `rustc` are reserved for use by the `rustc` compiler";
412-
feature_err(&self.session.parse_sess, sym::rustc_attrs, segment.ident.span, msg)
413-
.emit();
404+
if kind == MacroKind::Attr && segment.ident.as_str().starts_with("rustc") {
405+
self.session.span_err(
406+
segment.ident.span,
407+
"attributes starting with `rustc` are reserved for use by the `rustc` compiler",
408+
);
414409
}
415410
}
416411

src/test/ui-fulldeps/auxiliary/lint-for-crate-rpass.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
#![feature(plugin_registrar, rustc_private)]
44
#![feature(box_syntax)]
5+
56
extern crate rustc_driver;
67
extern crate rustc_hir;
7-
extern crate rustc_span;
8-
#[macro_use]
98
extern crate rustc_lint;
9+
extern crate rustc_span;
1010
#[macro_use]
1111
extern crate rustc_session;
1212
extern crate rustc_ast;
1313

14+
use rustc_ast::attr;
1415
use rustc_driver::plugin::Registry;
1516
use rustc_lint::{LateContext, LateLintPass, LintContext, LintPass};
1617
use rustc_span::symbol::Symbol;
17-
use rustc_ast::attr;
1818

1919
macro_rules! fake_lint_pass {
2020
($struct:ident, $($attr:expr),*) => {
@@ -50,17 +50,17 @@ declare_lint!(CRATE_NOT_GREEN, Warn, "crate not marked with #![crate_green]");
5050

5151
fake_lint_pass! {
5252
PassOkay,
53-
Symbol::intern("rustc_crate_okay")
53+
Symbol::intern("crate_okay")
5454
}
5555

5656
fake_lint_pass! {
5757
PassRedBlue,
58-
Symbol::intern("rustc_crate_red"), Symbol::intern("rustc_crate_blue")
58+
Symbol::intern("crate_red"), Symbol::intern("crate_blue")
5959
}
6060

6161
fake_lint_pass! {
6262
PassGreyGreen,
63-
Symbol::intern("rustc_crate_grey"), Symbol::intern("rustc_crate_green")
63+
Symbol::intern("crate_grey"), Symbol::intern("crate_green")
6464
}
6565

6666
#[plugin_registrar]

src/test/ui-fulldeps/auxiliary/macro-crate-test.rs

-33
This file was deleted.
+12-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
// run-pass
1+
// check-pass
22
// aux-build:lint-for-crate-rpass.rs
33
// ignore-stage1
44
// compile-flags: -D crate-not-okay
55

6-
#![feature(plugin, register_attr, custom_inner_attributes, rustc_attrs)]
6+
#![feature(plugin, register_attr, custom_inner_attributes)]
77

88
#![register_attr(
9-
rustc_crate_okay,
10-
rustc_crate_blue,
11-
rustc_crate_red,
12-
rustc_crate_grey,
13-
rustc_crate_green,
9+
crate_okay,
10+
crate_blue,
11+
crate_red,
12+
crate_grey,
13+
crate_green,
1414
)]
1515

1616
#![plugin(lint_for_crate_rpass)] //~ WARNING compiler plugins are deprecated
17-
#![rustc_crate_okay]
18-
#![rustc_crate_blue]
19-
#![rustc_crate_red]
20-
#![rustc_crate_grey]
21-
#![rustc_crate_green]
17+
#![crate_okay]
18+
#![crate_blue]
19+
#![crate_red]
20+
#![crate_grey]
21+
#![crate_green]
2222

2323
fn main() {}

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

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
1-
error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
1+
error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
22
--> $DIR/feature-gate-rustc-attrs.rs:8:3
33
|
44
LL | #[rustc::unknown]
55
| ^^^^^
6-
|
7-
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
86

97
error: expected attribute, found macro `rustc::unknown`
108
--> $DIR/feature-gate-rustc-attrs.rs:8:3
119
|
1210
LL | #[rustc::unknown]
1311
| ^^^^^^^^^^^^^^ not an attribute
1412

15-
error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
13+
error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
1614
--> $DIR/feature-gate-rustc-attrs.rs:13:12
1715
|
1816
LL | #[unknown::rustc]
1917
| ^^^^^
20-
|
21-
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
2218

2319
error: expected attribute, found macro `unknown::rustc`
2420
--> $DIR/feature-gate-rustc-attrs.rs:13:3
2521
|
2622
LL | #[unknown::rustc]
2723
| ^^^^^^^^^^^^^^ not an attribute
2824

29-
error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
25+
error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
3026
--> $DIR/feature-gate-rustc-attrs.rs:20:3
3127
|
3228
LL | #[rustc_unknown]
3329
| ^^^^^^^^^^^^^
34-
|
35-
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
3630

3731
error: cannot find attribute `rustc_unknown` in this scope
3832
--> $DIR/feature-gate-rustc-attrs.rs:20:3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![deny(unused)]
5+
#![crate_type = "proc-macro"]
6+
7+
extern crate proc_macro;
8+
use proc_macro::*;
9+
10+
#[proc_macro_attribute]
11+
pub fn duplicate(attr: TokenStream, item: TokenStream) -> TokenStream {
12+
let mut new_name = Some(attr.into_iter().nth(0).unwrap());
13+
let mut encountered_idents = 0;
14+
let input = item.to_string();
15+
let ret = item
16+
.into_iter()
17+
.map(move |token| match token {
18+
TokenTree::Ident(_) if encountered_idents == 1 => {
19+
encountered_idents += 1;
20+
new_name.take().unwrap()
21+
}
22+
TokenTree::Ident(_) => {
23+
encountered_idents += 1;
24+
token
25+
}
26+
_ => token,
27+
})
28+
.collect::<TokenStream>();
29+
let mut input_again = input.parse::<TokenStream>().unwrap();
30+
input_again.extend(ret);
31+
input_again
32+
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
1+
error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
22
--> $DIR/expand-to-unstable-2.rs:10:10
33
|
44
LL | #[derive(Unstable)]
55
| ^^^^^^^^
66
|
7-
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
87
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
98

109
error: aborting due to previous error
1110

12-
For more information about this error, try `rustc --explain E0658`.

src/test/ui-fulldeps/macro-crate-multi-decorator.rs src/test/ui/proc-macro/macro-crate-multi-decorator.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
1-
// check-pass
2-
// aux-build:macro-crate-test.rs
3-
// ignore-stage1
1+
// The duplicate macro will create a copy of the item with the given identifier.
42

5-
#![feature(rustc_attrs)]
3+
// check-pass
4+
// aux-build:duplicate.rs
65

76
#[macro_use]
8-
extern crate macro_crate_test;
9-
10-
// The duplicate macro will create a copy of the item with the given identifier.
7+
extern crate duplicate;
118

12-
#[rustc_duplicate(MyCopy)]
9+
#[duplicate(MyCopy)]
1310
struct MyStruct {
14-
number: i32
11+
number: i32,
1512
}
1613

1714
trait TestTrait {
18-
#[rustc_duplicate(TestType2)]
15+
#[duplicate(TestType2)]
1916
type TestType;
2017

21-
#[rustc_duplicate(required_fn2)]
18+
#[duplicate(required_fn2)]
2219
fn required_fn(&self);
2320

24-
#[rustc_duplicate(provided_fn2)]
25-
fn provided_fn(&self) { }
21+
#[duplicate(provided_fn2)]
22+
fn provided_fn(&self) {}
2623
}
2724

2825
impl TestTrait for MyStruct {
29-
#[rustc_duplicate(TestType2)]
26+
#[duplicate(TestType2)]
3027
type TestType = f64;
3128

32-
#[rustc_duplicate(required_fn2)]
33-
fn required_fn(&self) { }
29+
#[duplicate(required_fn2)]
30+
fn required_fn(&self) {}
3431
}
3532

3633
fn main() {

src/test/ui/reserved/reserved-attr-on-macro.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
1+
error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
22
--> $DIR/reserved-attr-on-macro.rs:1:3
33
|
44
LL | #[rustc_attribute_should_be_reserved]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
86

97
error: cannot determine resolution for the macro `foo`
108
--> $DIR/reserved-attr-on-macro.rs:10:5
@@ -22,4 +20,3 @@ LL | #[rustc_attribute_should_be_reserved]
2220

2321
error: aborting due to 3 previous errors
2422

25-
For more information about this error, try `rustc --explain E0658`.

src/test/ui/suggestions/attribute-typos.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
1+
error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
22
--> $DIR/attribute-typos.rs:11:3
33
|
44
LL | #[rustc_err]
55
| ^^^^^^^^^
6-
|
7-
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
86

97
error: cannot find attribute `rustc_err` in this scope
108
--> $DIR/attribute-typos.rs:11:3
@@ -31,4 +29,3 @@ LL | #[deprcated]
3129

3230
error: aborting due to 4 previous errors
3331

34-
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)