willcrichton / flowistry

Flowistry is an IDE plugin for Rust that helps you focus on relevant code.
https://marketplace.visualstudio.com/items?itemName=wcrichton.flowistry
MIT License
1.91k stars 45 forks source link

[PDG] Strong updates to mutable references don't seem to work. #90

Open JustusAdam opened 10 months ago

JustusAdam commented 10 months ago

I tried code equivalent to this

let mut user_data = Vec::new();
user_data.push(0);
send(&user_data);

What I expected is that the vector connects to the first argument of push and then to the first argument of send. Instead there is an additional direct connection from the initial vector to the first argument of send.

The same actually happens with return values too.

let mut user_data = Vec::new();
let r = user_data.deref();
send(r);

This also has a direct connection between the vector and send, despite the code clearly always going through deref.

JustusAdam commented 9 months ago

Actually after some experimentation it sems to also happen with immutable references which is strange to me? This is the code I analyzed:

fn main() {
    let s = new_s();
    // 'a : 'b
    let t = deref_t(&s);
    read(t);
}

// Type signatures for external functions
fn deref_t(s: &S) -> &String;
fn read<T>(t: &T);
fn new_s() -> S;

The result has an edge from s to the first argument of read which I believe it shouldn't. It is not possible for any part of s to reach that place without passing through/being selected by deref_t.