Skip to content

Commit 419fde7

Browse files
Handle RPITITs properly in register_hidden_type
1 parent 0940040 commit 419fde7

File tree

7 files changed

+63
-14
lines changed

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;
@@ -552,7 +553,12 @@ impl<'tcx> InferCtxt<'tcx> {
552553
ty_op: |ty| match *ty.kind() {
553554
// We can't normalize associated types from `rustc_infer`,
554555
// but we can eagerly register inference variables for them.
555-
ty::Projection(projection_ty) if !projection_ty.has_escaping_bound_vars() => {
556+
// FIXME(RPITIT): Don't replace RPITITs with inference vars.
557+
ty::Projection(projection_ty)
558+
if !projection_ty.has_escaping_bound_vars()
559+
&& tcx.def_kind(projection_ty.item_def_id)
560+
!= DefKind::ImplTraitPlaceholder =>
561+
{
556562
self.infer_projection(
557563
param_env,
558564
projection_ty,
@@ -568,6 +574,12 @@ impl<'tcx> InferCtxt<'tcx> {
568574
{
569575
hidden_ty
570576
}
577+
// FIXME(RPITIT): This can go away when we move to associated types
578+
ty::Projection(proj)
579+
if def_id.to_def_id() == proj.item_def_id && substs == proj.substs =>
580+
{
581+
hidden_ty
582+
}
571583
_ => ty,
572584
},
573585
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)