Merge pull request #518 from mjbshaw/arb_self_ty
Parse arbitrary self types as PatIdent
diff --git a/src/expr.rs b/src/expr.rs
index 1c883c8..7f43fb9 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -2531,16 +2531,20 @@
ahead.is_empty() || ahead.peek(Token![,])
}
})
+ || input.peek(Token![self]) && input.peek2(Token![::])
|| input.peek(Token![::])
|| input.peek(Token![<])
- || input.peek(Token![self])
|| input.peek(Token![Self])
|| input.peek(Token![super])
|| input.peek(Token![extern])
|| input.peek(Token![crate])
{
pat_path_or_macro_or_struct_or_range(input)
- } else if input.peek(Token![ref]) || input.peek(Token![mut]) || input.peek(Ident) {
+ } else if input.peek(Token![ref])
+ || input.peek(Token![mut])
+ || input.peek(Token![self])
+ || input.peek(Ident)
+ {
input.call(pat_ident).map(Pat::Ident)
} else if lookahead.peek(token::Paren) {
input.call(pat_tuple).map(Pat::Tuple)
diff --git a/tests/test_pat.rs b/tests/test_pat.rs
new file mode 100644
index 0000000..ee54e23
--- /dev/null
+++ b/tests/test_pat.rs
@@ -0,0 +1,27 @@
+// Copyright 2018 Syn Developers
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#[macro_use]
+extern crate quote;
+extern crate syn;
+
+#[test]
+fn test_pat_ident() {
+ match syn::parse2(quote!(self)).unwrap() {
+ syn::Pat::Ident(_) => (),
+ value => panic!("expected PatIdent, got {:?}", value),
+ }
+}
+
+#[test]
+fn test_pat_path() {
+ match syn::parse2(quote!(self::CONST)).unwrap() {
+ syn::Pat::Path(_) => (),
+ value => panic!("expected PatPath, got {:?}", value),
+ }
+}
\ No newline at end of file