1
Fork 0

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, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'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 def_id = tcx.parent(self.item_def_id);
let trait_generics = tcx.generics_of(def_id); let trait_generics = tcx.generics_of(def_id);
( (

View file

@ -122,8 +122,20 @@ where
&mut self, &mut self,
projection: ty::ProjectionTy<'tcx>, projection: ty::ProjectionTy<'tcx>,
) -> ControlFlow<V::BreakTy> { ) -> ControlFlow<V::BreakTy> {
let (trait_ref, assoc_substs) = let tcx = self.def_id_visitor.tcx();
projection.trait_ref_and_own_substs(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)?; self.visit_trait(trait_ref)?;
if self.def_id_visitor.shallow() { if self.def_id_visitor.shallow() {
ControlFlow::CONTINUE ControlFlow::CONTINUE

View file

@ -1325,10 +1325,11 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
) { ) {
let tcx = selcx.tcx(); let tcx = selcx.tcx();
if tcx.def_kind(obligation.predicate.item_def_id) == DefKind::ImplTraitPlaceholder { 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. // 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) == ty::InternalSubsts::identity_for_item(tcx, obligation.predicate.item_def_id)
.type_at(0)
{ {
candidate_set.push_candidate(ProjectionCandidate::ImplTraitInTrait( candidate_set.push_candidate(ProjectionCandidate::ImplTraitInTrait(
ImplTraitInTraitCandidate::Trait, ImplTraitInTraitCandidate::Trait,

View file

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