-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Chapter 8.1: Explanation for listing 8-7 seems to be incorrect #1785
Comments
@piotr-szpetkowski I think this is due to non lexical lifetimes and the fact you don't try to use 'first' after the push and the same code will not compile if you don't use 2018 edition semantics. Can you try removing the edition field from Cargo.toml to check? |
@eddyp Yeah, it looks like you're right. In case of 2015 edition it fails on push with |
@piotr-szpetkowski OK, going back to 2018, I think it will fail with non lexical lifetimes if you try to use 'first', say by println!("first = {}", first) after the v.push. Can try that, too? |
@eddyp Sure, I've already tried that before when I've been experimenting with the listing from the book and it does cause an error which is presented in Listing 8.7 of the book. So, basically it seems like Listing has been updated for the 2018 edition, but the explanation hasn't. |
It's not just that we add something to the end, it's also that we need to hold onto the reference. FIxes #1785
It's quite interesting, because I've tried it out with Rust 1.32 and pushing new element to vector seems to work just fine:
Output:
In my case it's printing variable
first
after pushing to vector that causes the error.The text was updated successfully, but these errors were encountered: