Closure breaks function with higher-ranked trait bound #131677
Labels
A-closures
Area: Closures (`|…| { … }`)
A-higher-ranked
Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
I tried this code:
I expected this to compile, perhaps with warnings. Instead, I get this error:
Rust version: rustc 1.84.0-nightly (27861c4 2024-10-13)
As best as I can tell, this happens when a generic is involved in a higher-ranked trait bound, and a closure is defined inside the function. It seems like since the closure is somewhat generic over
T
, the closure needs to satisfy something about the bound. Things that also exhibit the issue:T: for<'a> Trait<Item<'a> = &'a ()>
Things that don't exhibit the issue:
T: for<'a> Trait<'a>
orfor<'a> T: Trait<'a>
for<'a> &'a ():
f
This is probably the same as #102540 but that issue misidentified the problem and is old. I did some quick checking of old versions and this compiles in 1.20.0 and 1.30.1, throws ICE in 1.40.0, and gives an error in 1.50.0 and 1.60.0. The 1.60.0 error has a little more info.
The ICE from 1.40.0 looks similar to #59311 (weirdly, predates 1.30) and #71546 and looks like this:
The text was updated successfully, but these errors were encountered: