Rust's borrow checker has been unsound since version 1.4, a new bug report reveals

11 year old unsoundness bugs found in Rust borrow checker

Rust's borrow checker has been unsound since version 1.4, a new bug report reveals

A GitHub issue filed by jsnell shows that Rust's lifetime requirements can be bypassed through covariant field assignment. A struct with a 'static bound can be handed a non-'static reference, letting Drop code treat a dangling pointer as valid. The bug compiles on stable releases back to 1.4, and ASan flags a stack-use-after-scope. Rust maintainers have labeled it I-unsound and P-high.

My version of the code has been compiling ever since 1.18.0 (2017). How on earth was this not found before this???
  1. mrkeen

    Type systems are hard! Check out https://counterexamples.org/

    I gave it a quick scan for Rust examples; there are 11 samples among the following pages:

    https://counterexamples.org/eventually-nothing.html

    https://counterexamples.org/mutable-matching.html

    https://counterexamples.org/selfishness.html

    https://counterexamples.org/scope-escape.html

    https://counterexamples.org/nearly-universal.html

    The first thing I always look for is mutability (combined with some other tricky feature), e.g. "Now it's a Just(3):Maybe<Int>, now it's a Nothing:Maybe<Int>, now it's a Nothing:Maybe<String>."

    I wonder if TFA's example could be reproduced without mutability.

  2. GrantMoyer

    It's surprising this bug went unnoticed for so long, but at least it's easy to fix, since it's not a bug with the type system itself; it's just a bug in the compiler. The compiler should always have been rejecting that code according to lifetime rules of Rust's type system, so the fix is to just make it reject the code, rather than having to change the fundamental rules of lifetimes.

  3. weinzierl

    This is remarkable but not super unusual. There are more than 100 issues labeled unsound currently. Some are long standing but from what I understand the new trait solver will unblock fixes for some of them (but probably not the one in OP).

  4. lambdaone

    Perhaps ironically, AI-based searching of the Rust compiler for bugs is likely to find more of these, pushing Rust closer and closer to the point of complete reliability.

    The eventual formalization of Rust and a creation of a formally proven compiler is presumably going to be the end point of this process.

  5. Eridrus

    I feel like these things get waved around as gotchas without any sense for whether any real code is impacted.

    It will be interesting to see if fixing this bug actually causes any crates to not compile.

  6. Surac

    The question is. If rust used rust would that have prevented this?

  7. sreekanth850

    Was this done by LLM? this is a doubt. because recently we are seeing many such bug reports.

  8. FuzzywarmWalnut

    Worked on a variance-related lint once and the scary part is how rarely anyone writes down variance by hand, so bugs there just sit untested for a decade.

  9. randyrand

    I just wish Rust handled out of memory more gracefully like a normal error.

  10. wat10000

    The emotional reactions to this stuff are so weird. Yeah, software has bugs, what a surprise. That doesn't mean that static safety is useless or that we should all just continue YOLOing stuff in C.

More from this day

2026-10-13