I tried this code:
#![feature(reborrow)]
use std::marker::Reborrow;
struct Thing<'a>(&'a ());
impl<'a> Reborrow for Thing<'a> {}
fn foo<'a>(x: Thing<'a>) -> Thing<'a> {
x
}
I expected this code to compile, since it's just an identity function. Instead, I got the following error:
Checking foo v0.1.0 (/Users/timch/foo)
error[E0515]: cannot return reference to temporary value
--> src/lib.rs:9:39
|
9 | fn foo<'a>(x: Thing<'a>) -> Thing<'a> {
| _______________________________________^
10 | | x
11 | | }
| |_^ returns a reference to data owned by the current function
error[E0515]: cannot return value referencing function parameter `x`
--> src/lib.rs:9:39
|
9 | fn foo<'a>(x: Thing<'a>) -> Thing<'a> {
| _______________________________________^
10 | | x
| | - `x` is borrowed here
11 | | }
| |_^ returns a value referencing data owned by the current function
For more information about this error, try `rustc --explain E0515`.
error: could not compile `foo` (lib) due to 2 previous errors
cc @aapoalas
Meta
rustc --version --verbose:
rustc 1.97.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: aarch64-apple-darwin
release: 1.97.0-dev
LLVM version: 22.1.4
Compiled from the main branch at commit 63b1dfc.
I tried this code:
I expected this code to compile, since it's just an identity function. Instead, I got the following error:
cc @aapoalas
Meta
rustc --version --verbose:Compiled from the
mainbranch at commit 63b1dfc.