How polonius analyzes code on the CFG

⚓ rust    📅 2025-06-19    👤 surdeus    👁️ 2      

surdeus

I read an-alias-based-formulation-of-the-borrow-checker, but the article doesn't mention:

  1. How Polonius works when the origin of input and output references in function signatures are the same.
  2. How Polonius handles reborrow constraints. NLL describes this in detail and introduces a concept called "supporting prefixes," but Polonius lacks description about handling reborrows.
  3. I'd like to understand more details about how Polonius analyzes code on the CFG (Control Flow Graph).

Take the following example:

use std::collections::HashMap;
use std::hash::Hash;

fn get_default<'r, K, V>(map: &'r mut HashMap<K, V>, key: K) -> &'r mut V
where K: Clone + Eq + Hash, V: Default + Clone,
{
    match map.get_mut(&key) {
        Some(value) => { /* nothing... */ }
        None => {
            map.insert(key.clone(), V::default());  
            return map.get_mut(&key).unwrap();
        }
    } 

    map.get_mut(&key).unwrap()
}

In this example, the origin of the input and output references is the same, and reborrows also occur. I'd like to understand how Polonius operates on the CFG corresponding to this code.
Thank you very much for your help.

1 post - 1 participant

Read full topic

🏷️ rust_feed