A lifetime cannot be determined in the given situation.
Erroneous code example:
#![allow(unused)]
fn main() {
fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
match (&t,) { // error!
((u,),) => u,
}
}
let y = Box::new((42,));
let x = transmute_lifetime(&y);
} In this code, you have two ways to solve this issue:
'a lives at least as long as 'b.So for the first solution, you can do it by replacing 'a with 'a: 'b:
#![allow(unused)]
fn main() {
fn transmute_lifetime<'a: 'b, 'b, T>(t: &'a (T,)) -> &'b T {
match (&t,) { // ok!
((u,),) => u,
}
}
} In the second you can do it by simply removing 'b so they both use 'a:
#![allow(unused)]
fn main() {
fn transmute_lifetime<'a, T>(t: &'a (T,)) -> &'a T {
match (&t,) { // ok!
((u,),) => u,
}
}
}
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/error_codes/E0495.html