diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2018-02-23 12:39:51 -0800 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2018-02-23 12:39:51 -0800 |
| commit | bdccbcf41bd881806d5370b8c7fe05e90143a076 (patch) | |
| tree | efd12e9f0ab336f7b542c17cdaa12c0225321446 /src/libsyntax/parse/parser.rs | |
| parent | 063deba92e44809125a433ca6e6c1ad0993313bf (diff) | |
| download | rust-bdccbcf41bd881806d5370b8c7fe05e90143a076.tar.gz rust-bdccbcf41bd881806d5370b8c7fe05e90143a076.zip | |
parse `dyn (Foo)` as a trait object
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 74daa5179d3..f798855d0e0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -405,11 +405,14 @@ impl TokenType { } } -// Returns true if `IDENT t` can start a type - `IDENT::a::b`, `IDENT<u8, u8>`, -// `IDENT<<u8 as Trait>::AssocTy>`, `IDENT(u8, u8) -> u8`. -fn can_continue_type_after_ident(t: &token::Token) -> bool { +/// Returns true if `IDENT t` can start a type - `IDENT::a::b`, `IDENT<u8, u8>`, +/// `IDENT<<u8 as Trait>::AssocTy>`. +/// +/// Types can also be of the form `IDENT(u8, u8) -> u8`, however this assumes +/// that IDENT is not the ident of a fn trait +fn can_continue_type_after_non_fn_ident(t: &token::Token) -> bool { t == &token::ModSep || t == &token::Lt || - t == &token::BinOp(token::Shl) || t == &token::OpenDelim(token::Paren) + t == &token::BinOp(token::Shl) } /// Information about the path to a module. @@ -1619,7 +1622,8 @@ impl<'a> Parser<'a> { impl_dyn_multi = bounds.len() > 1 || self.prev_token_kind == PrevTokenKind::Plus; TyKind::ImplTrait(bounds) } else if self.check_keyword(keywords::Dyn) && - self.look_ahead(1, |t| t.can_begin_bound() && !can_continue_type_after_ident(t)) { + self.look_ahead(1, |t| t.can_begin_bound() && + !can_continue_type_after_non_fn_ident(t)) { self.bump(); // `dyn` // Always parse bounds greedily for better error recovery. let bounds = self.parse_ty_param_bounds()?; |
