Skip to content

Conversation

@rynewang
Copy link
Owner

@rynewang rynewang commented Feb 7, 2026

Summary

Fix ICE in closure capture migration analysis when encountering associated type projections.

Problem

#![deny(rust_2021_incompatible_closure_captures)]
struct Foo;
struct S;
impl Drop for S { fn drop(&mut self) {} }
struct U(<Foo as NewTrait>::Assoc);
fn test(u: U) { let _ = || { let _x = u.0.0; }; }
trait NewTrait { type Assoc; }
impl NewTrait for Foo { type Assoc = (S,); }

ICEs at upvar.rs:1685 with unreachable!().

Fix

Replace three unreachable!() calls with conservative fallbacks:

  • unreachable!() in filter_map → None
  • _ => unreachable!()_ => false

Safe because this only affects the edition migration lint — conservative false means we might miss a warning, which is better than an ICE.

Includes regression test.

Fixes rust-lang#152205

The closure capture migration analysis (`rust_2021_incompatible_closure_captures`)
hit `unreachable!()` in `has_significant_drop_outside_of_captures` when
encountering associated type projections (`ty::Alias`).

Three `unreachable!()` calls in `upvar.rs` assumed only certain type kinds
and projection kinds would appear, but associated types like
`<Foo as Trait>::Assoc` can produce unexpected patterns.

Replace the panics with conservative fallbacks:
- `unreachable!()` in filter_map closures → `None` (filter out)
- `_ => unreachable!()` in main match → `false` (no significant drop)

This is safe because the function is only used for the edition migration
lint, so a conservative `false` just means we might miss a warning about
incompatible closure captures, which is better than an ICE.

Fixes rust-lang#152205
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE : internal error: entered unreachable code

1 participant