Skip to content

Commit

Permalink
Add a test for rust-lang#26619
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Feb 26, 2019
1 parent 26e5fc3 commit d6448a4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/test/ui/issues/issue-26619.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![feature(slice_patterns)]

pub struct History<'a> { pub _s: &'a str }

impl<'a> History<'a> {
pub fn get_page(&self) {
for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
//~^ ERROR borrowed value does not live long enough
println!("{:?}", s);
}
}

fn make_entry(&self, s: &'a String) -> Option<&str> {
let parts: Vec<_> = s.split('|').collect();
println!("{:?} -> {:?}", s, parts);

if let [commit, ..] = &parts[..] { Some(commit) } else { None }
}
}

fn main() {
let h = History{ _s: "" };
h.get_page();
}
12 changes: 12 additions & 0 deletions src/test/ui/issues/issue-26619.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0597]: borrowed value does not live long enough
--> $DIR/issue-26619.rs:7:66
|
LL | for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
| ^^^^^^^^ -- temporary value needs to live until here
| | |
| | temporary value dropped here while still borrowed
| temporary value does not live long enough

error: aborting due to previous error

For more information about this error, try `rustc --explain E0597`.

0 comments on commit d6448a4

Please sign in to comment.