forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#123962 - oli-obk:define_opaque_types5, r=lcnr
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!() } ``` r? ``@compiler-errors`` fixes rust-lang#121404 cc rust-lang#116652
- Loading branch information
Showing
42 changed files
with
922 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error[E0282]: type annotations needed | ||
--> $DIR/call_method_ambiguous.rs:29:13 | ||
| | ||
LL | let mut iter = foo(n - 1, m); | ||
| ^^^^^^^^ | ||
LL | | ||
LL | assert_eq!(iter.get(), 1); | ||
| ---- type must be known at this point | ||
| | ||
help: consider giving `iter` an explicit type | ||
| | ||
LL | let mut iter: /* Type */ = foo(n - 1, m); | ||
| ++++++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0282`. |
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,39 @@ | ||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
//@[current] run-pass | ||
|
||
#![feature(precise_capturing)] | ||
#![allow(incomplete_features)] | ||
|
||
trait Get { | ||
fn get(&mut self) -> u32; | ||
} | ||
|
||
impl Get for () { | ||
fn get(&mut self) -> u32 { | ||
0 | ||
} | ||
} | ||
|
||
impl<T> Get for &mut T | ||
where | ||
T: Get, | ||
{ | ||
fn get(&mut self) -> u32 { | ||
T::get(self) + 1 | ||
} | ||
} | ||
|
||
fn foo(n: usize, m: &mut ()) -> impl use<'_> Get { | ||
if n > 0 { | ||
let mut iter = foo(n - 1, m); | ||
//[next]~^ type annotations needed | ||
assert_eq!(iter.get(), 1); | ||
} | ||
m | ||
} | ||
|
||
fn main() { | ||
let g = foo(1, &mut ()).get(); | ||
assert_eq!(g, 1); | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ui/impl-trait/call_method_on_inherent_impl.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,17 @@ | ||
error[E0282]: type annotations needed | ||
--> $DIR/call_method_on_inherent_impl.rs:18:13 | ||
| | ||
LL | let x = my_foo(); | ||
| ^ | ||
LL | | ||
LL | x.my_debug(); | ||
| - type must be known at this point | ||
| | ||
help: consider giving `x` an explicit type | ||
| | ||
LL | let x: /* Type */ = my_foo(); | ||
| ++++++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0282`. |
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,25 @@ | ||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
//@[current] check-pass | ||
|
||
trait MyDebug { | ||
fn my_debug(&self); | ||
} | ||
|
||
impl<T> MyDebug for T | ||
where | ||
T: std::fmt::Debug, | ||
{ | ||
fn my_debug(&self) {} | ||
} | ||
|
||
fn my_foo() -> impl std::fmt::Debug { | ||
if false { | ||
let x = my_foo(); | ||
//[next]~^ type annotations needed | ||
x.my_debug(); | ||
} | ||
() | ||
} | ||
|
||
fn main() {} |
16 changes: 16 additions & 0 deletions
16
tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.current.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,16 @@ | ||
error[E0599]: no method named `my_debug` found for reference `&impl Debug` in the current scope | ||
--> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:16:11 | ||
| | ||
LL | x.my_debug(); | ||
| ^^^^^^^^ method not found in `&impl Debug` | ||
| | ||
= help: items from traits can only be used if the trait is implemented and in scope | ||
note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it | ||
--> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:4:1 | ||
| | ||
LL | trait MyDebug { | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
17 changes: 17 additions & 0 deletions
17
tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.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,17 @@ | ||
error[E0282]: type annotations needed for `&_` | ||
--> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:14:13 | ||
| | ||
LL | let x = &my_foo(); | ||
| ^ | ||
LL | | ||
LL | x.my_debug(); | ||
| -------- type must be known at this point | ||
| | ||
help: consider giving `x` an explicit type, where the placeholders `_` are specified | ||
| | ||
LL | let x: &_ = &my_foo(); | ||
| ++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0282`. |
22 changes: 22 additions & 0 deletions
22
tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.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,22 @@ | ||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
trait MyDebug { | ||
fn my_debug(&self); | ||
} | ||
|
||
impl MyDebug for &() { | ||
fn my_debug(&self) {} | ||
} | ||
|
||
fn my_foo() -> impl std::fmt::Debug { | ||
if false { | ||
let x = &my_foo(); | ||
//[next]~^ ERROR: type annotations needed | ||
x.my_debug(); | ||
//[current]~^ ERROR: no method named `my_debug` | ||
} | ||
() | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.