libsyntax: better error for lifetimes in patterns
Previously, if you copied a signature from a trait definition such as: ``` fn foo<'a>(&'a Bar) -> bool {} ``` and moved it into an `impl`, there would be an error message: "unexpected token `'a`" Adding to the error message that a pattern is expected should help users to find the actual problem with using a lifetime here.
This commit is contained in:
parent
04e497c005
commit
64da379c8c
2 changed files with 20 additions and 0 deletions
|
@ -3196,6 +3196,10 @@ impl<'a> Parser<'a> {
|
|||
// Parse &pat / &mut pat
|
||||
try!(self.expect_and());
|
||||
let mutbl = try!(self.parse_mutability());
|
||||
if let token::Lifetime(ident) = self.token {
|
||||
return Err(self.fatal(&format!("unexpected lifetime `{}` in pattern", ident)));
|
||||
}
|
||||
|
||||
let subpat = try!(self.parse_pat_nopanic());
|
||||
pat = PatRegion(subpat, mutbl);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue