Add a test for #26619

This commit is contained in:
varkor 2019-02-25 23:55:00 +00:00
parent 651c1abfb7
commit d49f4f86d9
2 changed files with 36 additions and 0 deletions

View File

@ -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();
}

View File

@ -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`.