mirror of
https://gitee.com/openharmony/third_party_rust_syn
synced 2024-11-27 09:50:41 +00:00
Parse arbitrary self types as PatIdent
This commit is contained in:
parent
d8666299ca
commit
7531e1579d
@ -2531,16 +2531,20 @@ pub mod parsing {
|
||||
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)
|
||||
|
27
tests/test_pat.rs
Normal file
27
tests/test_pat.rs
Normal file
@ -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),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user