Skip to content

Commit ff689a1

Browse files
authored
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```
2 parents b656f5e + 419fde7 commit ff689a1

7 files changed

+63
-14
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::errors::OpaqueHiddenTypeDiag;
22
use crate::infer::{DefiningAnchor, InferCtxt, InferOk};
33
use crate::traits;
4+
use hir::def::DefKind;
45
use hir::def_id::{DefId, LocalDefId};
56
use hir::{HirId, OpaqueTyOrigin};
67
use rustc_data_structures::sync::Lrc;
@@ -549,7 +550,12 @@ impl<'tcx> InferCtxt<'tcx> {
549550
ty_op: |ty| match *ty.kind() {
550551
// We can't normalize associated types from `rustc_infer`,
551552
// but we can eagerly register inference variables for them.
552-
ty::Projection(projection_ty) if !projection_ty.has_escaping_bound_vars() => {
553+
// FIXME(RPITIT): Don't replace RPITITs with inference vars.
554+
ty::Projection(projection_ty)
555+
if !projection_ty.has_escaping_bound_vars()
556+
&& tcx.def_kind(projection_ty.item_def_id)
557+
!= DefKind::ImplTraitPlaceholder =>
558+
{
553559
self.infer_projection(
554560
param_env,
555561
projection_ty,
@@ -565,6 +571,12 @@ impl<'tcx> InferCtxt<'tcx> {
565571
{
566572
hidden_ty
567573
}
574+
// FIXME(RPITIT): This can go away when we move to associated types
575+
ty::Projection(proj)
576+
if def_id.to_def_id() == proj.item_def_id && substs == proj.substs =>
577+
{
578+
hidden_ty
579+
}
568580
_ => ty,
569581
},
570582
lt_op: |lt| lt,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// edition:2021
2+
3+
#![allow(incomplete_features)]
4+
#![feature(async_fn_in_trait)]
5+
6+
pub trait Foo {
7+
async fn woopsie_async(&self) -> String {
8+
42
9+
//~^ ERROR mismatched types
10+
}
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/default-body-type-err-2.rs:8:9
3+
|
4+
LL | 42
5+
| ^^- help: try using a conversion method: `.to_string()`
6+
| |
7+
| expected struct `String`, found integer
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![allow(incomplete_features)]
2+
#![feature(return_position_impl_trait_in_trait)]
3+
4+
use std::ops::Deref;
5+
6+
pub trait Foo {
7+
fn lol(&self) -> impl Deref<Target = String> {
8+
//~^ type mismatch resolving `<&i32 as Deref>::Target == String`
9+
&1i32
10+
}
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0271]: type mismatch resolving `<&i32 as Deref>::Target == String`
2+
--> $DIR/default-body-type-err.rs:7:22
3+
|
4+
LL | fn lol(&self) -> impl Deref<Target = String> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `String`
6+
LL |
7+
LL | &1i32
8+
| ----- return type was inferred to be `&i32` here
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0271`.

src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// known-bug: #102688
1+
// check-pass
22
// edition:2021
33

44
#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)]

src/test/ui/impl-trait/in-trait/default-body-with-rpit.stderr

-12
This file was deleted.

0 commit comments

Comments
 (0)