diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-08 08:49:20 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-21 19:20:41 +0100 |
| commit | 85d3ed9c90cdf6802d3425f08eddb3f4f38d2429 (patch) | |
| tree | e65753a60abb2e67c097773c46313cbffa6c208f /src/librustc_parse/parser/ty.rs | |
| parent | b7071f2bc04530c055b2198efb08f2478af32c19 (diff) | |
extract parse_path_start_ty
Diffstat (limited to 'src/librustc_parse/parser/ty.rs')
| -rw-r--r-- | src/librustc_parse/parser/ty.rs | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs index e88bfc17dd6..ddbb9afa02b 100644 --- a/src/librustc_parse/parser/ty.rs +++ b/src/librustc_parse/parser/ty.rs @@ -121,27 +121,7 @@ impl<'a> Parser<'a> { let (qself, path) = self.parse_qpath(PathStyle::Type)?; TyKind::Path(Some(qself), path) } else if self.token.is_path_start() { - // Simple path - let path = self.parse_path(PathStyle::Type)?; - if self.eat(&token::Not) { - // Macro invocation in type position - let args = self.parse_mac_args()?; - let mac = Mac { - path, - args, - prior_type_ascription: self.last_type_ascription, - }; - TyKind::Mac(mac) - } else { - // Just a type path or bound list (trait object type) starting with a trait. - // `Type` - // `Trait1 + Trait2 + 'a` - if allow_plus && self.check_plus() { - self.parse_remaining_bounds(Vec::new(), path, lo, true)? - } else { - TyKind::Path(None, path) - } - } + self.parse_path_start_ty(lo, allow_plus)? } else if self.eat(&token::DotDotDot) { if allow_c_variadic { TyKind::CVarArgs @@ -330,6 +310,31 @@ impl<'a> Parser<'a> { Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::Dyn)) } + /// Parses a type starting with a path. + /// + /// This can be: + /// 1. a type macro, `mac!(...)`, + /// 2. a bare trait object, `B0 + ... + Bn`, + /// 3. or a path, `path::to::MyType`. + fn parse_path_start_ty(&mut self, lo: Span, allow_plus: bool) -> PResult<'a, TyKind> { + // Simple path + let path = self.parse_path(PathStyle::Type)?; + if self.eat(&token::Not) { + // Macro invocation in type position + Ok(TyKind::Mac(Mac { + path, + args: self.parse_mac_args()?, + prior_type_ascription: self.last_type_ascription, + })) + } else if allow_plus && self.check_plus() { + // `Trait1 + Trait2 + 'a` + self.parse_remaining_bounds(Vec::new(), path, lo, true) + } else { + // Just a type path. + Ok(TyKind::Path(None, path)) + } + } + pub(super) fn parse_generic_bounds(&mut self, colon_span: Option<Span>) -> PResult<'a, GenericBounds> { self.parse_generic_bounds_common(true, colon_span) |
