Repository navigation
Implementing Reborrow prevents normally moving a value of that type. #156310
Copy link
Copy link
Open
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-bugCategory: This is a bug.Category: This is a bug.F-reborrow`#![feature(reborrow)]`; see #145612`#![feature(reborrow)]`; see #145612T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
Activity
- addedA-borrow-checkerArea: The borrow checkerArea: The borrow checkerT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.C-bugCategory: This is a bug.Category: This is a bug.F-reborrow`#![feature(reborrow)]`; see #145612`#![feature(reborrow)]`; see #145612
on May 8, 2026 - addedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on May 8, 2026 - addedT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.and removedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on May 8, 2026 Just ran into a variant of this: the same issue occurs when creating and returning
Thinginside a function (playground)#![feature(reborrow)] use std::marker::Reborrow; struct Thing<'a>(&'a ()); // Compiles when this line is commented out impl<'a> Reborrow for Thing<'a> {} fn make_thing(x: &'static ()) -> Thing<'static> { Thing(x) } fn make_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]: cannot return 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]: cannot return 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]: cannot return 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
This looks like to have been fixed by #159103.
Metadata
Metadata
Assignees
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-bugCategory: This is a bug.Category: This is a bug.F-reborrow`#![feature(reborrow)]`; see #145612`#![feature(reborrow)]`; see #145612T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
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.