Fix test for default body with impl

This commit is contained in:
Michael Goulet 2022-10-05 04:16:05 +00:00
parent 21047f1a1c
commit 79450360d2
4 changed files with 28 additions and 8 deletions

View File

@ -1160,6 +1160,7 @@ impl<'tcx> ProjectionTy<'tcx> {
&self,
tcx: TyCtxt<'tcx>,
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
assert_eq!(tcx.def_kind(def_id), DefKind::Trait);
let def_id = tcx.parent(self.item_def_id);
let trait_generics = tcx.generics_of(def_id);
(

View File

@ -122,8 +122,20 @@ where
&mut self,
projection: ty::ProjectionTy<'tcx>,
) -> ControlFlow<V::BreakTy> {
let (trait_ref, assoc_substs) =
projection.trait_ref_and_own_substs(self.def_id_visitor.tcx());
let tcx = self.def_id_visitor.tcx();
let (trait_ref, assoc_substs) = if tcx.def_kind(projection.item_def_id)
!= DefKind::ImplTraitPlaceholder
{
projection.trait_ref_and_own_substs(tcx)
} else {
// HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys
let def_id = tcx.impl_trait_in_trait_parent(projection.item_def_id);
let trait_generics = tcx.generics_of(def_id);
(
ty::TraitRef { def_id, substs: projection.substs.truncate_to(tcx, trait_generics) },
&projection.substs[trait_generics.count()..],
)
};
self.visit_trait(trait_ref)?;
if self.def_id_visitor.shallow() {
ControlFlow::CONTINUE

View File

@ -1325,10 +1325,11 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
) {
let tcx = selcx.tcx();
if tcx.def_kind(obligation.predicate.item_def_id) == DefKind::ImplTraitPlaceholder {
// If we are trying to project an RPITIT with the _identity_ substs,
// If we are trying to project an RPITIT with trait's default `Self` parameter,
// then we must be within a default trait body.
if obligation.predicate.substs
if obligation.predicate.self_ty()
== ty::InternalSubsts::identity_for_item(tcx, obligation.predicate.item_def_id)
.type_at(0)
{
candidate_set.push_candidate(ProjectionCandidate::ImplTraitInTrait(
ImplTraitInTraitCandidate::Trait,

View File

@ -1,15 +1,21 @@
// check-pass
// edition:2021
#![feature(return_position_impl_trait_in_trait)]
#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)]
#![allow(incomplete_features)]
use std::fmt::Debug;
trait Foo {
async fn baz() -> impl Debug {
Self::baz().await
async fn baz(&self) -> &str {
""
}
}
fn main() {}
struct Bar;
impl Foo for Bar {}
fn main() {
let _ = Bar.baz();
}