diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-01-14 13:04:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-14 13:04:26 +0100 |
| commit | 8c538f7d833daa83dc07e59718cfc61ba8bdda10 (patch) | |
| tree | d6775e435b877e9b4c607745ecc43ec31abf7a5f /tests | |
| parent | 108b5f462b0c1845253002c3d4b615a11a844cb8 (diff) | |
| parent | 22a0e4fa6e08acf2de50ed87cfb909092ab0459d (diff) | |
| download | rust-8c538f7d833daa83dc07e59718cfc61ba8bdda10.tar.gz rust-8c538f7d833daa83dc07e59718cfc61ba8bdda10.zip | |
Rollup merge of #106788 - estebank:elaborate_pred_E0599, r=compiler-errors
Tweak E0599 and elaborate_predicates CC https://github.com/rust-lang/rust/issues/86377.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/associated-types/issue-43784-associated-type.stderr | 5 | ||||
| -rw-r--r-- | tests/ui/derives/issue-91550.stderr | 34 | ||||
| -rw-r--r-- | tests/ui/generic-associated-types/issue-74824.stderr | 1 | ||||
| -rw-r--r-- | tests/ui/missing-trait-bounds/issue-35677.stderr | 2 | ||||
| -rw-r--r-- | tests/ui/traits/issue-43784-supertrait.stderr | 5 | ||||
| -rw-r--r-- | tests/ui/traits/track-obligations.rs | 88 | ||||
| -rw-r--r-- | tests/ui/traits/track-obligations.stderr | 76 |
7 files changed, 209 insertions, 2 deletions
diff --git a/tests/ui/associated-types/issue-43784-associated-type.stderr b/tests/ui/associated-types/issue-43784-associated-type.stderr index f1677b822b4..50fa7d1ac4d 100644 --- a/tests/ui/associated-types/issue-43784-associated-type.stderr +++ b/tests/ui/associated-types/issue-43784-associated-type.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `T: Copy` is not satisfied LL | type Assoc = T; | ^ the trait `Copy` is not implemented for `T` | +note: required for `<T as Complete>::Assoc` to implement `Partial<T>` + --> $DIR/issue-43784-associated-type.rs:1:11 + | +LL | pub trait Partial<X: ?Sized>: Copy { + | ^^^^^^^ note: required by a bound in `Complete::Assoc` --> $DIR/issue-43784-associated-type.rs:5:17 | diff --git a/tests/ui/derives/issue-91550.stderr b/tests/ui/derives/issue-91550.stderr index bf0bb3fbdf8..af03f0e5e5f 100644 --- a/tests/ui/derives/issue-91550.stderr +++ b/tests/ui/derives/issue-91550.stderr @@ -6,12 +6,15 @@ LL | struct Value(u32); | | | doesn't satisfy `Value: Eq` | doesn't satisfy `Value: Hash` + | doesn't satisfy `Value: PartialEq` ... LL | hs.insert(Value(0)); | ^^^^^^ | = note: the following trait bounds were not satisfied: `Value: Eq` + `Value: PartialEq` + which is required by `Value: Eq` `Value: Hash` help: consider annotating `Value` with `#[derive(Eq, Hash, PartialEq)]` | @@ -22,7 +25,10 @@ error[E0599]: the method `use_eq` exists for struct `Object<NoDerives>`, but its --> $DIR/issue-91550.rs:26:9 | LL | pub struct NoDerives; - | -------------------- doesn't satisfy `NoDerives: Eq` + | -------------------- + | | + | doesn't satisfy `NoDerives: Eq` + | doesn't satisfy `NoDerives: PartialEq` LL | LL | struct Object<T>(T); | ---------------- method `use_eq` not found for this struct @@ -37,6 +43,9 @@ LL | impl<T: Eq> Object<T> { | ^^ --------- | | | unsatisfied trait bound introduced here + = note: the following trait bounds were not satisfied: + `NoDerives: PartialEq` + which is required by `NoDerives: Eq` help: consider annotating `NoDerives` with `#[derive(Eq, PartialEq)]` | LL | #[derive(Eq, PartialEq)] @@ -46,7 +55,12 @@ error[E0599]: the method `use_ord` exists for struct `Object<NoDerives>`, but it --> $DIR/issue-91550.rs:27:9 | LL | pub struct NoDerives; - | -------------------- doesn't satisfy `NoDerives: Ord` + | -------------------- + | | + | doesn't satisfy `NoDerives: Eq` + | doesn't satisfy `NoDerives: Ord` + | doesn't satisfy `NoDerives: PartialEq` + | doesn't satisfy `NoDerives: PartialOrd` LL | LL | struct Object<T>(T); | ---------------- method `use_ord` not found for this struct @@ -61,6 +75,13 @@ LL | impl<T: Ord> Object<T> { | ^^^ --------- | | | unsatisfied trait bound introduced here + = note: the following trait bounds were not satisfied: + `NoDerives: PartialOrd` + which is required by `NoDerives: Ord` + `NoDerives: PartialEq` + which is required by `NoDerives: Ord` + `NoDerives: Eq` + which is required by `NoDerives: Ord` help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]` | LL | #[derive(Eq, Ord, PartialEq, PartialOrd)] @@ -72,7 +93,9 @@ error[E0599]: the method `use_ord_and_partial_ord` exists for struct `Object<NoD LL | pub struct NoDerives; | -------------------- | | + | doesn't satisfy `NoDerives: Eq` | doesn't satisfy `NoDerives: Ord` + | doesn't satisfy `NoDerives: PartialEq` | doesn't satisfy `NoDerives: PartialOrd` LL | LL | struct Object<T>(T); @@ -91,6 +114,13 @@ LL | impl<T: Ord + PartialOrd> Object<T> { | | | | | unsatisfied trait bound introduced here | unsatisfied trait bound introduced here + = note: the following trait bounds were not satisfied: + `NoDerives: PartialEq` + which is required by `NoDerives: Ord` + `NoDerives: Eq` + which is required by `NoDerives: Ord` + `NoDerives: PartialEq` + which is required by `NoDerives: PartialOrd` help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]` | LL | #[derive(Eq, Ord, PartialEq, PartialOrd)] diff --git a/tests/ui/generic-associated-types/issue-74824.stderr b/tests/ui/generic-associated-types/issue-74824.stderr index 623adb1c2ad..e5638d90ee8 100644 --- a/tests/ui/generic-associated-types/issue-74824.stderr +++ b/tests/ui/generic-associated-types/issue-74824.stderr @@ -17,6 +17,7 @@ LL | type Copy<T>: Copy = Box<T>; | ^^^^^^ the trait `Clone` is not implemented for `T` | = note: required for `Box<T>` to implement `Clone` + = note: required for `<Self as UnsafeCopy>::Copy<T>` to implement `Copy` note: required by a bound in `UnsafeCopy::Copy` --> $DIR/issue-74824.rs:6:19 | diff --git a/tests/ui/missing-trait-bounds/issue-35677.stderr b/tests/ui/missing-trait-bounds/issue-35677.stderr index a2201b946a6..05d3de80d84 100644 --- a/tests/ui/missing-trait-bounds/issue-35677.stderr +++ b/tests/ui/missing-trait-bounds/issue-35677.stderr @@ -6,6 +6,8 @@ LL | this.is_subset(other) | = note: the following trait bounds were not satisfied: `T: Eq` + `T: PartialEq` + which is required by `T: Eq` `T: Hash` help: consider restricting the type parameters to satisfy the trait bounds | diff --git a/tests/ui/traits/issue-43784-supertrait.stderr b/tests/ui/traits/issue-43784-supertrait.stderr index 4fe12731475..6b5b721384c 100644 --- a/tests/ui/traits/issue-43784-supertrait.stderr +++ b/tests/ui/traits/issue-43784-supertrait.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `T: Copy` is not satisfied LL | impl<T> Complete for T {} | ^ the trait `Copy` is not implemented for `T` | +note: required for `T` to implement `Partial` + --> $DIR/issue-43784-supertrait.rs:1:11 + | +LL | pub trait Partial: Copy { + | ^^^^^^^ note: required by a bound in `Complete` --> $DIR/issue-43784-supertrait.rs:4:21 | diff --git a/tests/ui/traits/track-obligations.rs b/tests/ui/traits/track-obligations.rs new file mode 100644 index 00000000000..77e753c13f7 --- /dev/null +++ b/tests/ui/traits/track-obligations.rs @@ -0,0 +1,88 @@ +// These are simplifications of the tower traits by the same name: + +pub trait Service<Request> { + type Response; +} + +pub trait Layer<C> { + type Service; +} + +// Any type will do here: + +pub struct Req; +pub struct Res; + +// This is encoding a trait alias. + +pub trait ParticularService: + Service<Req, Response = Res> { +} + +impl<T> ParticularService for T +where + T: Service<Req, Response = Res>, +{ +} + +// This is also a trait alias. +// The weird = <Self as ...> bound is there so that users of the trait do not +// need to repeat the bounds. See https://github.com/rust-lang/rust/issues/20671 +// for context, and in particular the workaround in: +// https://github.com/rust-lang/rust/issues/20671#issuecomment-529752828 + +pub trait ParticularServiceLayer<C>: + Layer<C, Service = <Self as ParticularServiceLayer<C>>::Service> +{ + type Service: ParticularService; +} + +impl<T, C> ParticularServiceLayer<C> for T +where + T: Layer<C>, + T::Service: ParticularService, +{ + type Service = T::Service; +} + +// These are types that implement the traits that the trait aliases refer to. +// They should also implement the alias traits due to the blanket impls. + +struct ALayer<C>(C); +impl<C> Layer<C> for ALayer<C> { + type Service = AService; +} + +struct AService; +impl Service<Req> for AService { + // However, AService does _not_ meet the blanket implementation, + // since its Response type is bool, not Res as it should be. + type Response = bool; +} + +// This is a wrapper type around ALayer that uses the trait alias +// as a way to communicate the requirements of the provided types. +struct Client<C>(C); + +// The method and the free-standing function below both have the same bounds. + +impl<C> Client<C> +where + ALayer<C>: ParticularServiceLayer<C>, +{ + fn check(&self) {} +} + +fn check<C>(_: C) where ALayer<C>: ParticularServiceLayer<C> {} + +// But, they give very different error messages. + +fn main() { + // This gives a very poor error message that does nothing to point the user + // at the underlying cause of why the types involved do not meet the bounds. + Client(()).check(); //~ ERROR E0599 + + // This gives a good(ish) error message that points the user at _why_ the + // bound isn't met, and thus how they might fix it. + check(()); //~ ERROR E0271 +} diff --git a/tests/ui/traits/track-obligations.stderr b/tests/ui/traits/track-obligations.stderr new file mode 100644 index 00000000000..89477475970 --- /dev/null +++ b/tests/ui/traits/track-obligations.stderr @@ -0,0 +1,76 @@ +error[E0599]: the method `check` exists for struct `Client<()>`, but its trait bounds were not satisfied + --> $DIR/track-obligations.rs:83:16 + | +LL | struct ALayer<C>(C); + | ---------------- + | | + | doesn't satisfy `<_ as Layer<()>>::Service = <ALayer<()> as ParticularServiceLayer<()>>::Service` + | doesn't satisfy `ALayer<()>: ParticularServiceLayer<()>` +... +LL | struct Client<C>(C); + | ---------------- method `check` not found for this struct +... +LL | Client(()).check(); + | ^^^^^ method cannot be called on `Client<()>` due to unsatisfied trait bounds + | +note: trait bound `<ALayer<()> as Layer<()>>::Service = <ALayer<()> as ParticularServiceLayer<()>>::Service` was not satisfied + --> $DIR/track-obligations.rs:35:14 + | +LL | pub trait ParticularServiceLayer<C>: + | ---------------------- +LL | Layer<C, Service = <Self as ParticularServiceLayer<C>>::Service> + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here +note: trait bound `ALayer<()>: ParticularServiceLayer<()>` was not satisfied + --> $DIR/track-obligations.rs:71:16 + | +LL | impl<C> Client<C> + | --------- +LL | where +LL | ALayer<C>: ParticularServiceLayer<C>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here +note: the trait `ParticularServiceLayer` must be implemented + --> $DIR/track-obligations.rs:34:1 + | +LL | / pub trait ParticularServiceLayer<C>: +LL | | Layer<C, Service = <Self as ParticularServiceLayer<C>>::Service> + | |____________________________________________________________________^ + +error[E0271]: type mismatch resolving `<AService as Service<Req>>::Response == Res` + --> $DIR/track-obligations.rs:87:11 + | +LL | check(()); + | ----- ^^ type mismatch resolving `<AService as Service<Req>>::Response == Res` + | | + | required by a bound introduced by this call + | +note: expected this to be `Res` + --> $DIR/track-obligations.rs:60:21 + | +LL | type Response = bool; + | ^^^^ +note: required for `AService` to implement `ParticularService` + --> $DIR/track-obligations.rs:22:9 + | +LL | impl<T> ParticularService for T + | ^^^^^^^^^^^^^^^^^ ^ +LL | where +LL | T: Service<Req, Response = Res>, + | -------------- unsatisfied trait bound introduced here +note: required for `ALayer<_>` to implement `ParticularServiceLayer<_>` + --> $DIR/track-obligations.rs:40:12 + | +LL | impl<T, C> ParticularServiceLayer<C> for T + | ^^^^^^^^^^^^^^^^^^^^^^^^^ ^ +... +LL | T::Service: ParticularService, + | ----------------- unsatisfied trait bound introduced here +note: required by a bound in `check` + --> $DIR/track-obligations.rs:76:36 + | +LL | fn check<C>(_: C) where ALayer<C>: ParticularServiceLayer<C> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0271, E0599. +For more information about an error, try `rustc --explain E0271`. |
