Skip to content

[NLL] rejects-valid vec of array usage #46994

New issue

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

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

Already on GitHub? # to your account

Closed
leonardo-m opened this issue Dec 25, 2017 · 3 comments
Closed

[NLL] rejects-valid vec of array usage #46994

leonardo-m opened this issue Dec 25, 2017 · 3 comments
Labels
A-NLL Area: Non-lexical lifetimes (NLL)

Comments

@leonardo-m
Copy link

This code compiles without feature(nll):

#![feature(nll)]
fn main() {
    let mut m = vec![[0; 1]; 1];
    m[0][0] = 1;
}

With feature(nll) it gives:

error[E0597]: `m` does not live long enough
 --> ...\test.rs:4:5
  |
4 |     m[0][0] = 1;
  |     ^ borrowed value does not live long enough
5 | }
  |  - borrowed value only lives until here
  |
  = note: borrowed value must be valid for lifetime '_#2r...
@leonardo-m
Copy link
Author

Perhaps another example of the same problem:

#![feature(nll)]
fn main() {
    let mut a = [0u8; 1];
    a[0] = 0.to_string().as_bytes()[0];
}

Gives:

error[E0597]: borrowed value does not live long enough
 --> ...\test.rs:4:12
  |
4 |     a[0] = 0.to_string().as_bytes()[0];
  |            ^^^^^^^^^^^^^               - temporary value only lives until here
  |            |
  |            temporary value does not live long enough
  |
  = note: borrowed value must be valid for lifetime '_#3r...

@arielb1
Copy link
Contributor

arielb1 commented Dec 25, 2017

This is fixed on my branch - #46984 - so I'll close it as a duplicate of #46875.

@bstrie bstrie added the A-NLL Area: Non-lexical lifetimes (NLL) label Dec 26, 2017
@CryZe
Copy link
Contributor

CryZe commented Jan 4, 2018

This seems to be fixed now.

@arielb1 arielb1 closed this as completed Jan 15, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL)
Projects
None yet
Development

No branches or pull requests

4 participants