Closed
Description
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 ArgMatches
→ Option<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.