Skip to content

Commit 14872a5

Browse files
Merge pull request #20504 from ShoyuVanilla/ethereum-madness
fix: Infinite recursion while lowering assoc type bounds from supertraits
2 parents 9577ca7 + 80ce520 commit 14872a5

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

crates/hir-ty/src/lower_nextsolver.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,11 @@ fn named_associated_type_shorthand_candidates<'db, R>(
17561756
db,
17571757
GenericDefId::TraitId(trait_def_id),
17581758
PredicateFilter::SelfTrait,
1759-
|pred| pred == GenericDefId::TraitId(trait_def_id),
1759+
// We are likely in the midst of lowering generic predicates of `def`.
1760+
// So, if we allow `pred == def` we might fall into an infinite recursion.
1761+
// Actually, we have already checked for the case `pred == def` above as we started
1762+
// with a stack including `trait_id`
1763+
|pred| pred != def && pred == GenericDefId::TraitId(trait_def_id),
17601764
)
17611765
.0
17621766
.deref()

crates/hir-ty/src/tests/regression.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,3 +2439,56 @@ pub fn null_mut<T: PointeeSized + Thin>() -> *mut T {
24392439
"#,
24402440
);
24412441
}
2442+
2443+
#[test]
2444+
fn issue_20484() {
2445+
check_no_mismatches(
2446+
r#"
2447+
struct Eth;
2448+
2449+
trait FullBlockBody {
2450+
type Transaction;
2451+
}
2452+
2453+
impl FullBlockBody for () {
2454+
type Transaction = ();
2455+
}
2456+
2457+
trait NodePrimitives {
2458+
type BlockBody;
2459+
type SignedTx;
2460+
}
2461+
2462+
impl NodePrimitives for () {
2463+
type BlockBody = ();
2464+
type SignedTx = ();
2465+
}
2466+
2467+
impl NodePrimitives for Eth {
2468+
type BlockBody = ();
2469+
type SignedTx = ();
2470+
}
2471+
2472+
trait FullNodePrimitives
2473+
where
2474+
Self: NodePrimitives<BlockBody: FullBlockBody<Transaction = Self::SignedTx>>,
2475+
{
2476+
}
2477+
2478+
impl<T> FullNodePrimitives for T where
2479+
T: NodePrimitives<BlockBody: FullBlockBody<Transaction = Self::SignedTx>>,
2480+
{
2481+
}
2482+
2483+
fn node<N>(_: N)
2484+
where
2485+
N: FullNodePrimitives,
2486+
{
2487+
}
2488+
2489+
fn main() {
2490+
node(Eth);
2491+
}
2492+
"#,
2493+
);
2494+
}

0 commit comments

Comments
 (0)