Skip to content

Commit d6448a4

Browse files
committed
Add a test for rust-lang#26619
1 parent 26e5fc3 commit d6448a4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/test/ui/issues/issue-26619.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![feature(slice_patterns)]
2+
3+
pub struct History<'a> { pub _s: &'a str }
4+
5+
impl<'a> History<'a> {
6+
pub fn get_page(&self) {
7+
for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
8+
//~^ ERROR borrowed value does not live long enough
9+
println!("{:?}", s);
10+
}
11+
}
12+
13+
fn make_entry(&self, s: &'a String) -> Option<&str> {
14+
let parts: Vec<_> = s.split('|').collect();
15+
println!("{:?} -> {:?}", s, parts);
16+
17+
if let [commit, ..] = &parts[..] { Some(commit) } else { None }
18+
}
19+
}
20+
21+
fn main() {
22+
let h = History{ _s: "" };
23+
h.get_page();
24+
}

src/test/ui/issues/issue-26619.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0597]: borrowed value does not live long enough
2+
--> $DIR/issue-26619.rs:7:66
3+
|
4+
LL | for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
5+
| ^^^^^^^^ -- temporary value needs to live until here
6+
| | |
7+
| | temporary value dropped here while still borrowed
8+
| temporary value does not live long enough
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)