Skip to content

Commit fda91cd

Browse files
committed
Improve testing coverage for #[diagnostic::do_not_recommend]
This PR aims to improve the testing coverage for `#[diagnostic::do_not_recommend]`. It ensures that all tests are run for the old and new solver to verify that the behaviour is the same for both variants. It also adds two new tests: * A test with 4 traits having wild card impl for each other, with alternating `#[diagnostic::do_not_recommend]` attributse * A test with a lifetime dependend wild card impl, which is something that's not supported yet
1 parent 3fb7e44 commit fda91cd

18 files changed

+230
-14
lines changed

tests/ui/diagnostic_namespace/do_not_recommend/do_not_apply_attribute_without_feature_flag.stderr renamed to tests/ui/diagnostic_namespace/do_not_recommend/do_not_apply_attribute_without_feature_flag.current.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `(): Foo` is not satisfied
2-
--> $DIR/do_not_apply_attribute_without_feature_flag.rs:19:11
2+
--> $DIR/do_not_apply_attribute_without_feature_flag.rs:22:11
33
|
44
LL | check(());
55
| ----- ^^ the trait `Foo` is not implemented for `()`
@@ -11,7 +11,7 @@ LL | check(());
1111
(A, B, C)
1212
(A,)
1313
note: required by a bound in `check`
14-
--> $DIR/do_not_apply_attribute_without_feature_flag.rs:16:18
14+
--> $DIR/do_not_apply_attribute_without_feature_flag.rs:19:18
1515
|
1616
LL | fn check(a: impl Foo) {}
1717
| ^^^ required by this bound in `check`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0277]: the trait bound `(): Foo` is not satisfied
2+
--> $DIR/do_not_apply_attribute_without_feature_flag.rs:22:11
3+
|
4+
LL | check(());
5+
| ----- ^^ the trait `Foo` is not implemented for `()`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= help: the following other types implement trait `Foo`:
10+
(A, B)
11+
(A, B, C)
12+
(A,)
13+
note: required by a bound in `check`
14+
--> $DIR/do_not_apply_attribute_without_feature_flag.rs:19:18
15+
|
16+
LL | fn check(a: impl Foo) {}
17+
| ^^^ required by this bound in `check`
18+
19+
error: aborting due to 1 previous error
20+
21+
For more information about this error, try `rustc --explain E0277`.

tests/ui/diagnostic_namespace/do_not_recommend/do_not_apply_attribute_without_feature_flag.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
14
#![allow(unknown_or_malformed_diagnostic_attributes)]
25

36
trait Foo {}

tests/ui/diagnostic_namespace/do_not_recommend/feature-gate-do_not_recommend.stderr renamed to tests/ui/diagnostic_namespace/do_not_recommend/feature-gate-do_not_recommend.current.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0277]: the trait bound `u8: Bar` is not satisfied
2-
--> $DIR/feature-gate-do_not_recommend.rs:15:11
2+
--> $DIR/feature-gate-do_not_recommend.rs:18:11
33
|
44
LL | stuff(1u8);
55
| ^^^ the trait `Bar` is not implemented for `u8`
66
|
77
note: required by a bound in `stuff`
8-
--> $DIR/feature-gate-do_not_recommend.rs:12:13
8+
--> $DIR/feature-gate-do_not_recommend.rs:15:13
99
|
1010
LL | fn stuff<T: Bar>(_: T) {}
1111
| ^^^ required by this bound in `stuff`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: the trait bound `u8: Bar` is not satisfied
2+
--> $DIR/feature-gate-do_not_recommend.rs:18:11
3+
|
4+
LL | stuff(1u8);
5+
| ----- ^^^ the trait `Bar` is not implemented for `u8`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
note: required by a bound in `stuff`
10+
--> $DIR/feature-gate-do_not_recommend.rs:15:13
11+
|
12+
LL | fn stuff<T: Bar>(_: T) {}
13+
| ^^^ required by this bound in `stuff`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.

tests/ui/diagnostic_namespace/do_not_recommend/feature-gate-do_not_recommend.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
14
#![feature(do_not_recommend)]
25

36
pub trait Foo {}

tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.stderr renamed to tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.current.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
2-
--> $DIR/incorrect-locations.rs:4:1
2+
--> $DIR/incorrect-locations.rs:7:1
33
|
44
LL | #[diagnostic::do_not_recommend]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default
88

99
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
10-
--> $DIR/incorrect-locations.rs:8:1
10+
--> $DIR/incorrect-locations.rs:11:1
1111
|
1212
LL | #[diagnostic::do_not_recommend]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

1515
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
16-
--> $DIR/incorrect-locations.rs:12:1
16+
--> $DIR/incorrect-locations.rs:15:1
1717
|
1818
LL | #[diagnostic::do_not_recommend]
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020

2121
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
22-
--> $DIR/incorrect-locations.rs:16:1
22+
--> $DIR/incorrect-locations.rs:19:1
2323
|
2424
LL | #[diagnostic::do_not_recommend]
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626

2727
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
28-
--> $DIR/incorrect-locations.rs:20:1
28+
--> $DIR/incorrect-locations.rs:23:1
2929
|
3030
LL | #[diagnostic::do_not_recommend]
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232

3333
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
34-
--> $DIR/incorrect-locations.rs:24:1
34+
--> $DIR/incorrect-locations.rs:27:1
3535
|
3636
LL | #[diagnostic::do_not_recommend]
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3838

3939
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
40-
--> $DIR/incorrect-locations.rs:28:1
40+
--> $DIR/incorrect-locations.rs:31:1
4141
|
4242
LL | #[diagnostic::do_not_recommend]
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444

4545
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
46-
--> $DIR/incorrect-locations.rs:32:1
46+
--> $DIR/incorrect-locations.rs:35:1
4747
|
4848
LL | #[diagnostic::do_not_recommend]
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
2+
--> $DIR/incorrect-locations.rs:7:1
3+
|
4+
LL | #[diagnostic::do_not_recommend]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default
8+
9+
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
10+
--> $DIR/incorrect-locations.rs:11:1
11+
|
12+
LL | #[diagnostic::do_not_recommend]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
16+
--> $DIR/incorrect-locations.rs:15:1
17+
|
18+
LL | #[diagnostic::do_not_recommend]
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
21+
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
22+
--> $DIR/incorrect-locations.rs:19:1
23+
|
24+
LL | #[diagnostic::do_not_recommend]
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
27+
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
28+
--> $DIR/incorrect-locations.rs:23:1
29+
|
30+
LL | #[diagnostic::do_not_recommend]
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
33+
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
34+
--> $DIR/incorrect-locations.rs:27:1
35+
|
36+
LL | #[diagnostic::do_not_recommend]
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
39+
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
40+
--> $DIR/incorrect-locations.rs:31:1
41+
|
42+
LL | #[diagnostic::do_not_recommend]
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
45+
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
46+
--> $DIR/incorrect-locations.rs:35:1
47+
|
48+
LL | #[diagnostic::do_not_recommend]
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
51+
warning: 8 warnings emitted
52+

tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
//@ check-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
25
#![feature(do_not_recommend)]
36

47
#[diagnostic::do_not_recommend]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `(): Root` is not satisfied
2+
--> $DIR/nested.rs:23:18
3+
|
4+
LL | needs_root::<()>();
5+
| ^^ the trait `Root` is not implemented for `()`
6+
|
7+
note: required by a bound in `needs_root`
8+
--> $DIR/nested.rs:20:18
9+
|
10+
LL | fn needs_root<T: Root>() {}
11+
| ^^^^ required by this bound in `needs_root`
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `(): Root` is not satisfied
2+
--> $DIR/nested.rs:23:18
3+
|
4+
LL | needs_root::<()>();
5+
| ^^ the trait `Root` is not implemented for `()`
6+
|
7+
note: required by a bound in `needs_root`
8+
--> $DIR/nested.rs:20:18
9+
|
10+
LL | fn needs_root<T: Root>() {}
11+
| ^^^^ required by this bound in `needs_root`
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
4+
5+
#![feature(do_not_recommend)]
6+
7+
trait Root {}
8+
trait DontRecommend {}
9+
trait Other {}
10+
trait Child {}
11+
12+
#[diagnostic::do_not_recommend]
13+
impl<T> Root for T where T: DontRecommend {}
14+
15+
impl<T> DontRecommend for T where T: Other {}
16+
17+
#[diagnostic::do_not_recommend]
18+
impl<T> Other for T where T: Child {}
19+
20+
fn needs_root<T: Root>() {}
21+
22+
fn main() {
23+
needs_root::<()>();
24+
//~^ ERROR the trait bound `(): Root` is not satisfied
25+
}

tests/ui/diagnostic_namespace/do_not_recommend/unstable-feature.stderr renamed to tests/ui/diagnostic_namespace/do_not_recommend/unstable-feature.current.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: unknown diagnostic attribute
2-
--> $DIR/unstable-feature.rs:4:15
2+
--> $DIR/unstable-feature.rs:7:15
33
|
44
LL | #[diagnostic::do_not_recommend]
55
| ^^^^^^^^^^^^^^^^
66
|
77
note: the lint level is defined here
8-
--> $DIR/unstable-feature.rs:1:9
8+
--> $DIR/unstable-feature.rs:4:9
99
|
1010
LL | #![deny(unknown_or_malformed_diagnostic_attributes)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unknown diagnostic attribute
2+
--> $DIR/unstable-feature.rs:7:15
3+
|
4+
LL | #[diagnostic::do_not_recommend]
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unstable-feature.rs:4:9
9+
|
10+
LL | #![deny(unknown_or_malformed_diagnostic_attributes)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+

tests/ui/diagnostic_namespace/do_not_recommend/unstable-feature.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
14
#![deny(unknown_or_malformed_diagnostic_attributes)]
25
trait Foo {}
36

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/with_lifetime.rs:19:5
3+
|
4+
LL | fn foo<'a>(a: &'a ()) {
5+
| -- lifetime `'a` defined here
6+
LL | needs_root::<&'a ()>();
7+
| ^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
8+
9+
error: aborting due to 1 previous error
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/with_lifetime.rs:19:5
3+
|
4+
LL | fn foo<'a>(a: &'a ()) {
5+
| -- lifetime `'a` defined here
6+
LL | needs_root::<&'a ()>();
7+
| ^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
8+
9+
error: aborting due to 1 previous error
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
4+
5+
#![feature(do_not_recommend)]
6+
7+
trait Root {}
8+
trait DontRecommend {}
9+
10+
impl<T> Root for T where T: DontRecommend {}
11+
12+
// this has no effect yet for resolving the trait error below
13+
#[diagnostic::do_not_recommend]
14+
impl<T> DontRecommend for &'static T {}
15+
16+
fn needs_root<T: Root>() {}
17+
18+
fn foo<'a>(a: &'a ()) {
19+
needs_root::<&'a ()>();
20+
//~^ ERROR lifetime may not live long enough
21+
}
22+
23+
fn main() {
24+
foo(&());
25+
}

0 commit comments

Comments
 (0)