Skip to content

Commit 7945036

Browse files
Fix test for default body with impl
1 parent 21047f1 commit 7945036

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

Diff for: compiler/rustc_middle/src/ty/sty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@ impl<'tcx> ProjectionTy<'tcx> {
11601160
&self,
11611161
tcx: TyCtxt<'tcx>,
11621162
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
1163+
assert_eq!(tcx.def_kind(def_id), DefKind::Trait);
11631164
let def_id = tcx.parent(self.item_def_id);
11641165
let trait_generics = tcx.generics_of(def_id);
11651166
(

Diff for: compiler/rustc_privacy/src/lib.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,20 @@ where
122122
&mut self,
123123
projection: ty::ProjectionTy<'tcx>,
124124
) -> ControlFlow<V::BreakTy> {
125-
let (trait_ref, assoc_substs) =
126-
projection.trait_ref_and_own_substs(self.def_id_visitor.tcx());
125+
let tcx = self.def_id_visitor.tcx();
126+
let (trait_ref, assoc_substs) = if tcx.def_kind(projection.item_def_id)
127+
!= DefKind::ImplTraitPlaceholder
128+
{
129+
projection.trait_ref_and_own_substs(tcx)
130+
} else {
131+
// HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys
132+
let def_id = tcx.impl_trait_in_trait_parent(projection.item_def_id);
133+
let trait_generics = tcx.generics_of(def_id);
134+
(
135+
ty::TraitRef { def_id, substs: projection.substs.truncate_to(tcx, trait_generics) },
136+
&projection.substs[trait_generics.count()..],
137+
)
138+
};
127139
self.visit_trait(trait_ref)?;
128140
if self.def_id_visitor.shallow() {
129141
ControlFlow::CONTINUE

Diff for: compiler/rustc_trait_selection/src/traits/project.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1325,10 +1325,11 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
13251325
) {
13261326
let tcx = selcx.tcx();
13271327
if tcx.def_kind(obligation.predicate.item_def_id) == DefKind::ImplTraitPlaceholder {
1328-
// If we are trying to project an RPITIT with the _identity_ substs,
1328+
// If we are trying to project an RPITIT with trait's default `Self` parameter,
13291329
// then we must be within a default trait body.
1330-
if obligation.predicate.substs
1330+
if obligation.predicate.self_ty()
13311331
== ty::InternalSubsts::identity_for_item(tcx, obligation.predicate.item_def_id)
1332+
.type_at(0)
13321333
{
13331334
candidate_set.push_candidate(ProjectionCandidate::ImplTraitInTrait(
13341335
ImplTraitInTraitCandidate::Trait,

Diff for: src/test/ui/impl-trait/in-trait/default-body.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
// check-pass
22
// edition:2021
33

4-
#![feature(return_position_impl_trait_in_trait)]
4+
#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)]
55
#![allow(incomplete_features)]
66

77
use std::fmt::Debug;
88

99
trait Foo {
10-
async fn baz() -> impl Debug {
11-
Self::baz().await
10+
async fn baz(&self) -> &str {
11+
""
1212
}
1313
}
1414

15-
fn main() {}
15+
struct Bar;
16+
17+
impl Foo for Bar {}
18+
19+
fn main() {
20+
let _ = Bar.baz();
21+
}

0 commit comments

Comments
 (0)