why is it impossible for rust to infer the minimal lifetime of parameters automatically?
in page 197 of the rust programming language book i found this and i couldnt understand it
" Rust can analyze the code within the function without any help. However, when a function has references to or from code outside that function, it becomes almost impossible for Rust to figure out the lifetimes of the parameters or return values on its own. The lifetimes might be different each time the function is called. This is why we need to annotate the lifetimes manually".
why is it impossible, cant the complier just figuire it out manually by checking the parameters passed in the function call and then decide the smallest lifetime?
for example:
//declare function longest
fn longest(x: &str, y: &str) -> &str
//call function longest
longest(string1,string2)
why not automatically give the smallest lifetime to both x and y since you already know the lifetime of both string1 and string 2, (in this case string 2 for example has the smallest lifetime).