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

IntoIterator for fixed-size arrays shouldn't borrow the original #39257

Closed
jdm opened this issue Jan 23, 2017 · 2 comments
Closed

IntoIterator for fixed-size arrays shouldn't borrow the original #39257

jdm opened this issue Jan 23, 2017 · 2 comments

Comments

@jdm
Copy link
Contributor

jdm commented Jan 23, 2017

fn main() {
    let _v = {
        [0, 1].into_iter()
    }.collect::<Vec<_>>();
}

This yields:

rustc 1.14.0 (e8a012324 2016-12-16)
error: borrowed value does not live long enough
 --> <anon>:5:9
  |
5 |         [0, 1].into_iter()
  |         ^^^^^^ temporary value created here
6 |     }.collect::<Vec<_>>();
  |                          - temporary value only lives until here
7 | }
  | - temporary value needs to live until here
  |
  = note: consider using a `let` binding to increase its lifetime

This is very confusing conceptually, since into_iter() is supposed to consume the value it iterates over. Presumably this happens because IntoIterator is only implemented for &[T; N] and &mut [T; N], and not [T; N].

@malbarbo
Copy link
Contributor

Related #25725

@jdm
Copy link
Contributor Author

jdm commented Jan 23, 2017

Looks like an exact duplicate. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants