I am looking to do some analysis of how certain functions cause dependencies between variable lifetimes.
For example, with
let x_0: Vec<String> = vec![ "A".to_string(), "B".to_string()]; let x_1: Option<&mut String> = x_0.get_mut(0); let x_2: &mut String = x_1.unwrap();
We know that
x_0 must outlive
x_2 because the reference is to a memory location owned by the vector
However, this is not clear by looking at the type signature of
Vec::get_mut. There are no obvious lifetime annotations.
pub fn get_mut<I>( &mut self, index: I ) -> Option<&mut <I as SliceIndex<[T]>>::Output> where I: SliceIndex<[T]>,
First of all, since
rustc is already doing this, is there a way to extract that data for each function? If not, what is the easiest way to model this externally?
Please note that I ask for lifetime information on each function and not entire programs because the end goal for my project is to automatically assemble unit tests, thus I don't have the entire program to start out with. Lifetime information for each function in needed for semantically accurate assembly.
Thank you for your time.