Skip to content

[Experiment] Check that corresponding trait goal holds when projection is rigid #139763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,12 @@ pub(super) fn opt_normalize_projection_term<'a, 'b, 'tcx>(
let result =
Normalized { value: projected_ty, obligations: PredicateObligations::new() };
infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
// No need to extend `obligations`.
obligations.push(Obligation::new(
infcx.tcx,
cause,
param_env,
projection_term.trait_ref(infcx.tcx),
));
Ok(Some(result.value))
}
Err(ProjectionError::TooManyCandidates) => {
Expand Down
160 changes: 158 additions & 2 deletions tests/ui/associated-types/hr-associated-type-bound-1.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
error: implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`

error: implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-1.rs:1:1
|
LL | / trait X<'a>
LL | | where
LL | | for<'b> <Self as X<'b>>::U: Clone,
... |
LL | | }
| |_^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-1.rs:1:1
|
LL | / trait X<'a>
LL | | where
LL | | for<'b> <Self as X<'b>>::U: Clone,
... |
LL | | }
| |_^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0277]: the trait bound `str: Clone` is not satisfied
--> $DIR/hr-associated-type-bound-1.rs:12:14
|
Expand All @@ -14,6 +52,80 @@ LL | where
LL | for<'b> <Self as X<'b>>::U: Clone,
| ^^^^^ required by this bound in `X`

error: implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0478]: lifetime bound not satisfied
--> $DIR/hr-associated-type-bound-1.rs:6:5
|
LL | fn f(&self, x: &Self::U) {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'a` as defined here
--> $DIR/hr-associated-type-bound-1.rs:1:9
|
LL | trait X<'a>
| ^^

error[E0478]: lifetime bound not satisfied
--> $DIR/hr-associated-type-bound-1.rs:6:5
|
LL | fn f(&self, x: &Self::U) {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: but lifetime parameter must outlive the lifetime `'a` as defined here
--> $DIR/hr-associated-type-bound-1.rs:1:9
|
LL | trait X<'a>
| ^^

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-1.rs:6:8
|
LL | fn f(&self, x: &Self::U) {
| ^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-1.rs:6:8
|
LL | fn f(&self, x: &Self::U) {
| ^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-1.rs:6:20
|
LL | fn f(&self, x: &Self::U) {
| ^^^^^^^^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-1.rs:6:20
|
LL | fn f(&self, x: &Self::U) {
| ^^^^^^^^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0277]: the trait bound `str: Clone` is not satisfied
--> $DIR/hr-associated-type-bound-1.rs:17:10
|
Expand All @@ -30,6 +142,50 @@ LL | for<'b> <Self as X<'b>>::U: Clone,
LL | fn f(&self, x: &Self::U) {
| - required by a bound in this associated function

error: aborting due to 2 previous errors
error: lifetime may not live long enough
--> $DIR/hr-associated-type-bound-1.rs:6:5
|
LL | trait X<'a>
| -- lifetime `'a` defined here
...
LL | fn f(&self, x: &Self::U) {
| ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`

error: higher-ranked subtype error
--> $DIR/hr-associated-type-bound-1.rs:6:5
|
LL | fn f(&self, x: &Self::U) {
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-1.rs:7:9
|
LL | <Self::U>::clone(x);
| ^^^^^^^^^^^^^^^^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'1>`, for some specific lifetime `'1`

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-1.rs:7:9
|
LL | <Self::U>::clone(x);
| ^^^^^^^^^^^^^^^^^^^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'1>`, for some specific lifetime `'1`

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-1.rs:7:9
|
LL | <Self::U>::clone(x);
| ^^^^^^^^^^^^^^^^^^^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'1>`, for some specific lifetime `'1`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 19 previous errors

For more information about this error, try `rustc --explain E0277`.
Some errors have detailed explanations: E0277, E0478.
For more information about an error, try `rustc --explain E0277`.
40 changes: 39 additions & 1 deletion tests/ui/associated-types/hr-associated-type-bound-2.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
error: implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`

error: implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-2.rs:1:1
|
LL | / trait X<'a>
LL | | where
LL | | for<'b> <Self as X<'b>>::U: Clone,
... |
LL | | }
| |_^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-2.rs:1:1
|
LL | / trait X<'a>
LL | | where
LL | | for<'b> <Self as X<'b>>::U: Clone,
... |
LL | | }
| |_^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0275]: overflow evaluating the requirement `for<'b> u32: X<'b>`
--> $DIR/hr-associated-type-bound-2.rs:11:1
|
Expand All @@ -18,6 +56,6 @@ LL | for<'b> <Self as X<'b>>::U: Clone,
= note: 128 redundant requirements hidden
= note: required for `u32` to implement `for<'b> X<'b>`

error: aborting due to 1 previous error
error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0275`.
40 changes: 39 additions & 1 deletion tests/ui/associated-types/hr-associated-type-bound-object.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
error: implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`

error: implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-object.rs:1:1
|
LL | / trait X<'a>
LL | | where
LL | | for<'b> <Self as X<'b>>::U: Clone,
... |
LL | | }
| |_^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`

error: implementation of `X` is not general enough
--> $DIR/hr-associated-type-bound-object.rs:1:1
|
LL | / trait X<'a>
LL | | where
LL | | for<'b> <Self as X<'b>>::U: Clone,
... |
LL | | }
| |_^ implementation of `X` is not general enough
|
= note: `Self` must implement `X<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `X<'a>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0277]: the trait bound `for<'b> <T as X<'b>>::U: Clone` is not satisfied
--> $DIR/hr-associated-type-bound-object.rs:7:13
|
Expand Down Expand Up @@ -85,6 +123,6 @@ help: consider further restricting the associated type
LL | fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) where for<'b> <T as X<'b>>::U: Clone {
| ++++++++++++++++++++++++++++++++++++

error: aborting due to 5 previous errors
error: aborting due to 9 previous errors

For more information about this error, try `rustc --explain E0277`.
Loading
Loading