From d53ca634532d548ad30cb75af3f93030f1b415f4 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 30 Oct 2024 22:30:28 +0000 Subject: [PATCH] Make sure type_param_predicates resolves correctly for RPITIT --- .../rustc_hir_analysis/src/collect/predicates_of.rs | 10 ++++++++++ .../shorthand-projection-in-rpitit-bound.rs | 13 +++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/ui/impl-trait/in-trait/shorthand-projection-in-rpitit-bound.rs diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 644ff0c667c..4cdf0fc545c 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -764,6 +764,16 @@ pub(super) fn type_param_predicates<'tcx>( tcx: TyCtxt<'tcx>, (item_def_id, def_id, assoc_name): (LocalDefId, LocalDefId, Ident), ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> { + match tcx.opt_rpitit_info(item_def_id.to_def_id()) { + Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => { + return tcx.type_param_predicates((opaque_def_id.expect_local(), def_id, assoc_name)); + } + Some(ty::ImplTraitInTraitData::Impl { .. }) => { + unreachable!("should not be lowering bounds on RPITIT in impl") + } + None => {} + } + use rustc_hir::*; use rustc_middle::ty::Ty; diff --git a/tests/ui/impl-trait/in-trait/shorthand-projection-in-rpitit-bound.rs b/tests/ui/impl-trait/in-trait/shorthand-projection-in-rpitit-bound.rs new file mode 100644 index 00000000000..102b53f4957 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/shorthand-projection-in-rpitit-bound.rs @@ -0,0 +1,13 @@ +//@ check-pass + +// Ensure that we can resolve a shorthand projection in an item bound in an RPITIT. + +pub trait Bar { + type Foo; +} + +pub trait Baz { + fn boom() -> impl Bar; +} + +fn main() {}