Skip to content

Implementing Reborrow on invariant type has strange behavior. #157313

Closed

Description

@theemathas

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)

Activity

  1. added
    C-bug
    on Jun 2, 2026
  2. added
    needs-triage
    on Jun 2, 2026
  3. added
    T-compiler
    A-variance
    T-types
    F-reborrow
    A-borrow-checker
    and removed
    needs-triage
    on Jun 2, 2026
  4. Jules-Bertholet commented on Sep 30, 2026

    @Jules-Bertholet
    Contributor

    This now compiles

  5. added
    E-needs-test
    on Sep 30, 2026
  6. zanville commented on Oct 5, 2026

    @zanville
    Contributor

    @rustbot claim

  7. added 3 commits that reference this issue on Oct 25, 2026
    3979c08
    01fe945
    8b55dde
  8. added a commit that references this issue on Oct 26, 2026
    39b2afd
  9. added a commit that references this issue on Oct 26, 2026
    2443d48
  10. added a commit that references this issue on Nov 16, 2026
    0e21563
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-borrow-checkerA-varianceC-bugE-needs-testF-reborrowT-compilerT-types

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions