Skip to content

Commit b96b9f2

Browse files
committed
make FCW into error for #[should_panic] and #[ignore]
1 parent 1102efa commit b96b9f2

11 files changed

Lines changed: 157 additions & 204 deletions

compiler/rustc_passes/messages.ftl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ passes_attr_crate_level =
3535
.note = read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
3636
3737
passes_attr_must_be_applied_to_test_or_bench = `#[{$attr_name}]` should only be applied to functions annotated with `#[test]` or `#[bench]`
38-
.warn = {-passes_previously_accepted}
3938
4039
passes_autodiff_attr =
4140
`#[autodiff]` should be applied to a function

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
457457
// The error message only makes sense if it's actually being applied on a function
458458
if matches!(target, Target::Fn) {
459459
if !find_attr!(attrs, AttributeKind::TestTrace) {
460-
self.dcx().emit_warn(errors::MustBeAppliedToTest {
461-
attr_span,
462-
attr_name: sym::ignore,
463-
warning: true,
464-
});
460+
self.dcx()
461+
.emit_err(errors::MustBeAppliedToTest { attr_span, attr_name: sym::ignore });
465462
}
466463
}
467464
}
@@ -470,10 +467,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
470467
// The error message only makes sense if it's actually being applied on a function
471468
if matches!(target, Target::Fn) {
472469
if !find_attr!(attrs, AttributeKind::TestTrace) {
473-
self.dcx().emit_warn(errors::MustBeAppliedToTest {
470+
self.dcx().emit_err(errors::MustBeAppliedToTest {
474471
attr_span,
475472
attr_name: sym::should_panic,
476-
warning: true,
477473
});
478474
}
479475
}

compiler/rustc_passes/src/errors.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,5 @@ pub(crate) struct FunctionNamesDuplicated {
13661366
pub(crate) struct MustBeAppliedToTest {
13671367
#[primary_span]
13681368
pub attr_span: Span,
1369-
#[warning]
1370-
pub warning: bool,
13711369
pub attr_name: Symbol,
13721370
}

tests/ui/attributes/ignore.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
//@ check-pass
21
#![feature(test)]
32

43
#[ignore]
5-
//~^ WARN `#[ignore]` should only be applied to functions annotated with `#[test]` or `#[bench]`
6-
//~| WARN this was previously accepted
4+
//~^ ERROR `#[ignore]` should only be applied to functions annotated with `#[test]` or `#[bench]`
75
pub fn foo() {}
86

97

tests/ui/attributes/ignore.stderr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
warning: `#[ignore]` should only be applied to functions annotated with `#[test]` or `#[bench]`
2-
--> $DIR/ignore.rs:4:1
1+
error: `#[ignore]` should only be applied to functions annotated with `#[test]` or `#[bench]`
2+
--> $DIR/ignore.rs:3:1
33
|
44
LL | #[ignore]
55
| ^^^^^^^^^
6-
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
86

9-
warning: 1 warning emitted
7+
error: aborting due to 1 previous error
108

tests/ui/attributes/should-panic.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
//@ check-pass
21
#![feature(test)]
32

43
#[should_panic]
5-
//~^ WARN `#[should_panic]` should only be applied to functions annotated with `#[test]` or `#[bench]`
6-
//~| WARN this was previously accepted
4+
//~^ ERROR `#[should_panic]` should only be applied to functions annotated with `#[test]` or `#[bench]`
75
pub fn foo() {}
86

97

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
warning: `#[should_panic]` should only be applied to functions annotated with `#[test]` or `#[bench]`
2-
--> $DIR/should-panic.rs:4:1
1+
error: `#[should_panic]` should only be applied to functions annotated with `#[test]` or `#[bench]`
2+
--> $DIR/should-panic.rs:3:1
33
|
44
LL | #[should_panic]
55
| ^^^^^^^^^^^^^^^
6-
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
86

9-
warning: 1 warning emitted
7+
error: aborting due to 1 previous error
108

tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ fn aa() {}
1111

1212
#[unsafe(ignore = "test")]
1313
//~^ ERROR: is not an unsafe attribute
14-
//~| WARN`#[ignore]` should only be applied to functions annotated with `#[test]` or `#[bench]`
15-
//~| WARN this was previously accepted by the compiler
14+
//~| ERROR `#[ignore]` should only be applied to functions annotated with `#[test]` or `#[bench]`
1615
fn bb() {}
1716

1817
#[unsafe(should_panic(expected = "test"))]
1918
//~^ ERROR: is not an unsafe attribute
20-
//~| WARN `#[should_panic]` should only be applied to functions annotated with `#[test]` or `#[bench]`
21-
//~| WARN this was previously accepted
19+
//~| ERROR `#[should_panic]` should only be applied to functions annotated with `#[test]` or `#[bench]`
2220
fn cc() {}
2321

2422
#[unsafe(macro_use)] //~ ERROR: is not an unsafe attribute

tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ LL | #[unsafe(test)]
2323
= note: extraneous unsafe is not allowed in attributes
2424

2525
error: expected identifier, found keyword `unsafe`
26-
--> $DIR/extraneous-unsafe-attributes.rs:36:19
26+
--> $DIR/extraneous-unsafe-attributes.rs:34:19
2727
|
2828
LL | let _a = cfg!(unsafe(foo));
2929
| ^^^^^^ expected identifier, found keyword
@@ -34,7 +34,7 @@ LL | let _a = cfg!(r#unsafe(foo));
3434
| ++
3535

3636
error[E0537]: invalid predicate `r#unsafe`
37-
--> $DIR/extraneous-unsafe-attributes.rs:36:19
37+
--> $DIR/extraneous-unsafe-attributes.rs:34:19
3838
|
3939
LL | let _a = cfg!(unsafe(foo));
4040
| ^^^^^^^^^^^
@@ -48,53 +48,49 @@ LL | #[unsafe(ignore = "test")]
4848
= note: extraneous unsafe is not allowed in attributes
4949

5050
error: `should_panic` is not an unsafe attribute
51-
--> $DIR/extraneous-unsafe-attributes.rs:18:3
51+
--> $DIR/extraneous-unsafe-attributes.rs:17:3
5252
|
5353
LL | #[unsafe(should_panic(expected = "test"))]
5454
| ^^^^^^ this is not an unsafe attribute
5555
|
5656
= note: extraneous unsafe is not allowed in attributes
5757

5858
error: `macro_use` is not an unsafe attribute
59-
--> $DIR/extraneous-unsafe-attributes.rs:24:3
59+
--> $DIR/extraneous-unsafe-attributes.rs:22:3
6060
|
6161
LL | #[unsafe(macro_use)]
6262
| ^^^^^^ this is not an unsafe attribute
6363
|
6464
= note: extraneous unsafe is not allowed in attributes
6565

6666
error: `macro_export` is not an unsafe attribute
67-
--> $DIR/extraneous-unsafe-attributes.rs:26:7
67+
--> $DIR/extraneous-unsafe-attributes.rs:24:7
6868
|
6969
LL | #[unsafe(macro_export)]
7070
| ^^^^^^ this is not an unsafe attribute
7171
|
7272
= note: extraneous unsafe is not allowed in attributes
7373

7474
error: `used` is not an unsafe attribute
75-
--> $DIR/extraneous-unsafe-attributes.rs:32:3
75+
--> $DIR/extraneous-unsafe-attributes.rs:30:3
7676
|
7777
LL | #[unsafe(used)]
7878
| ^^^^^^ this is not an unsafe attribute
7979
|
8080
= note: extraneous unsafe is not allowed in attributes
8181

82-
warning: `#[ignore]` should only be applied to functions annotated with `#[test]` or `#[bench]`
82+
error: `#[ignore]` should only be applied to functions annotated with `#[test]` or `#[bench]`
8383
--> $DIR/extraneous-unsafe-attributes.rs:12:1
8484
|
8585
LL | #[unsafe(ignore = "test")]
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
87-
|
88-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8987

90-
warning: `#[should_panic]` should only be applied to functions annotated with `#[test]` or `#[bench]`
91-
--> $DIR/extraneous-unsafe-attributes.rs:18:1
88+
error: `#[should_panic]` should only be applied to functions annotated with `#[test]` or `#[bench]`
89+
--> $DIR/extraneous-unsafe-attributes.rs:17:1
9290
|
9391
LL | #[unsafe(should_panic(expected = "test"))]
9492
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
95-
|
96-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9793

98-
error: aborting due to 10 previous errors; 2 warnings emitted
94+
error: aborting due to 12 previous errors
9995

10096
For more information about this error, try `rustc --explain E0537`.

tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,6 @@ mod should_panic {
382382
//~| HELP can only be applied to
383383
//~| HELP remove the attribute
384384

385-
#[should_panic]
386-
//~^ WARN `#[should_panic]` should only be applied to functions annotated with `#[test]` or `#[bench]`
387-
//~| WARN this was previously accepted
388-
fn f() { }
389-
390385
#[should_panic] struct S;
391386
//~^ WARN attribute cannot be used on
392387
//~| WARN previously accepted
@@ -418,11 +413,6 @@ mod ignore {
418413
//~| HELP can only be applied to
419414
//~| HELP remove the attribute
420415

421-
#[ignore]
422-
//~^ WARN`#[ignore]` should only be applied to functions annotated with `#[test]` or `#[bench]`
423-
//~| WARN this was previously accepted by the compiler
424-
fn f() { }
425-
426416
#[ignore] struct S;
427417
//~^ WARN attribute cannot be used on
428418
//~| WARN previously accepted

0 commit comments

Comments
 (0)