Skip to content

Commit efd5645

Browse files
authored
Rollup merge of rust-lang#132373 - compiler-errors:rpitit-bound, r=fmease
Make sure `type_param_predicates` resolves correctly for RPITIT After rust-lang#132194, we end up lowering the item bounds for an RPITIT in an `ItemCtxt` whose def id is the *synthetic GAT*, not the opaque type from the HIR. This means that when we're resolving a shorthand projection like `T::Assoc`, we call the `type_param_predicates` function with the `item_def_id` of the *GAT* and not the opaque. That function operates on the HIR, and is not designed to work with the `Node::Synthetic` that gets fed for items synthesized by the compiler... This PR reuses the trick we use elsewhere in lowering, where we intercept whether an item comes from RPITIT lowering, and forwards the query off to the correct item. Fixes rust-lang#132372
2 parents 271a8c9 + d53ca63 commit efd5645

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Diff for: compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+10
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,16 @@ pub(super) fn type_param_predicates<'tcx>(
764764
tcx: TyCtxt<'tcx>,
765765
(item_def_id, def_id, assoc_name): (LocalDefId, LocalDefId, Ident),
766766
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
767+
match tcx.opt_rpitit_info(item_def_id.to_def_id()) {
768+
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
769+
return tcx.type_param_predicates((opaque_def_id.expect_local(), def_id, assoc_name));
770+
}
771+
Some(ty::ImplTraitInTraitData::Impl { .. }) => {
772+
unreachable!("should not be lowering bounds on RPITIT in impl")
773+
}
774+
None => {}
775+
}
776+
767777
use rustc_hir::*;
768778
use rustc_middle::ty::Ty;
769779

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ check-pass
2+
3+
// Ensure that we can resolve a shorthand projection in an item bound in an RPITIT.
4+
5+
pub trait Bar {
6+
type Foo;
7+
}
8+
9+
pub trait Baz {
10+
fn boom<X: Bar>() -> impl Bar<Foo = X::Foo>;
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)