Skip to content

Commit cb2a31c

Browse files
committed
fully de-stabilize all custom inner attributes
1 parent 4847d6a commit cb2a31c

6 files changed

+40
-97
lines changed

compiler/rustc_resolve/src/macros.rs

+9-42
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ use std::cell::Cell;
55
use std::mem;
66

77
use rustc_ast::expand::StrippedCfgItem;
8-
use rustc_ast::{self as ast, Crate, Inline, ItemKind, ModKind, NodeId, attr};
8+
use rustc_ast::{self as ast, Crate, NodeId, attr};
99
use rustc_ast_pretty::pprust;
1010
use rustc_attr::StabilityLevel;
1111
use rustc_data_structures::intern::Interned;
1212
use rustc_data_structures::sync::Lrc;
1313
use rustc_errors::{Applicability, StashKey};
1414
use rustc_expand::base::{
15-
Annotatable, DeriveResolution, Indeterminate, ResolverExpand, SyntaxExtension,
16-
SyntaxExtensionKind,
15+
DeriveResolution, Indeterminate, ResolverExpand, SyntaxExtension, SyntaxExtensionKind,
1716
};
1817
use rustc_expand::compile_declarative_macro;
1918
use rustc_expand::expand::{
@@ -25,8 +24,8 @@ use rustc_middle::middle::stability;
2524
use rustc_middle::ty::{RegisteredTools, TyCtxt, Visibility};
2625
use rustc_session::lint::BuiltinLintDiag;
2726
use rustc_session::lint::builtin::{
28-
LEGACY_DERIVE_HELPERS, OUT_OF_SCOPE_MACRO_CALLS, SOFT_UNSTABLE,
29-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_MACRO_RULES, UNUSED_MACROS,
27+
LEGACY_DERIVE_HELPERS, OUT_OF_SCOPE_MACRO_CALLS, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
28+
UNUSED_MACRO_RULES, UNUSED_MACROS,
3029
};
3130
use rustc_session::parse::feature_err;
3231
use rustc_span::edit_distance::edit_distance;
@@ -157,26 +156,6 @@ pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools {
157156
registered_tools
158157
}
159158

160-
// Some feature gates for inner attributes are reported as lints for backward compatibility.
161-
fn soft_custom_inner_attributes_gate(path: &ast::Path, invoc: &Invocation) -> bool {
162-
match &path.segments[..] {
163-
// `#![test]`
164-
[seg] if seg.ident.name == sym::test => return true,
165-
// `#![rustfmt::skip]` on out-of-line modules
166-
[seg1, seg2] if seg1.ident.name == sym::rustfmt && seg2.ident.name == sym::skip => {
167-
if let InvocationKind::Attr { item, .. } = &invoc.kind {
168-
if let Annotatable::Item(item) = item {
169-
if let ItemKind::Mod(_, ModKind::Loaded(_, Inline::No, _)) = item.kind {
170-
return true;
171-
}
172-
}
173-
}
174-
}
175-
_ => {}
176-
}
177-
false
178-
}
179-
180159
impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
181160
fn next_node_id(&mut self) -> NodeId {
182161
self.next_node_id()
@@ -317,7 +296,6 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
317296
parent_scope,
318297
node_id,
319298
force,
320-
soft_custom_inner_attributes_gate(path, invoc),
321299
deleg_impl,
322300
looks_like_invoc_in_mod_inert_attr,
323301
)?;
@@ -549,7 +527,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
549527
parent_scope: &ParentScope<'ra>,
550528
node_id: NodeId,
551529
force: bool,
552-
soft_custom_inner_attributes_gate: bool,
553530
deleg_impl: Option<LocalDefId>,
554531
invoc_in_mod_inert_attr: Option<LocalDefId>,
555532
) -> Result<(Lrc<SyntaxExtension>, Res), Indeterminate> {
@@ -667,22 +644,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
667644
Res::NonMacroAttr(..) => false,
668645
_ => unreachable!(),
669646
};
670-
if soft_custom_inner_attributes_gate {
671-
self.tcx.sess.psess.buffer_lint(
672-
SOFT_UNSTABLE,
673-
path.span,
674-
node_id,
675-
BuiltinLintDiag::InnerAttributeUnstable { is_macro },
676-
);
647+
let msg = if is_macro {
648+
"inner macro attributes are unstable"
677649
} else {
678-
// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::InnerAttributeUnstable`)
679-
let msg = if is_macro {
680-
"inner macro attributes are unstable"
681-
} else {
682-
"custom inner attributes are unstable"
683-
};
684-
feature_err(&self.tcx.sess, sym::custom_inner_attributes, path.span, msg).emit();
685-
}
650+
"custom inner attributes are unstable"
651+
};
652+
feature_err(&self.tcx.sess, sym::custom_inner_attributes, path.span, msg).emit();
686653
}
687654

688655
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)

tests/ui/proc-macro/inner-attr-non-inline-mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@ compile-flags: -Z span-debug
22
//@ error-pattern:custom inner attributes are unstable
33
//@ error-pattern:inner macro attributes are unstable
4-
//@ error-pattern:this was previously accepted
54
//@ proc-macro: test-macros.rs
65

76
#![no_std] // Don't load unnecessary hygiene information from std
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
error[E0658]: custom inner attributes are unstable
2+
--> $DIR/module_with_attrs.rs:3:4
3+
|
4+
LL | #![rustfmt::skip]
5+
| ^^^^^^^^^^^^^
6+
|
7+
= note: see issue #54726 <https://github.com/rust-lang/rust/issues/54726> for more information
8+
= help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
111
error[E0658]: inner macro attributes are unstable
212
--> $DIR/module_with_attrs.rs:4:4
313
|
@@ -9,7 +19,7 @@ LL | #![print_attr]
919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1020

1121
error[E0658]: non-inline modules in proc macro input are unstable
12-
--> $DIR/inner-attr-non-inline-mod.rs:14:1
22+
--> $DIR/inner-attr-non-inline-mod.rs:13:1
1323
|
1424
LL | mod module_with_attrs;
1525
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -19,7 +29,7 @@ LL | mod module_with_attrs;
1929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2030

2131
error[E0658]: custom inner attributes are unstable
22-
--> $DIR/inner-attr-non-inline-mod.rs:14:1
32+
--> $DIR/inner-attr-non-inline-mod.rs:13:1
2333
|
2434
LL | mod module_with_attrs;
2535
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -28,27 +38,6 @@ LL | mod module_with_attrs;
2838
= help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable
2939
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3040

31-
error: custom inner attributes are unstable
32-
--> $DIR/module_with_attrs.rs:3:4
33-
|
34-
LL | #![rustfmt::skip]
35-
| ^^^^^^^^^^^^^
36-
|
37-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
38-
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
39-
= note: `#[deny(soft_unstable)]` on by default
40-
4141
error: aborting due to 4 previous errors
4242

4343
For more information about this error, try `rustc --explain E0658`.
44-
Future incompatibility report: Future breakage diagnostic:
45-
error: custom inner attributes are unstable
46-
--> $DIR/module_with_attrs.rs:3:4
47-
|
48-
LL | #![rustfmt::skip]
49-
| ^^^^^^^^^^^^^
50-
|
51-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
52-
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
53-
= note: `#[deny(soft_unstable)]` on by default
54-

tests/ui/proc-macro/inner-attr-non-inline-mod.stdout

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,74 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
44
Punct {
55
ch: '#',
66
spacing: Alone,
7-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
7+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
88
},
99
Group {
1010
delimiter: Bracket,
1111
stream: TokenStream [
1212
Ident {
1313
ident: "deny",
14-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
14+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
1515
},
1616
Group {
1717
delimiter: Parenthesis,
1818
stream: TokenStream [
1919
Ident {
2020
ident: "unused_attributes",
21-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
21+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
2222
},
2323
],
24-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
24+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
2525
},
2626
],
27-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
27+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
2828
},
2929
Ident {
3030
ident: "mod",
31-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
31+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
3232
},
3333
Ident {
3434
ident: "module_with_attrs",
35-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
35+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
3636
},
3737
Group {
3838
delimiter: Brace,
3939
stream: TokenStream [
4040
Punct {
4141
ch: '#',
4242
spacing: Joint,
43-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
43+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
4444
},
4545
Punct {
4646
ch: '!',
4747
spacing: Alone,
48-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
48+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
4949
},
5050
Group {
5151
delimiter: Bracket,
5252
stream: TokenStream [
5353
Ident {
5454
ident: "rustfmt",
55-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
55+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
5656
},
5757
Punct {
5858
ch: ':',
5959
spacing: Joint,
60-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
60+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
6161
},
6262
Punct {
6363
ch: ':',
6464
spacing: Alone,
65-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
65+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
6666
},
6767
Ident {
6868
ident: "skip",
69-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
69+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
7070
},
7171
],
72-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
72+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
7373
},
7474
],
75-
span: $DIR/inner-attr-non-inline-mod.rs:14:1: 14:23 (#0),
75+
span: $DIR/inner-attr-non-inline-mod.rs:13:1: 13:23 (#0),
7676
},
7777
]

tests/ui/proc-macro/proc-macro-gates.rs

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ fn attrs() {
4747

4848
fn test_case() {
4949
#![test] //~ ERROR inner macro attributes are unstable
50-
//~| WARN this was previously accepted
5150
}
5251

5352
fn main() {}

tests/ui/proc-macro/proc-macro-gates.stderr

+4-15
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,16 @@ LL | let _x = #[identity_attr] println!();
8484
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable
8585
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
8686

87-
error: inner macro attributes are unstable
87+
error[E0658]: inner macro attributes are unstable
8888
--> $DIR/proc-macro-gates.rs:49:8
8989
|
9090
LL | #![test]
9191
| ^^^^
9292
|
93-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
94-
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
95-
= note: `#[deny(soft_unstable)]` on by default
93+
= note: see issue #54726 <https://github.com/rust-lang/rust/issues/54726> for more information
94+
= help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable
95+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
9696

9797
error: aborting due to 10 previous errors
9898

9999
For more information about this error, try `rustc --explain E0658`.
100-
Future incompatibility report: Future breakage diagnostic:
101-
error: inner macro attributes are unstable
102-
--> $DIR/proc-macro-gates.rs:49:8
103-
|
104-
LL | #![test]
105-
| ^^^^
106-
|
107-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
108-
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
109-
= note: `#[deny(soft_unstable)]` on by default
110-

0 commit comments

Comments
 (0)