Skip to content

Commit bdccbcf

Browse files
committed
parse dyn (Foo) as a trait object
1 parent 063deba commit bdccbcf

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,14 @@ impl TokenType {
405405
}
406406
}
407407

408-
// Returns true if `IDENT t` can start a type - `IDENT::a::b`, `IDENT<u8, u8>`,
409-
// `IDENT<<u8 as Trait>::AssocTy>`, `IDENT(u8, u8) -> u8`.
410-
fn can_continue_type_after_ident(t: &token::Token) -> bool {
408+
/// Returns true if `IDENT t` can start a type - `IDENT::a::b`, `IDENT<u8, u8>`,
409+
/// `IDENT<<u8 as Trait>::AssocTy>`.
410+
///
411+
/// Types can also be of the form `IDENT(u8, u8) -> u8`, however this assumes
412+
/// that IDENT is not the ident of a fn trait
413+
fn can_continue_type_after_non_fn_ident(t: &token::Token) -> bool {
411414
t == &token::ModSep || t == &token::Lt ||
412-
t == &token::BinOp(token::Shl) || t == &token::OpenDelim(token::Paren)
415+
t == &token::BinOp(token::Shl)
413416
}
414417

415418
/// Information about the path to a module.
@@ -1619,7 +1622,8 @@ impl<'a> Parser<'a> {
16191622
impl_dyn_multi = bounds.len() > 1 || self.prev_token_kind == PrevTokenKind::Plus;
16201623
TyKind::ImplTrait(bounds)
16211624
} else if self.check_keyword(keywords::Dyn) &&
1622-
self.look_ahead(1, |t| t.can_begin_bound() && !can_continue_type_after_ident(t)) {
1625+
self.look_ahead(1, |t| t.can_begin_bound() &&
1626+
!can_continue_type_after_non_fn_ident(t)) {
16231627
self.bump(); // `dyn`
16241628
// Always parse bounds greedily for better error recovery.
16251629
let bounds = self.parse_ty_param_bounds()?;

0 commit comments

Comments
 (0)