1
Fork 0

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
This commit is contained in:
Georg Semmler 2024-10-22 19:48:11 +02:00
parent a89ca2c85e
commit bfd02d8b36
No known key found for this signature in database
GPG key ID: A87BCEE5205CE489
18 changed files with 230 additions and 14 deletions

View file

@ -1,5 +1,5 @@
error[E0277]: the trait bound `(): Foo` is not satisfied error[E0277]: the trait bound `(): Foo` is not satisfied
--> $DIR/do_not_apply_attribute_without_feature_flag.rs:19:11 --> $DIR/do_not_apply_attribute_without_feature_flag.rs:22:11
| |
LL | check(()); LL | check(());
| ----- ^^ the trait `Foo` is not implemented for `()` | ----- ^^ the trait `Foo` is not implemented for `()`
@ -11,7 +11,7 @@ LL | check(());
(A, B, C) (A, B, C)
(A,) (A,)
note: required by a bound in `check` note: required by a bound in `check`
--> $DIR/do_not_apply_attribute_without_feature_flag.rs:16:18 --> $DIR/do_not_apply_attribute_without_feature_flag.rs:19:18
| |
LL | fn check(a: impl Foo) {} LL | fn check(a: impl Foo) {}
| ^^^ required by this bound in `check` | ^^^ required by this bound in `check`

View file

@ -0,0 +1,21 @@
error[E0277]: the trait bound `(): Foo` is not satisfied
--> $DIR/do_not_apply_attribute_without_feature_flag.rs:22:11
|
LL | check(());
| ----- ^^ the trait `Foo` is not implemented for `()`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `Foo`:
(A, B)
(A, B, C)
(A,)
note: required by a bound in `check`
--> $DIR/do_not_apply_attribute_without_feature_flag.rs:19:18
|
LL | fn check(a: impl Foo) {}
| ^^^ required by this bound in `check`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,3 +1,6 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
#![allow(unknown_or_malformed_diagnostic_attributes)] #![allow(unknown_or_malformed_diagnostic_attributes)]
trait Foo {} trait Foo {}

View file

@ -1,11 +1,11 @@
error[E0277]: the trait bound `u8: Bar` is not satisfied error[E0277]: the trait bound `u8: Bar` is not satisfied
--> $DIR/feature-gate-do_not_recommend.rs:15:11 --> $DIR/feature-gate-do_not_recommend.rs:18:11
| |
LL | stuff(1u8); LL | stuff(1u8);
| ^^^ the trait `Bar` is not implemented for `u8` | ^^^ the trait `Bar` is not implemented for `u8`
| |
note: required by a bound in `stuff` note: required by a bound in `stuff`
--> $DIR/feature-gate-do_not_recommend.rs:12:13 --> $DIR/feature-gate-do_not_recommend.rs:15:13
| |
LL | fn stuff<T: Bar>(_: T) {} LL | fn stuff<T: Bar>(_: T) {}
| ^^^ required by this bound in `stuff` | ^^^ required by this bound in `stuff`

View file

@ -0,0 +1,17 @@
error[E0277]: the trait bound `u8: Bar` is not satisfied
--> $DIR/feature-gate-do_not_recommend.rs:18:11
|
LL | stuff(1u8);
| ----- ^^^ the trait `Bar` is not implemented for `u8`
| |
| required by a bound introduced by this call
|
note: required by a bound in `stuff`
--> $DIR/feature-gate-do_not_recommend.rs:15:13
|
LL | fn stuff<T: Bar>(_: T) {}
| ^^^ required by this bound in `stuff`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,3 +1,6 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
#![feature(do_not_recommend)] #![feature(do_not_recommend)]
pub trait Foo {} pub trait Foo {}

View file

@ -1,5 +1,5 @@
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:4:1 --> $DIR/incorrect-locations.rs:7:1
| |
LL | #[diagnostic::do_not_recommend] LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -7,43 +7,43 @@ LL | #[diagnostic::do_not_recommend]
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default = note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:8:1 --> $DIR/incorrect-locations.rs:11:1
| |
LL | #[diagnostic::do_not_recommend] LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:12:1 --> $DIR/incorrect-locations.rs:15:1
| |
LL | #[diagnostic::do_not_recommend] LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:16:1 --> $DIR/incorrect-locations.rs:19:1
| |
LL | #[diagnostic::do_not_recommend] LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:20:1 --> $DIR/incorrect-locations.rs:23:1
| |
LL | #[diagnostic::do_not_recommend] LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:24:1 --> $DIR/incorrect-locations.rs:27:1
| |
LL | #[diagnostic::do_not_recommend] LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:28:1 --> $DIR/incorrect-locations.rs:31:1
| |
LL | #[diagnostic::do_not_recommend] LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:32:1 --> $DIR/incorrect-locations.rs:35:1
| |
LL | #[diagnostic::do_not_recommend] LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -0,0 +1,52 @@
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:7:1
|
LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:11:1
|
LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:15:1
|
LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:19:1
|
LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:23:1
|
LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:27:1
|
LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:31:1
|
LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
--> $DIR/incorrect-locations.rs:35:1
|
LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: 8 warnings emitted

View file

@ -1,4 +1,7 @@
//@ check-pass //@ check-pass
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
#![feature(do_not_recommend)] #![feature(do_not_recommend)]
#[diagnostic::do_not_recommend] #[diagnostic::do_not_recommend]

View file

@ -0,0 +1,15 @@
error[E0277]: the trait bound `(): Root` is not satisfied
--> $DIR/nested.rs:23:18
|
LL | needs_root::<()>();
| ^^ the trait `Root` is not implemented for `()`
|
note: required by a bound in `needs_root`
--> $DIR/nested.rs:20:18
|
LL | fn needs_root<T: Root>() {}
| ^^^^ required by this bound in `needs_root`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -0,0 +1,15 @@
error[E0277]: the trait bound `(): Root` is not satisfied
--> $DIR/nested.rs:23:18
|
LL | needs_root::<()>();
| ^^ the trait `Root` is not implemented for `()`
|
note: required by a bound in `needs_root`
--> $DIR/nested.rs:20:18
|
LL | fn needs_root<T: Root>() {}
| ^^^^ required by this bound in `needs_root`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -0,0 +1,25 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
#![feature(do_not_recommend)]
trait Root {}
trait DontRecommend {}
trait Other {}
trait Child {}
#[diagnostic::do_not_recommend]
impl<T> Root for T where T: DontRecommend {}
impl<T> DontRecommend for T where T: Other {}
#[diagnostic::do_not_recommend]
impl<T> Other for T where T: Child {}
fn needs_root<T: Root>() {}
fn main() {
needs_root::<()>();
//~^ ERROR the trait bound `(): Root` is not satisfied
}

View file

@ -1,11 +1,11 @@
error: unknown diagnostic attribute error: unknown diagnostic attribute
--> $DIR/unstable-feature.rs:4:15 --> $DIR/unstable-feature.rs:7:15
| |
LL | #[diagnostic::do_not_recommend] LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/unstable-feature.rs:1:9 --> $DIR/unstable-feature.rs:4:9
| |
LL | #![deny(unknown_or_malformed_diagnostic_attributes)] LL | #![deny(unknown_or_malformed_diagnostic_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -0,0 +1,14 @@
error: unknown diagnostic attribute
--> $DIR/unstable-feature.rs:7:15
|
LL | #[diagnostic::do_not_recommend]
| ^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/unstable-feature.rs:4:9
|
LL | #![deny(unknown_or_malformed_diagnostic_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error

View file

@ -1,3 +1,6 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
#![deny(unknown_or_malformed_diagnostic_attributes)] #![deny(unknown_or_malformed_diagnostic_attributes)]
trait Foo {} trait Foo {}

View file

@ -0,0 +1,10 @@
error: lifetime may not live long enough
--> $DIR/with_lifetime.rs:19:5
|
LL | fn foo<'a>(a: &'a ()) {
| -- lifetime `'a` defined here
LL | needs_root::<&'a ()>();
| ^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
error: aborting due to 1 previous error

View file

@ -0,0 +1,10 @@
error: lifetime may not live long enough
--> $DIR/with_lifetime.rs:19:5
|
LL | fn foo<'a>(a: &'a ()) {
| -- lifetime `'a` defined here
LL | needs_root::<&'a ()>();
| ^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
error: aborting due to 1 previous error

View file

@ -0,0 +1,25 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
#![feature(do_not_recommend)]
trait Root {}
trait DontRecommend {}
impl<T> Root for T where T: DontRecommend {}
// this has no effect yet for resolving the trait error below
#[diagnostic::do_not_recommend]
impl<T> DontRecommend for &'static T {}
fn needs_root<T: Root>() {}
fn foo<'a>(a: &'a ()) {
needs_root::<&'a ()>();
//~^ ERROR lifetime may not live long enough
}
fn main() {
foo(&());
}