rust-lang / rust-lang/rust

Implementing `Reborrow` on invariant type has strange behavior.

Open
#157,313 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-borrow-checker A-variance C-bug F-reborrow T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

The following code fails to compile, giving a strange error. This seems to be a strange point to error out.

#![feature(reborrow)]

use std::marker::Reborrow;

struct MyMut<'a>(*mut &'a ());

impl Reborrow for MyMut<'_> {}

fn foo(x: MyMut) {
    let _y: MyMut = x;
}
error[E0597]: `x` does not live long enough
  --> src/lib.rs:10:21
   |
 9 | fn foo(x: MyMut) {
   |        -
   |        |
   |        binding `x` declared here
   |        has type `MyMut<'1>`
10 |     let _y: MyMut = x;
   |                     ^
   |                     |
   |                     borrowed value does not live long enough
   |                     requires that `x` is borrowed for `'1`
11 | }
   |  - `x` dropped here while still borrowed

For more information about this error, try `rustc --explain E0597`.

Possibly related to #156310.

cc @aapoalas @P8L1

Meta

Reproducible on the playground with version 1.98.0-nightly (2026-06-01 6bdf43094fae65d298bc)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust playground reproducer using the nightly version noted in the issue, and inspect the Reborrow behavior around the MyMut assignment and E0597 diagnostic. Compare the report with related issue #156310 to establish the intended compiler result; done means this example receives the agreed behavior rather than the reported unexpected borrow error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.