You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implementing Reborrow prevents normally moving a value of that type. #156310
#![feature(reborrow)]use std::marker::Reborrow;structThing<'a>(&'a());impl<'a>ReborrowforThing<'a>{}fnfoo<'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
Just ran into a variant of this: the same issue occurs when creating and returning Thing inside a function (playground)
#![feature(reborrow)]use std::marker::Reborrow;structThing<'a>(&'a());// Compiles when this line is commented outimpl<'a>ReborrowforThing<'a>{}fnmake_thing(x:&'static()) -> Thing<'static>{Thing(x)}fnmake_up_thing() -> Thing<'static>{Thing(&())}
Compiler error
error[E0515]: cannot return value referencing temporary value
--> src/lib.rs:9:49
|
9 | fn make_thing(x:&'static ()) -> Thing<'static> {
| _________________________________________________^
10 | | Thing(x)
| | -------- temporary value created here
11 | | }
| |_^ returns a value referencing data owned by the current function
error[E0515]:cannotreturn reference to temporary value
--> src/lib.rs:9:49
|
9 | fn make_thing(x:&'static ()) -> Thing<'static> {
| _________________________________________________^
10 | | Thing(x)11 | | }
| |_^ returns a reference to data owned by the current function
error[E0515]:cannotreturn value referencing temporary value
--> src/lib.rs:13:38
|
13 | fn make_up_thing() -> Thing<'static> {
| ______________________________________^
14 | | Thing(&())
| | ---------- temporary value created here
15 | | }
| |_^ returns a value referencing data owned by the current function
error[E0515]:cannotreturn reference to temporary value
--> src/lib.rs:13:38
|
13 | fn make_up_thing() -> Thing<'static> {
| ______________________________________^
14 | | Thing(&())15 | | }
| |_^ returns a reference to data owned by the current function
Activity
tvsfx commentedon Jul 21, 2026
Just ran into a variant of this: the same issue occurs when creating and returning
Thinginside a function (playground)Compiler error
fix: UserRef soundness
sleepycatcoding commentedon Sep 6, 2026
This looks like to have been fixed by #159103.