Repository navigation
don't ignore ambiguity during MIR type check #164055
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| error[E0283]: type annotations needed: cannot satisfy `dyn D<&(), &()>: B<&()>` | ||
| --> $DIR/ambiguity-due-to-uniquification-1.rs:15:31 | ||
| | | ||
| LL | (&() as &dyn D<&(), &()>).f() | ||
| | ^ | ||
| | | ||
| = note: cannot satisfy `dyn D<&(), &()>: B<&()>` | ||
| help: the trait `B<C>` is implemented for `()` | ||
| --> $DIR/ambiguity-due-to-uniquification-1.rs:9:1 | ||
| | | ||
| LL | impl<C> B<C> for () {} | ||
| | ^^^^^^^^^^^^^^^^^^^ | ||
| note: required by a bound in `D::f` | ||
| --> $DIR/ambiguity-due-to-uniquification-1.rs:10:16 | ||
| | | ||
| LL | trait D<C, E>: B<C> + B<E> { | ||
| | ^^^^ required by this bound in `D::f` | ||
| LL | fn f(&self) {} | ||
| | | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0283`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| //@ revisions: current next | ||
| //@[next] compile-flags: -Znext-solver | ||
| //@ ignore-compare-mode-next-solver (explicit revisions) | ||
| //@ check-pass | ||
| //@[current] check-pass | ||
|
|
||
| // Regression test for #139409 and trait-system-refactor-initiative#27. | ||
|
|
||
|
|
@@ -13,4 +13,5 @@ trait D<C, E>: B<C> + B<E> { | |
| impl<C, E> D<C, E> for () {} | ||
| fn main() { | ||
| (&() as &dyn D<&(), &()>).f() | ||
| //[next]~^ ERROR: type annotations needed: cannot satisfy `dyn D<&(), &()>: B<&()>` | ||
|
Comment on lines
15
to
+16
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So...this on first glance this really doesn't seem to me like it should fail. I guess from a technical perspective, I can probably see why it does (lack of OR constraints) but even that I'm unsure about, because I would expect that Given that I would expect that this test be marked as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is odd because it should also just be ambiguous during HIR typeck already. For |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| error[E0283]: type annotations needed: cannot satisfy `impl Trait<'_> + Trait<'_>: Trait<'_>` | ||
| --> $DIR/ambiguity-due-to-uniquification-2.rs:16:5 | ||
| | | ||
| LL | impls_trait::<'y, _>(foo::<'x, 'y>()); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: cannot satisfy `impl Trait<'_> + Trait<'_>: Trait<'_>` | ||
| help: the trait `Trait<'t>` is implemented for `()` | ||
| --> $DIR/ambiguity-due-to-uniquification-2.rs:9:1 | ||
| | | ||
| LL | impl<'t> Trait<'t> for () {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| note: required by a bound in `impls_trait` | ||
| --> $DIR/ambiguity-due-to-uniquification-2.rs:13:23 | ||
| | | ||
| LL | fn impls_trait<'x, T: Trait<'x>>(_: T) {} | ||
| | ^^^^^^^^^ required by this bound in `impls_trait` | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0283`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| //@ revisions: current next | ||
| //@[next] compile-flags: -Znext-solver | ||
| //@ ignore-compare-mode-next-solver (explicit revisions) | ||
| //@ check-pass | ||
| //@[current] check-pass | ||
|
|
||
| // Regression test from trait-system-refactor-initiative#27. | ||
|
|
||
|
|
@@ -14,6 +14,7 @@ fn impls_trait<'x, T: Trait<'x>>(_: T) {} | |
|
|
||
| fn bar<'x, 'y>() { | ||
| impls_trait::<'y, _>(foo::<'x, 'y>()); | ||
| //[next]~^ ERROR: type annotations needed: cannot satisfy `impl Trait<'_> + Trait<'_>: Trait<'_>` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar point to above. |
||
| } | ||
|
|
||
| fn main() {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| error[E0283]: type annotations needed: cannot satisfy `dyn Object<&(), &()>: Trait<&()>` | ||
| --> $DIR/ambiguity-due-to-uniquification-3.rs:30:5 | ||
| | | ||
| LL | impls_trait(obj, t); | ||
| | ^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: cannot satisfy `dyn Object<&(), &()>: Trait<&()>` | ||
| help: the trait `Trait<T>` is implemented for `()` | ||
| --> $DIR/ambiguity-due-to-uniquification-3.rs:17:1 | ||
| | | ||
| LL | impl<T> Trait<T> for () {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| note: required by a bound in `impls_trait` | ||
| --> $DIR/ambiguity-due-to-uniquification-3.rs:26:19 | ||
| | | ||
| LL | fn impls_trait<T: Trait<U>, U>(_: Inv<T>, _: Inv<U>) {} | ||
| | ^^^^^^^^ required by this bound in `impls_trait` | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0283`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| error[E0283]: type annotations needed: cannot satisfy `dyn D<&(), &()>: B<&()>` | ||
| --> $DIR/ambiguity-due-to-uniquification-old-solver.rs:15:31 | ||
| | | ||
| LL | (&() as &dyn D<&(), &()>).f() | ||
| | ^ | ||
| | | ||
| = note: cannot satisfy `dyn D<&(), &()>: B<&()>` | ||
| help: the trait `B<C>` is implemented for `()` | ||
| --> $DIR/ambiguity-due-to-uniquification-old-solver.rs:9:1 | ||
| | | ||
| LL | impl<C> B<C> for () {} | ||
| | ^^^^^^^^^^^^^^^^^^^ | ||
| note: required by a bound in `D::f` | ||
| --> $DIR/ambiguity-due-to-uniquification-old-solver.rs:10:16 | ||
| | | ||
| LL | trait D<C, E>: B<C> + B<E> { | ||
| | ^^^^ required by this bound in `D::f` | ||
| LL | fn f(&self) {} | ||
| | | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0283`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| //@ revisions: current next | ||
| //@[next] compile-flags: -Znext-solver | ||
| //@ ignore-compare-mode-next-solver (explicit revisions) | ||
| //@[current] check-pass | ||
|
|
||
| // Regression test for #139409 and trait-system-refactor-initiative#27. | ||
|
|
||
| trait B<C> {} | ||
| impl<C> B<C> for () {} | ||
| trait D<C, E>: B<C> + B<E> { | ||
| fn f(&self) {} | ||
| } | ||
| impl<C, E> D<C, E> for () {} | ||
| fn main() { | ||
| (&() as &dyn D<&(), &()>).f() | ||
| //[next]~^ ERROR: type annotations needed: cannot satisfy `dyn D<&(), &()>: B<&()>` | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| error[E0283]: type annotations needed: cannot satisfy `dyn Tr<'a, 'a, (), ()>: Sup<'a, ()>` | ||
| --> $DIR/ambiguity-due-to-uniquification-unsound-old.rs:37:7 | ||
| | | ||
| LL | x.hide_me() | ||
| | ^^^^^^^ | ||
| | | ||
| = note: cannot satisfy `dyn Tr<'a, 'a, (), ()>: Sup<'a, ()>` | ||
| help: the trait `Sup<'a, ()>` is implemented for `&'a str` | ||
| --> $DIR/ambiguity-due-to-uniquification-unsound-old.rs:15:1 | ||
| | | ||
| LL | impl<'a> Sup<'a, ()> for &'a str { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| note: required for `dyn Tr<'a, 'a, (), ()>` to implement `HideMe` | ||
| --> $DIR/ambiguity-due-to-uniquification-unsound-old.rs:31:57 | ||
| | | ||
| LL | impl<'a, T: Sup<'a, (), Assoc = &'static str> + ?Sized> HideMe for T { | ||
| | --------------------------------- ^^^^^^ ^ | ||
| | | | ||
| | unsatisfied trait bound introduced here | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0283`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // A regression test for trait-system-refactor-initiative#307 affecting | ||
| // the old solver instead. The old solver only cares about region identity | ||
| // inside of `project` when merging candidates. This means this unsoundness | ||
| // also affects the old solver. | ||
|
|
||
| //@ revisions: current next | ||
| //@[next] compile-flags: -Znext-solver | ||
| //@ ignore-compare-mode-next-solver (explicit revisions) | ||
| //@[current] build-pass | ||
| //@[current] known-bug: unknown | ||
| trait Sup<'a, T> { | ||
| type Assoc; | ||
| fn to_assoc(&self) -> Self::Assoc; | ||
| } | ||
| impl<'a> Sup<'a, ()> for &'a str { | ||
| type Assoc = &'a str; | ||
| fn to_assoc(&self) -> Self::Assoc { self } | ||
| } | ||
|
|
||
| // Need the trait arguments to pass WF-checking | ||
| trait Tr<'a, 'b, T, U>: Sup<'a, T, Assoc = &'a str> + Sup<'b, U, Assoc = &'b str> {} | ||
| impl<'a> Tr<'a, 'a, (), ()> for &'a str {} | ||
|
|
||
| trait HideMe { | ||
| fn hide_me(&self) -> &'static str; | ||
| } | ||
|
|
||
| // Need the ambiguous `T: Sup<'a, (), Assoc = &'static str>` bound to only be | ||
| // used inside of the trait impl, as otherwise we also encounter ambiguity | ||
| // during normalization, which ICEs instead of ignoring it. | ||
| impl<'a, T: Sup<'a, (), Assoc = &'static str> + ?Sized> HideMe for T { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, this one clearly should not pass. |
||
| fn hide_me(&self) -> &'static str { | ||
| self.to_assoc() | ||
| } | ||
| } | ||
| fn yeet<'a>(x: &dyn Tr<'a, 'a, (), ()>) -> &'static str { | ||
| x.hide_me() | ||
| //[next]~^ ERROR: type annotations needed: cannot satisfy `dyn Tr<'a, 'a, (), ()>: Sup<'a, ()>` | ||
| } | ||
|
|
||
| fn main() { | ||
| let s = String::from("hello"); | ||
| let r = yeet(&s.as_str()); | ||
| drop(s); | ||
| println!("{r}"); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Breaking MIRI does not bode well for the fallout here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proving
dyn Trait<&'x (), &'y ()>: Supertrait<&'z ()>is ambiguous as it either requires'z = 'xor'z = 'y. The reason this previously compiled with-Znext-solveris that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your last sentence cut off I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proving
dyn Trait<&'x (), &'y ()>: Supertrait<&'z ()>is ambiguous as it either requires'z = 'xor'z = 'y. The reason this previously compiled with-Znext-solveris that during HIR typeck succeeds as it hasTrait<&'static (), &'static ()>while MIR borrowck proves it forTrait<&'x (), &'y ()>and the resulting ambiguity got ignored.The explanation here is in #164055 (comment)