Skip to content

Non-Lexical Lifetimes only work with some types #46935

Closed
@CryZe

Description

@CryZe

This one is really weird. It's the same code, but one is a Vec and one is a i32. The Vec one compiles, the i32 one doesn't:

fn vec() {
    let mut _x = vec!['c'];
    let _y = &_x;
    _x = Vec::new();
}

fn int()  {
    let mut _x = 5;
    let _y = &_x;
    _x = 7;
}

Error:

error[E0506]: cannot assign to `_x` because it is borrowed
  --> src\lib.rs:49:5
   |
48 |     let _y = &_x;
   |              --- borrow of `_x` occurs here
49 |     _x = 7;
   |     ^^^^^^ assignment to borrowed `_x` occurs here

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions