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

Regression: rvalue temporary "does not live long enough" #29166

Closed
DanielKeep opened this issue Oct 19, 2015 · 4 comments
Closed

Regression: rvalue temporary "does not live long enough" #29166

DanielKeep opened this issue Oct 19, 2015 · 4 comments
Assignees
Labels
regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@DanielKeep
Copy link
Contributor

The following code compiles on stable and beta, but not nightly:

/*!
The following is a reduced test case extracted from `cargo-script`, depending on clap 1.4.5.

Fails to compile using 1.5.0-nightly (d3f497861 2015-10-18).

Compiles with rustc 1.4.0-nightly (7bf626a68 2015-09-07).

It compiles without fault on playpen under both stable and beta as of 2015-10-19.
*/

fn main() {
    // This fails to compile:
    drop(vec![&()].into_iter())

    // This *does* compile:
    // drop(vec![&()])

    // So does this:
    // drop([&()].into_iter())
}

For reference, the error produced by the above is:

   Compiling clapsplode v0.1.0 (file:///F:/Programming/Rust/sandbox/cargo-test/clapsplode)
main.rs:13:16: 13:18 error: borrowed value does not live long enough
main.rs:13     drop(vec![&()].into_iter())
                          ^~
main.rs:13:10: 13:19 note: in this expansion of vec! (defined in <std macros>)
main.rs:11:11: 20:2 note: reference must be valid for the destruction scope surrounding block at 11:10...
main.rs:11 fn main() {
main.rs:12     // This fails to compile:
main.rs:13     drop(vec![&()].into_iter())
main.rs:14
main.rs:15     // This *does* compile:
main.rs:16     // drop(vec![&()])
           ...
main.rs:11:11: 20:2 note: ...but borrowed value is only valid for the block at 11:10
main.rs:11 fn main() {
main.rs:12     // This fails to compile:
main.rs:13     drop(vec![&()].into_iter())
main.rs:14
main.rs:15     // This *does* compile:
main.rs:16     // drop(vec![&()])
           ...

The original test case was reduced down to the above thanks to eddyb and bluss. The original problematic line was m.values_of("args").unwrap_or(vec![]).into_iter().map(Into::into).collect() (clap ArgMatchesOption<Vec<&str>>Vec<&str> → boom). Specifically, the issue was with the .into_iter() method, though the error pointed to an earlier temporary as not living long enough.

If desired, I can provide a complete, in-context example of this going awry.

bluss suggested that this was related to #29006.

@DanielKeep
Copy link
Contributor Author

cc @brson

@pnkfelix
Copy link
Member

Hmm I wonder if the iterators involved need to have the escape hatch for dropck added to them.

@pnkfelix
Copy link
Member

Here is a variant (that has also regressed) that does not use the vec! macro:

fn main() {
    drop((match (Vec::new(), &()) { (mut v, b) => { v.push(b); v } })
         .into_iter())
}

@alexcrichton alexcrichton added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Oct 19, 2015
@pnkfelix
Copy link
Member

(It looks like vec::Drain may need similar treatment too, but I am having trouble actually making a concrete test illustrating the necessity there -- it seems when I call .drain instead of .into_iter in the above test case, even stable and beta complain about lifetime issues. Maybe the old dropck is catching something I'm missing in my manual analysis of vec::Drain, so I'm not going to lump that in until I see evidence that it is warranted.)

Update: Oh, duh, Drain has a lifetime bound (and a Drop impl), so of course the old dropck was going to reject it.

@pnkfelix pnkfelix self-assigned this Oct 19, 2015
pnkfelix added a commit to pnkfelix/rust that referenced this issue Oct 20, 2015
bors added a commit that referenced this issue Oct 21, 2015
Add dropck unsafe escape hatch (UGEH) to vec::IntoIter.

Fix #29166
DanielKeep added a commit to DanielKeep/cargo-script that referenced this issue Oct 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

No branches or pull requests

3 participants