Prevent caching projections in the case of cycles
When normalizing a projection which results in a cycle, we would cache the result of `project_type` without the nested obligations (because they're not needed for inference). This would result in the nested obligations only being handled once in fulfill, which would avoid the cycle error. Fixes #79714, a regresion from #79305 caused by the removal of `get_paranoid_cache_value_obligation`.
This commit is contained in:
parent
77fce67733
commit
2e92b13a60
11 changed files with 150 additions and 21 deletions
|
|
@ -24,13 +24,13 @@ impl Tr for u32 {
|
|||
// ...but not in an impl that redefines one of the types.
|
||||
impl Tr for bool {
|
||||
type A = Box<Self::B>;
|
||||
//~^ ERROR type mismatch resolving `<bool as Tr>::B == _`
|
||||
//~^ ERROR overflow evaluating the requirement `<bool as Tr>::B == _`
|
||||
}
|
||||
// (the error is shown twice for some reason)
|
||||
|
||||
impl Tr for usize {
|
||||
type B = &'static Self::A;
|
||||
//~^ ERROR type mismatch resolving `<usize as Tr>::A == _`
|
||||
//~^ ERROR overflow evaluating the requirement `<usize as Tr>::A == _`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
error[E0271]: type mismatch resolving `<bool as Tr>::B == _`
|
||||
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B == _`
|
||||
--> $DIR/defaults-cyclic-fail-1.rs:26:5
|
||||
|
|
||||
LL | type A = Box<Self::B>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0271]: type mismatch resolving `<usize as Tr>::A == _`
|
||||
error[E0275]: overflow evaluating the requirement `<usize as Tr>::A == _`
|
||||
--> $DIR/defaults-cyclic-fail-1.rs:32:5
|
||||
|
|
||||
LL | type B = &'static Self::A;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
For more information about this error, try `rustc --explain E0275`.
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ impl Tr for u32 {
|
|||
|
||||
impl Tr for bool {
|
||||
type A = Box<Self::B>;
|
||||
//~^ ERROR type mismatch resolving `<bool as Tr>::B == _`
|
||||
//~^ ERROR overflow evaluating the requirement `<bool as Tr>::B == _`
|
||||
}
|
||||
// (the error is shown twice for some reason)
|
||||
|
||||
impl Tr for usize {
|
||||
type B = &'static Self::A;
|
||||
//~^ ERROR type mismatch resolving `<usize as Tr>::A == _`
|
||||
//~^ ERROR overflow evaluating the requirement `<usize as Tr>::A == _`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
error[E0271]: type mismatch resolving `<bool as Tr>::B == _`
|
||||
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B == _`
|
||||
--> $DIR/defaults-cyclic-fail-2.rs:27:5
|
||||
|
|
||||
LL | type A = Box<Self::B>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0271]: type mismatch resolving `<usize as Tr>::A == _`
|
||||
error[E0275]: overflow evaluating the requirement `<usize as Tr>::A == _`
|
||||
--> $DIR/defaults-cyclic-fail-2.rs:33:5
|
||||
|
|
||||
LL | type B = &'static Self::A;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
For more information about this error, try `rustc --explain E0275`.
|
||||
|
|
|
|||
29
src/test/ui/associated-types/impl-wf-cycle-1.rs
Normal file
29
src/test/ui/associated-types/impl-wf-cycle-1.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// Regression test for #79714
|
||||
|
||||
trait Baz {}
|
||||
impl Baz for () {}
|
||||
impl<T> Baz for (T,) {}
|
||||
|
||||
trait Fiz {}
|
||||
impl Fiz for bool {}
|
||||
|
||||
trait Grault {
|
||||
type A;
|
||||
type B;
|
||||
}
|
||||
|
||||
impl<T: Grault> Grault for (T,)
|
||||
where
|
||||
Self::A: Baz,
|
||||
Self::B: Fiz,
|
||||
{
|
||||
type A = ();
|
||||
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
type B = bool;
|
||||
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
}
|
||||
//~^^^^^^^^^^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
|
||||
fn main() {
|
||||
let x: <(_,) as Grault>::A = ();
|
||||
}
|
||||
39
src/test/ui/associated-types/impl-wf-cycle-1.stderr
Normal file
39
src/test/ui/associated-types/impl-wf-cycle-1.stderr
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
--> $DIR/impl-wf-cycle-1.rs:15:1
|
||||
|
|
||||
LL | / impl<T: Grault> Grault for (T,)
|
||||
LL | | where
|
||||
LL | | Self::A: Baz,
|
||||
LL | | Self::B: Fiz,
|
||||
... |
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
= note: 1 redundant requirements hidden
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
--> $DIR/impl-wf-cycle-1.rs:20:5
|
||||
|
|
||||
LL | type A = ();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
= note: 1 redundant requirements hidden
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
--> $DIR/impl-wf-cycle-1.rs:22:5
|
||||
|
|
||||
LL | type B = bool;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
= note: 1 redundant requirements hidden
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0275`.
|
||||
16
src/test/ui/associated-types/impl-wf-cycle-2.rs
Normal file
16
src/test/ui/associated-types/impl-wf-cycle-2.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Regression test for #79714
|
||||
|
||||
trait Grault {
|
||||
type A;
|
||||
}
|
||||
|
||||
impl<T: Grault> Grault for (T,)
|
||||
where
|
||||
Self::A: Copy,
|
||||
{
|
||||
type A = ();
|
||||
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
}
|
||||
//~^^^^^^^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
|
||||
fn main() {}
|
||||
25
src/test/ui/associated-types/impl-wf-cycle-2.stderr
Normal file
25
src/test/ui/associated-types/impl-wf-cycle-2.stderr
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
--> $DIR/impl-wf-cycle-2.rs:7:1
|
||||
|
|
||||
LL | / impl<T: Grault> Grault for (T,)
|
||||
LL | | where
|
||||
LL | | Self::A: Copy,
|
||||
LL | | {
|
||||
LL | | type A = ();
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
--> $DIR/impl-wf-cycle-2.rs:11:5
|
||||
|
|
||||
LL | type A = ();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0275`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue