Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"temporary value dropped while borrowed"-checker does not use NLL #93163

Open
JonasAlaif opened this issue Jan 21, 2022 · 0 comments
Open

"temporary value dropped while borrowed"-checker does not use NLL #93163

JonasAlaif opened this issue Jan 21, 2022 · 0 comments
Labels
A-borrow-checker Area: The borrow checker A-NLL Area: Non Lexical Lifetimes (NLL)

Comments

@JonasAlaif
Copy link
Contributor

A slightly modified version of Example 2 from here fails:

fn main() {
    let foo: &mut i32       = &mut 22;
    let mut r_a: &&mut i32  = & foo;
    let r_b: &mut &&mut i32 = &mut r_a;
    let r_c: &&mut i32      = & **r_b;

    // What is considered borrowed here?
    *r_b = &&mut 0;

    println!("{}", r_c);
}

with the following error:

error[E0716]: temporary value dropped while borrowed
  --> src/main.rs:8:13
   |
8  |     *r_b = &&mut 0;
   |             ^^^^^^- temporary value is freed at the end of this statement
   |             |
   |             creates a temporary which is freed while still in use
9  | 
10 |     println!("{}", r_c);
   |                    --- borrow later used here
   |
   = note: consider using a `let` binding to create a longer lived value

However, clearly r_c does not reborrow from r_a nor from r_b. Therefore, using it at the end should not affect either of these, but as we can see this is not the case. If one comments out the println! on line 10, then compilation succeeds as expected. Playground link here

@jyn514 jyn514 added A-borrow-checker Area: The borrow checker A-NLL Area: Non Lexical Lifetimes (NLL) labels May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-NLL Area: Non Lexical Lifetimes (NLL)
Projects
None yet
Development

No branches or pull requests

2 participants