forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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 rust-lang#123962 - oli-obk:define_opaque_types5, r=<try>
change method resolution to constrain hidden types instead of rejecting method candidates Some of these are in probes and may affect inference. This is therefore a breaking change. This allows new code to compile on stable: ```rust trait Trait {} impl Trait for u32 {} struct Bar<T>(T); impl Bar<u32> { fn foo(self) {} } fn foo(x: bool) -> Bar<impl Sized> { if x { let x = foo(false); x.foo(); //^ this used to not find the `foo` method, because while we did equate `x`'s type with possible candidates, we didn't allow opaque type inference while doing so } todo!() } ``` But it is also a breaking change, since `&self` and `&mut self` method calls on recursive RPIT function calls now constrain the hidden type to `&_` and `&mut _` respectively. This is not what users really expect or want from this, but there's way around this. r? `@compiler-errors` fixes rust-lang#121404 cc rust-lang#116652
- Loading branch information
Showing
31 changed files
with
569 additions
and
63 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
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
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
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
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
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
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
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
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,26 @@ | ||
//! Since there is only one possible `bar` method, we invoke it and subsequently | ||
//! constrain `foo`'s RPIT to `u32`. | ||
|
||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
//@ check-pass | ||
|
||
trait Trait {} | ||
|
||
impl Trait for u32 {} | ||
|
||
struct Bar<T>(T); | ||
|
||
impl Bar<u32> { | ||
fn bar(self) {} | ||
} | ||
|
||
fn foo(x: bool) -> Bar<impl Sized> { | ||
if x { | ||
let x = foo(false); | ||
x.bar(); | ||
} | ||
todo!() | ||
} | ||
|
||
fn main() {} |
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,20 @@ | ||
error[E0034]: multiple applicable items in scope | ||
--> $DIR/method-resolution2.rs:25:11 | ||
| | ||
LL | x.bar(); | ||
| ^^^ multiple `bar` found | ||
| | ||
note: candidate #1 is defined in an impl for the type `Bar<T>` | ||
--> $DIR/method-resolution2.rs:19:5 | ||
| | ||
LL | fn bar(self) {} | ||
| ^^^^^^^^^^^^ | ||
note: candidate #2 is defined in an impl for the type `Bar<u32>` | ||
--> $DIR/method-resolution2.rs:15:5 | ||
| | ||
LL | fn bar(self) {} | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0034`. |
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,31 @@ | ||
//! Check that the method call does not constrain the RPIT to `i32`, even though | ||
//! `i32` is the only type that satisfies the RPIT's trait bounds. | ||
|
||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
//@[current] check-pass | ||
|
||
trait Trait {} | ||
|
||
impl Trait for i32 {} | ||
|
||
struct Bar<T>(T); | ||
|
||
impl Bar<u32> { | ||
fn bar(self) {} | ||
} | ||
|
||
impl<T: Trait> Bar<T> { | ||
fn bar(self) {} | ||
} | ||
|
||
fn foo(x: bool) -> Bar<impl Trait> { | ||
if x { | ||
let x = foo(false); | ||
x.bar(); | ||
//[next]~^ ERROR: multiple applicable items in scope | ||
} | ||
Bar(42_i32) | ||
} | ||
|
||
fn main() {} |
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,20 @@ | ||
error[E0034]: multiple applicable items in scope | ||
--> $DIR/method-resolution3.rs:21:11 | ||
| | ||
LL | x.bar(); | ||
| ^^^ multiple `bar` found | ||
| | ||
note: candidate #1 is defined in an impl for the type `Bar<i32>` | ||
--> $DIR/method-resolution3.rs:15:5 | ||
| | ||
LL | fn bar(self) {} | ||
| ^^^^^^^^^^^^ | ||
note: candidate #2 is defined in an impl for the type `Bar<u32>` | ||
--> $DIR/method-resolution3.rs:11:5 | ||
| | ||
LL | fn bar(self) {} | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0034`. |
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,20 @@ | ||
error[E0034]: multiple applicable items in scope | ||
--> $DIR/method-resolution3.rs:21:11 | ||
| | ||
LL | x.bar(); | ||
| ^^^ multiple `bar` found | ||
| | ||
note: candidate #1 is defined in an impl for the type `Bar<i32>` | ||
--> $DIR/method-resolution3.rs:15:5 | ||
| | ||
LL | fn bar(self) {} | ||
| ^^^^^^^^^^^^ | ||
note: candidate #2 is defined in an impl for the type `Bar<u32>` | ||
--> $DIR/method-resolution3.rs:11:5 | ||
| | ||
LL | fn bar(self) {} | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0034`. |
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,27 @@ | ||
//! Check that we consider `Bar<impl Sized>` to successfully unify | ||
//! with both `Bar<u32>` and `Bar<i32>` (in isolation), so we bail | ||
//! out with ambiguity. | ||
|
||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
struct Bar<T>(T); | ||
|
||
impl Bar<u32> { | ||
fn bar(self) {} | ||
} | ||
|
||
impl Bar<i32> { | ||
fn bar(self) {} | ||
} | ||
|
||
fn foo(x: bool) -> Bar<impl Sized> { | ||
if x { | ||
let x = foo(false); | ||
x.bar(); | ||
//~^ ERROR: multiple applicable items in scope | ||
} | ||
todo!() | ||
} | ||
|
||
fn main() {} |
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[E0282]: type annotations needed | ||
--> $DIR/method-resolution4.rs:13:9 | ||
| | ||
LL | foo(false).next().unwrap(); | ||
| ^^^^^^^^^^ cannot infer type | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/method-resolution4.rs:16:5 | ||
| | ||
LL | fn foo(b: bool) -> impl Iterator<Item = ()> { | ||
| ------------------------ the expected opaque type | ||
... | ||
LL | std::iter::empty() | ||
| ^^^^^^^^^^^^^^^^^^ types differ | ||
| | ||
= note: expected opaque type `impl Iterator<Item = ()>` | ||
found struct `std::iter::Empty<_>` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0282, E0308. | ||
For more information about an error, try `rustc --explain E0282`. |
Oops, something went wrong.