Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle return-position impl Trait in traits properly in register_hidden_type #103355

Merged
merged 1 commit into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion compiler/rustc_infer/src/infer/opaque_types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::errors::OpaqueHiddenTypeDiag;
use crate::infer::{DefiningAnchor, InferCtxt, InferOk};
use crate::traits;
use hir::def::DefKind;
use hir::def_id::{DefId, LocalDefId};
use hir::{HirId, OpaqueTyOrigin};
use rustc_data_structures::sync::Lrc;
Expand Down Expand Up @@ -552,7 +553,12 @@ impl<'tcx> InferCtxt<'tcx> {
ty_op: |ty| match *ty.kind() {
// We can't normalize associated types from `rustc_infer`,
// but we can eagerly register inference variables for them.
ty::Projection(projection_ty) if !projection_ty.has_escaping_bound_vars() => {
// FIXME(RPITIT): Don't replace RPITITs with inference vars.
ty::Projection(projection_ty)
if !projection_ty.has_escaping_bound_vars()
&& tcx.def_kind(projection_ty.item_def_id)
!= DefKind::ImplTraitPlaceholder =>
{
self.infer_projection(
param_env,
projection_ty,
Expand All @@ -568,6 +574,12 @@ impl<'tcx> InferCtxt<'tcx> {
{
hidden_ty
}
// FIXME(RPITIT): This can go away when we move to associated types
ty::Projection(proj)
if def_id.to_def_id() == proj.item_def_id && substs == proj.substs =>
{
hidden_ty
}
_ => ty,
},
lt_op: |lt| lt,
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/impl-trait/in-trait/default-body-type-err-2.rs
Original file line number Diff line number Diff line change
@@ -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() {}
11 changes: 11 additions & 0 deletions src/test/ui/impl-trait/in-trait/default-body-type-err-2.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions src/test/ui/impl-trait/in-trait/default-body-type-err.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions src/test/ui/impl-trait/in-trait/default-body-type-err.stderr
Original file line number Diff line number Diff line change
@@ -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`.
2 changes: 1 addition & 1 deletion src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// known-bug: #102688
// check-pass
// edition:2021

#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)]
Expand Down
12 changes: 0 additions & 12 deletions src/test/ui/impl-trait/in-trait/default-body-with-rpit.stderr

This file was deleted.