#![allow(unused)]fnmain() {
fnget_dangling_reference() -> &'statici32 {
let x = 0;
&x
}
}
ⓘ
#![allow(unused)]fnmain() {
use std::slice::Iter;
fnget_dangling_iterator<'a>() -> Iter<'a, i32> {
let v = vec![1, 2, 3];
v.iter()
}
}
ⓘ
Local variables, function parameters and temporaries are all dropped before the
end of the function body. So a reference to them cannot be returned.
Consider returning an owned value instead:
#![allow(unused)]fnmain() {
use std::vec::IntoIter;
fnget_integer() -> i32 {
let x = 0;
x
}
fnget_owned_iterator() -> IntoIter<i32> {
let v = vec![1, 2, 3];
v.into_iter()
}
}