about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChayim Refael Friedman <chayimfr@gmail.com>2025-08-21 20:45:29 +0000
committerGitHub <noreply@github.com>2025-08-21 20:45:29 +0000
commite90138632de9cec54f417b4712a8d1a7f5416ef8 (patch)
tree412fefe8baa8caf93a1628eea32bcea43f494c87
parentd51554749d6a6b2823ac0d88d9d9f0859ff2cee2 (diff)
parent99576aa3f7f6148480608fb62fa10a38cd64f1fd (diff)
downloadrust-e90138632de9cec54f417b4712a8d1a7f5416ef8.tar.gz
rust-e90138632de9cec54f417b4712a8d1a7f5416ef8.zip
Merge pull request #20504 from ShoyuVanilla/ethereum-madness
fix: Infinite recursion while lowering assoc type bounds from supertraits
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/lower_nextsolver.rs6
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs53
2 files changed, 58 insertions, 1 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lower_nextsolver.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lower_nextsolver.rs
index ce953fdcb82..d87181f545d 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/lower_nextsolver.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/lower_nextsolver.rs
@@ -1756,7 +1756,11 @@ fn named_associated_type_shorthand_candidates<'db, R>(
                 db,
                 GenericDefId::TraitId(trait_def_id),
                 PredicateFilter::SelfTrait,
-                |pred| pred == GenericDefId::TraitId(trait_def_id),
+                // We are likely in the midst of lowering generic predicates of `def`.
+                // So, if we allow `pred == def` we might fall into an infinite recursion.
+                // Actually, we have already checked for the case `pred == def` above as we started
+                // with a stack including `trait_id`
+                |pred| pred != def && pred == GenericDefId::TraitId(trait_def_id),
             )
             .0
             .deref()
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
index fd8c641d86e..966433369aa 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
@@ -2439,3 +2439,56 @@ pub fn null_mut<T: PointeeSized + Thin>() -> *mut T {
 "#,
     );
 }
+
+#[test]
+fn issue_20484() {
+    check_no_mismatches(
+        r#"
+struct Eth;
+
+trait FullBlockBody {
+    type Transaction;
+}
+
+impl FullBlockBody for () {
+    type Transaction = ();
+}
+
+trait NodePrimitives {
+    type BlockBody;
+    type SignedTx;
+}
+
+impl NodePrimitives for () {
+    type BlockBody = ();
+    type SignedTx = ();
+}
+
+impl NodePrimitives for Eth {
+    type BlockBody = ();
+    type SignedTx = ();
+}
+
+trait FullNodePrimitives
+where
+    Self: NodePrimitives<BlockBody: FullBlockBody<Transaction = Self::SignedTx>>,
+{
+}
+
+impl<T> FullNodePrimitives for T where
+    T: NodePrimitives<BlockBody: FullBlockBody<Transaction = Self::SignedTx>>,
+{
+}
+
+fn node<N>(_: N)
+where
+    N: FullNodePrimitives,
+{
+}
+
+fn main() {
+    node(Eth);
+}
+"#,
+    );
+}