fn main()
{
let str1 = "a".to_string();
{
let str2 = "b".to_string();
longest(&str1, &str2);
}
}
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str
{
if x.len() > y.len()
{
x
}
else
{
y
}
}
How come this code is valid when str1 has a different lifetime compared to str2? Since str2 was defined in an innerscope (inside the main function) so shouldn't the longest function have 'a and 'b?