about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-10-31 01:14:03 +0100
committerGitHub <noreply@github.com>2024-10-31 01:14:03 +0100
commitefd5645e432fb153dae6b3583d48cb40fbaa14a3 (patch)
tree5fe527a4aa42e4bb60db1bb5b355ac8fe522a7c9
parent271a8c9f43c395cb52820c25ca6863c91c0c73c9 (diff)
parentd53ca634532d548ad30cb75af3f93030f1b415f4 (diff)
downloadrust-efd5645e432fb153dae6b3583d48cb40fbaa14a3.tar.gz
rust-efd5645e432fb153dae6b3583d48cb40fbaa14a3.zip
Rollup merge of #132373 - compiler-errors:rpitit-bound, r=fmease
Make sure `type_param_predicates` resolves correctly for RPITIT

After #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 #132372
-rw-r--r--compiler/rustc_hir_analysis/src/collect/predicates_of.rs10
-rw-r--r--tests/ui/impl-trait/in-trait/shorthand-projection-in-rpitit-bound.rs13
2 files changed, 23 insertions, 0 deletions
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<X: Bar>() -> impl Bar<Foo = X::Foo>;
+}
+
+fn main() {}