about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorKevin Butler <haqkrs@gmail.com>2015-10-25 00:57:42 +0100
committerKevin Butler <haqkrs@gmail.com>2015-10-25 01:28:00 +0100
commit64da379c8c6c967a451817dc4909eeb0055351e7 (patch)
tree0831e691f21f07c6aabb647e9e954f6012ee0493 /src/libsyntax/parse
parent04e497c0056aed899cd6edbc98e7a68a9b391c5c (diff)
downloadrust-64da379c8c6c967a451817dc4909eeb0055351e7.tar.gz
rust-64da379c8c6c967a451817dc4909eeb0055351e7.zip
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.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index fcebe035961..092013a4753 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -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);
           }