Skip to content

Commit b96620e

Browse files
authored
Unrolled build for rust-lang#132373
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 4add5e4 + d53ca63 commit b96620e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,16 @@ pub(super) fn type_param_predicates<'tcx>(
757757
tcx: TyCtxt<'tcx>,
758758
(item_def_id, def_id, assoc_name): (LocalDefId, LocalDefId, Ident),
759759
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
760+
match tcx.opt_rpitit_info(item_def_id.to_def_id()) {
761+
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
762+
return tcx.type_param_predicates((opaque_def_id.expect_local(), def_id, assoc_name));
763+
}
764+
Some(ty::ImplTraitInTraitData::Impl { .. }) => {
765+
unreachable!("should not be lowering bounds on RPITIT in impl")
766+
}
767+
None => {}
768+
}
769+
760770
use rustc_hir::*;
761771
use rustc_middle::ty::Ty;
762772

Lines changed: 13 additions & 0 deletions
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)