]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-54556-stephaneyfx.rs
Rollup merge of #105216 - GuillaumeGomez:rm-unused-gui-test, r=notriddle
[rust.git] / src / test / ui / nll / issue-54556-stephaneyfx.rs
1 // This is a reduction of a concrete test illustrating a case that was
2 // annoying to Rust developer stephaneyfx (see issue #46413).
3 //
4 // With resolving issue #54556, pnkfelix hopes that the new diagnostic
5 // output produced by NLL helps to *explain* the semantic significance
6 // of temp drop order, and thus why storing the result in `x` and then
7 // returning `x` works.
8
9 pub struct Statement;
10
11 pub struct Rows<'stmt>(&'stmt Statement);
12
13 impl<'stmt> Drop for Rows<'stmt> {
14     fn drop(&mut self) {}
15 }
16
17 impl<'stmt> Iterator for Rows<'stmt> {
18     type Item = String;
19
20     fn next(&mut self) -> Option<Self::Item> {
21         None
22     }
23 }
24
25 fn get_names() -> Option<String> {
26     let stmt = Statement;
27     let rows = Rows(&stmt); //~ ERROR does not live long enough
28     rows.map(|row| row).next()
29     // let x = rows.map(|row| row).next();
30     // x
31     //
32     // Removing the map works too as does removing the Drop impl.
33 }
34
35 fn main() {}