Skip to content

Commit cc6baf7

Browse files
committed
rustc_expand: Mark inner #![test] attributes as soft-unstable
1 parent 9722952 commit cc6baf7

File tree

8 files changed

+42
-18
lines changed

8 files changed

+42
-18
lines changed

compiler/rustc_expand/src/expand.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_errors::{struct_span_err, Applicability, PResult};
2222
use rustc_feature::Features;
2323
use rustc_parse::parser::{AttemptLocalParseRecovery, Parser};
2424
use rustc_parse::validate_attr;
25-
use rustc_session::lint::builtin::UNUSED_DOC_COMMENTS;
25+
use rustc_session::lint::builtin::{SOFT_UNSTABLE, UNUSED_DOC_COMMENTS};
2626
use rustc_session::lint::BuiltinLintDiagnostics;
2727
use rustc_session::parse::{feature_err, ParseSess};
2828
use rustc_session::Limit;
@@ -1064,17 +1064,24 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10641064
})
10651065
.map(|i| attrs.remove(i));
10661066
if let Some(attr) = &attr {
1067-
if !self.cx.ecfg.custom_inner_attributes()
1068-
&& attr.style == ast::AttrStyle::Inner
1069-
&& !attr.has_name(sym::test)
1070-
{
1071-
feature_err(
1072-
&self.cx.sess.parse_sess,
1073-
sym::custom_inner_attributes,
1074-
attr.span,
1075-
"non-builtin inner attributes are unstable",
1076-
)
1077-
.emit();
1067+
if attr.style == ast::AttrStyle::Inner && !self.cx.ecfg.custom_inner_attributes() {
1068+
let msg = "non-builtin inner attributes are unstable";
1069+
if attr.has_name(sym::test) {
1070+
self.cx.sess.parse_sess.buffer_lint(
1071+
SOFT_UNSTABLE,
1072+
attr.span,
1073+
ast::CRATE_NODE_ID,
1074+
msg,
1075+
);
1076+
} else {
1077+
feature_err(
1078+
&self.cx.sess.parse_sess,
1079+
sym::custom_inner_attributes,
1080+
attr.span,
1081+
msg,
1082+
)
1083+
.emit();
1084+
}
10781085
}
10791086
}
10801087
attr

library/std/src/num/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ fn test_checked_mul() {
7575

7676
macro_rules! test_is_power_of_two {
7777
($test_name:ident, $T:ident) => {
78+
#[test]
7879
fn $test_name() {
79-
#![test]
8080
assert_eq!((0 as $T).is_power_of_two(), false);
8181
assert_eq!((1 as $T).is_power_of_two(), true);
8282
assert_eq!((2 as $T).is_power_of_two(), true);
@@ -96,8 +96,8 @@ test_is_power_of_two! { test_is_power_of_two_uint, usize }
9696

9797
macro_rules! test_next_power_of_two {
9898
($test_name:ident, $T:ident) => {
99+
#[test]
99100
fn $test_name() {
100-
#![test]
101101
assert_eq!((0 as $T).next_power_of_two(), 1);
102102
let mut next_power = 1;
103103
for i in 1 as $T..40 {
@@ -118,8 +118,8 @@ test_next_power_of_two! { test_next_power_of_two_uint, usize }
118118

119119
macro_rules! test_checked_next_power_of_two {
120120
($test_name:ident, $T:ident) => {
121+
#[test]
121122
fn $test_name() {
122-
#![test]
123123
assert_eq!((0 as $T).checked_next_power_of_two(), Some(1));
124124
let smax = $T::MAX >> 1;
125125
assert_eq!(smax.checked_next_power_of_two(), Some(smax + 1));

src/test/ui/feature-gate/issue-43106-gating-of-test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// The non-crate level cases are in issue-43106-gating-of-builtin-attrs.rs.
22

3+
#![allow(soft_unstable)]
34
#![test = "4200"]
45
//~^ ERROR cannot determine resolution for the attribute macro `test`
56

src/test/ui/feature-gate/issue-43106-gating-of-test.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: cannot determine resolution for the attribute macro `test`
2-
--> $DIR/issue-43106-gating-of-test.rs:3:4
2+
--> $DIR/issue-43106-gating-of-test.rs:4:4
33
|
44
LL | #![test = "4200"]
55
| ^^^^

src/test/ui/issues/issue-28134.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// compile-flags: --test
22

3+
#![allow(soft_unstable)]
34
#![test] //~ ERROR cannot determine resolution for the attribute macro `test`

src/test/ui/issues/issue-28134.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: cannot determine resolution for the attribute macro `test`
2-
--> $DIR/issue-28134.rs:3:4
2+
--> $DIR/issue-28134.rs:4:4
33
|
44
LL | #![test]
55
| ^^^^

src/test/ui/proc-macro/proc-macro-gates.rs

+5
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ fn attrs() {
4545
//~^ ERROR: custom attributes cannot be applied to expressions
4646
}
4747

48+
fn test_case() {
49+
#![test] //~ ERROR non-builtin inner attributes are unstable
50+
//~| WARN this was previously accepted
51+
}
52+
4853
fn main() {}

src/test/ui/proc-macro/proc-macro-gates.stderr

+11-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ LL | let _x = #[identity_attr] println!();
7676
= note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information
7777
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable
7878

79-
error: aborting due to 9 previous errors
79+
error: non-builtin inner attributes are unstable
80+
--> $DIR/proc-macro-gates.rs:49:5
81+
|
82+
LL | #![test]
83+
| ^^^^^^^^
84+
|
85+
= note: `#[deny(soft_unstable)]` on by default
86+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
87+
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
88+
89+
error: aborting due to 10 previous errors
8090

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

0 commit comments

Comments
 (0)