Rollup merge of #103355 - compiler-errors:rpitit-default-check, r=oli-obk
Handle return-position `impl Trait` in traits properly in `register_hidden_type` The bounds that we get by calling `bound_explicit_item_bounds` from an RPITIT have projections, not opaques, but when we're *registering* an opaque, we want to treat it like an opaque. Coincidentally fixes #102688 as well, which makes sense, since that was failing because we were inferring an opaque type to be equal to itself (opaque cycle error => "cannot resolve opaque type"). Fixes #103352 r? ```@oli-obk```
This commit is contained in:
commit
ff689a1404
7 changed files with 63 additions and 14 deletions
13
src/test/ui/impl-trait/in-trait/default-body-type-err-2.rs
Normal file
13
src/test/ui/impl-trait/in-trait/default-body-type-err-2.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// edition:2021
|
||||
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(async_fn_in_trait)]
|
||||
|
||||
pub trait Foo {
|
||||
async fn woopsie_async(&self) -> String {
|
||||
42
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/default-body-type-err-2.rs:8:9
|
||||
|
|
||||
LL | 42
|
||||
| ^^- help: try using a conversion method: `.to_string()`
|
||||
| |
|
||||
| expected struct `String`, found integer
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
13
src/test/ui/impl-trait/in-trait/default-body-type-err.rs
Normal file
13
src/test/ui/impl-trait/in-trait/default-body-type-err.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#![allow(incomplete_features)]
|
||||
#![feature(return_position_impl_trait_in_trait)]
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
pub trait Foo {
|
||||
fn lol(&self) -> impl Deref<Target = String> {
|
||||
//~^ type mismatch resolving `<&i32 as Deref>::Target == String`
|
||||
&1i32
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
12
src/test/ui/impl-trait/in-trait/default-body-type-err.stderr
Normal file
12
src/test/ui/impl-trait/in-trait/default-body-type-err.stderr
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
error[E0271]: type mismatch resolving `<&i32 as Deref>::Target == String`
|
||||
--> $DIR/default-body-type-err.rs:7:22
|
||||
|
|
||||
LL | fn lol(&self) -> impl Deref<Target = String> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `String`
|
||||
LL |
|
||||
LL | &1i32
|
||||
| ----- return type was inferred to be `&i32` here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// known-bug: #102688
|
||||
// check-pass
|
||||
// edition:2021
|
||||
|
||||
#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)]
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
error[E0720]: cannot resolve opaque type
|
||||
--> $DIR/default-body-with-rpit.rs:10:28
|
||||
|
|
||||
LL | async fn baz(&self) -> impl Debug {
|
||||
| ^^^^^^^^^^ cannot resolve opaque type
|
||||
|
|
||||
= note: these returned values have a concrete "never" type
|
||||
= help: this error will resolve once the item's body returns a concrete type
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0720`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue