-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #125413 - lcnr:ambig-drop-region-constraints, r=compile…
…r-errors drop region constraints for ambiguous goals See the comment in `compute_external_query_constraints`. While the underlying issue is preexisting, this fixes a bug introduced by #125343. It slightly weakens the leak chec, even if we didn't have any test which was affected. I want to write such a test before merging this PR. r? `@compiler-errors`
- Loading branch information
Showing
6 changed files
with
172 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/ui/higher-ranked/leak-check/leak-check-in-selection-5-ambig.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//@ revisions: old next | ||
//@[next] compile-flags: -Znext-solver | ||
//@ check-pass | ||
|
||
// The new trait solver does not return region constraints if the goal | ||
// is still ambiguous. This causes the following test to fail with ambiguity, | ||
// even though `(): LeakCheckFailure<'!a, V>` would return `'!a: 'static` | ||
// which would have caused a leak check failure. | ||
|
||
trait Ambig {} | ||
impl Ambig for u32 {} | ||
impl Ambig for u16 {} | ||
|
||
trait Id<T> {} | ||
impl Id<u32> for u32 {} | ||
impl Id<u16> for u16 {} | ||
|
||
|
||
trait LeakCheckFailure<'a, V: ?Sized> {} | ||
impl<V: ?Sized + Ambig> LeakCheckFailure<'static, V> for () {} | ||
|
||
trait Trait<U, V> {} | ||
impl<V> Trait<u32, V> for () where for<'a> (): LeakCheckFailure<'a, V> {} | ||
impl<V> Trait<u16, V> for () {} | ||
fn impls_trait<T: Trait<U, V>, U: Id<V>, V>() {} | ||
fn main() { | ||
impls_trait::<(), _, _>() | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.next.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0283]: type annotations needed | ||
--> $DIR/leak-check-in-selection-6-ambig-unify.rs:30:5 | ||
| | ||
LL | impls_trait::<(), _, _>() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `impls_trait` | ||
| | ||
note: multiple `impl`s satisfying `(): Trait<_, _>` found | ||
--> $DIR/leak-check-in-selection-6-ambig-unify.rs:26:1 | ||
| | ||
LL | impl<V> Trait<u32, V> for () where for<'b> (): LeakCheckFailure<'static, 'b, V> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | impl<V> Trait<u16, V> for () {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
note: required by a bound in `impls_trait` | ||
--> $DIR/leak-check-in-selection-6-ambig-unify.rs:28:19 | ||
| | ||
LL | fn impls_trait<T: Trait<U, V>, U: Id<V>, V>() {} | ||
| ^^^^^^^^^^^ required by this bound in `impls_trait` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0283`. |
22 changes: 22 additions & 0 deletions
22
tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.old.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0283]: type annotations needed | ||
--> $DIR/leak-check-in-selection-6-ambig-unify.rs:30:5 | ||
| | ||
LL | impls_trait::<(), _, _>() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `impls_trait` | ||
| | ||
note: multiple `impl`s satisfying `(): Trait<_, _>` found | ||
--> $DIR/leak-check-in-selection-6-ambig-unify.rs:26:1 | ||
| | ||
LL | impl<V> Trait<u32, V> for () where for<'b> (): LeakCheckFailure<'static, 'b, V> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | impl<V> Trait<u16, V> for () {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
note: required by a bound in `impls_trait` | ||
--> $DIR/leak-check-in-selection-6-ambig-unify.rs:28:19 | ||
| | ||
LL | fn impls_trait<T: Trait<U, V>, U: Id<V>, V>() {} | ||
| ^^^^^^^^^^^ required by this bound in `impls_trait` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0283`. |
32 changes: 32 additions & 0 deletions
32
tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//@ revisions: old next | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
// The new trait solver does not return region constraints if the goal | ||
// is still ambiguous. This should cause the following test to fail with | ||
// ambiguity as even if `(): LeakCheckFailure<'static, '!b, V>` unifies | ||
// `'!b` with `'static`, we erase all region constraints. | ||
// | ||
// However, we do still unify the var_value for `'b` with `'static`, | ||
// causing us to return this requirement via the `var_values` even if | ||
// we don't return any region constraints. This is a bit inconsistent | ||
// but isn't something we should really worry about imo. | ||
trait Ambig {} | ||
impl Ambig for u32 {} | ||
impl Ambig for u16 {} | ||
|
||
trait Id<T> {} | ||
impl Id<u32> for u32 {} | ||
impl Id<u16> for u16 {} | ||
|
||
|
||
trait LeakCheckFailure<'a, 'b, V: ?Sized> {} | ||
impl<'a, 'b: 'a, V: ?Sized + Ambig> LeakCheckFailure<'a, 'b, V> for () {} | ||
|
||
trait Trait<U, V> {} | ||
impl<V> Trait<u32, V> for () where for<'b> (): LeakCheckFailure<'static, 'b, V> {} | ||
impl<V> Trait<u16, V> for () {} | ||
fn impls_trait<T: Trait<U, V>, U: Id<V>, V>() {} | ||
fn main() { | ||
impls_trait::<(), _, _>() | ||
//~^ ERROR type annotations needed | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/ui/traits/next-solver/normalize/ambig-goal-infer-in-type-oulives.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//@ check-pass | ||
//@ compile-flags: -Znext-solver | ||
//@ ignore-compare-mode-next-solver (explicitly enabled) | ||
|
||
// Regression test for an ICE when trying to bootstrap rustc | ||
// with #125343. An ambiguous goal returned a `TypeOutlives` | ||
// constraint referencing an inference variable. This inference | ||
// variable was created inside of the goal, causing it to be | ||
// unconstrained in the caller. This then caused an ICE in MIR | ||
// borrowck. | ||
|
||
struct Foo<T>(T); | ||
trait Extend<T> { | ||
fn extend<I: IntoIterator<Item = T>>(iter: I); | ||
} | ||
|
||
impl<T> Extend<T> for Foo<T> { | ||
fn extend<I: IntoIterator<Item = T>>(_: I) { | ||
todo!() | ||
} | ||
} | ||
|
||
impl<'a, T: 'a + Copy> Extend<&'a T> for Foo<T> { | ||
fn extend<I: IntoIterator<Item = &'a T>>(iter: I) { | ||
<Self as Extend<T>>::extend(iter.into_iter().copied()) | ||
} | ||
} | ||
|
||
fn main() {} |