Polonius is more ergonomic than NLL, but why hasn’t it been integrated into the stable or nightly channels yet?

In terms of lifetime analysis, Polonius is more ergonomic than NLL, but why hasn’t it been integrated into the stable or nightly channels yet?

Consider the following code:

fn get_default<'r,K,V:Default>(map: &'r mut HashMap<K,V>,
                               key: K)
                               -> &'r mut V {
    match map.get_mut(&key) { // -------------+ 'r
        Some(value) => value,              // |
        None => {                          // |
            map.insert(key, V::default()); // |
            //  ^~~~~~ ERROR               // |
            map.get_mut(&key).unwrap()     // |
        }                                  // |
    }                                      // |
}                                          // v

I am using the latest Rust compilers:

rustc 1.85.0 (4d91de4e4 2025-02-17)
rustc 1.87.0-nightly (f4a216d28 2025-03-02)

However, the above code still fails to compile. I suspect that, so far, Rust is still using NLL instead of Polonius. Can anyone explain why Rust has not yet integrated Polonius into the stable or nightly channels? Thank you for your answers.

just finished wathcing this video the other day:

I recommend watching the video @nerditation linked. I believe Amanda mentioned somewhere that Polonius is 5000x slower than the existing borrow-checker; IIRC the plan isn't to use Polonius instead of NLL, but rather use NLL and kick off Polonius for certain failure cases.

With that said, I recently saw some mention on Zulip about some substantial performance gains, and I'm pretty sure it was relating to Polonius. So maybe that is no longer true?

Anywho .. the short version is that Polonius isn't finished yet. Going by the Polonius stream on rust-lang Zulip, it has periods of high activity, and periods of very low activity. It's definitely not dead, but I think it's in a "we definitely want this, but clearly people are being highly productive with Rust without it, so we don't need it tomorrow" place.

2 Likes

It's available on nightly with -Z polonius=legacy or -Z polonius=next.

As someone who follows T-types groups and PRs, :100: this. Here's a relevant tracking issue. As you can see, there are steady updates and progress, including bug fixes and so on. We also may get location insensitive Polonius before location sensitive Polonius.


I for one am excited about the ongoing progress and grateful for those putting in the work to implement it while preserving performance and correctness. I don't think trying to @ people is going to improve matters in any way. No one is holding Polonius back out of lack of desire or spite. It's a tough nut to crack.

11 Likes

In the meantime, you can often get away with using polonius-the-crab — Rust library // Lib.rs

3 Likes