forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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>
Method resolution constrains hidden types instead of rejecting method candidates Some of these are in probes and may affect inference. 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`
- Loading branch information
Showing
16 changed files
with
194 additions
and
57 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 |
---|---|---|
@@ -1,19 +1,16 @@ | ||
error: opaque type's hidden type cannot be another opaque type from the same scope | ||
--> $DIR/issue-70877.rs:31:12 | ||
error[E0282]: type annotations needed | ||
--> $DIR/issue-70877.rs:30:9 | ||
| | ||
LL | let func = bar.next().unwrap(); | ||
| ^^^^ | ||
LL | return func(&"oof"); | ||
| ^^^^^^^^^^^^ one of the two opaque types used here has to be outside its defining scope | ||
| ------------ type must be known at this point | ||
| | ||
note: opaque type whose hidden type is being assigned | ||
--> $DIR/issue-70877.rs:28:19 | ||
help: consider giving `func` an explicit type | ||
| | ||
LL | fn oof(_: Foo) -> impl std::fmt::Debug { | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
note: opaque type being used as hidden type | ||
--> $DIR/issue-70877.rs:4:15 | ||
| | ||
LL | type FooRet = impl std::fmt::Debug; | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
LL | let func: /* Type */ = bar.next().unwrap(); | ||
| ++++++++++++ | ||
|
||
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,21 @@ | ||
//@ check-pass | ||
|
||
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(); | ||
} | ||
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
#![feature(type_alias_impl_trait)] | ||
|
||
type Foo = impl Sized; | ||
|
||
struct Bar<T>(T); | ||
|
||
impl Bar<Foo> { | ||
fn bar(self) {} | ||
} | ||
|
||
impl Bar<u32> { | ||
fn foo(self) { | ||
self.bar() | ||
//~^ ERROR: no method named `bar` | ||
} | ||
} | ||
|
||
fn foo() -> Foo { | ||
42_u32 | ||
} | ||
|
||
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,15 @@ | ||
error[E0599]: no method named `bar` found for struct `Bar<u32>` in the current scope | ||
--> $DIR/method_resolution.rs:13:14 | ||
| | ||
LL | struct Bar<T>(T); | ||
| ------------- method `bar` not found for this struct | ||
... | ||
LL | self.bar() | ||
| ^^^ method not found in `Bar<u32>` | ||
| | ||
= note: the method was found for | ||
- `Bar<Foo>` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
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 @@ | ||
#![feature(type_alias_impl_trait)] | ||
//@ check-pass | ||
|
||
type Foo = impl Sized; | ||
|
||
struct Bar<T>(T); | ||
|
||
impl Bar<Foo> { | ||
fn bar(self) { | ||
self.foo() | ||
} | ||
} | ||
|
||
impl Bar<u32> { | ||
fn foo(self) {} | ||
} | ||
|
||
fn foo() -> Foo { | ||
42_u32 | ||
} | ||
|
||
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,27 @@ | ||
#![feature(type_alias_impl_trait, arbitrary_self_types)] | ||
|
||
type Foo = impl Copy; | ||
|
||
#[derive(Copy, Clone)] | ||
struct Bar<T>(T); | ||
|
||
impl Bar<Foo> { | ||
fn bar(self: Bar<u32>) { | ||
//~^ ERROR: invalid `self` parameter | ||
self.foo() | ||
} | ||
fn baz(self: &Bar<u32>) { | ||
//~^ ERROR: invalid `self` parameter | ||
self.foo() | ||
} | ||
} | ||
|
||
impl Bar<u32> { | ||
fn foo(self) {} | ||
} | ||
|
||
fn foo() -> Foo { | ||
42_u32 | ||
} | ||
|
||
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,21 @@ | ||
error[E0307]: invalid `self` parameter type: Bar<u32> | ||
--> $DIR/method_resolution3.rs:9:18 | ||
| | ||
LL | fn bar(self: Bar<u32>) { | ||
| ^^^^^^^^ | ||
| | ||
= note: type of `self` must be `Self` or a type that dereferences to it | ||
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) | ||
|
||
error[E0307]: invalid `self` parameter type: &Bar<u32> | ||
--> $DIR/method_resolution3.rs:13:18 | ||
| | ||
LL | fn baz(self: &Bar<u32>) { | ||
| ^^^^^^^^^ | ||
| | ||
= note: type of `self` must be `Self` or a type that dereferences to it | ||
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0307`. |
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 @@ | ||
#![feature(type_alias_impl_trait, arbitrary_self_types)] | ||
|
||
type Foo = impl Copy; | ||
|
||
#[derive(Copy, Clone)] | ||
struct Bar<T>(T); | ||
|
||
impl Bar<Foo> { | ||
fn bar(self) {} | ||
} | ||
|
||
impl Bar<u32> { | ||
fn foo(self: Bar<Foo>) { | ||
//~^ ERROR: invalid `self` parameter | ||
self.bar() | ||
} | ||
fn foomp(self: &Bar<Foo>) { | ||
//~^ ERROR: invalid `self` parameter | ||
self.bar() | ||
} | ||
} | ||
|
||
fn foo() -> Foo { | ||
42_u32 | ||
} | ||
|
||
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,21 @@ | ||
error[E0307]: invalid `self` parameter type: Bar<Foo> | ||
--> $DIR/method_resolution4.rs:13:18 | ||
| | ||
LL | fn foo(self: Bar<Foo>) { | ||
| ^^^^^^^^ | ||
| | ||
= note: type of `self` must be `Self` or a type that dereferences to it | ||
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) | ||
|
||
error[E0307]: invalid `self` parameter type: &Bar<Foo> | ||
--> $DIR/method_resolution4.rs:17:20 | ||
| | ||
LL | fn foomp(self: &Bar<Foo>) { | ||
| ^^^^^^^^^ | ||
| | ||
= note: type of `self` must be `Self` or a type that dereferences to it | ||
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0307`. |