Skip to content

Commit 85d3ed9

Browse files
committed
extract parse_path_start_ty
1 parent b7071f2 commit 85d3ed9

File tree

1 file changed

+26
-21
lines changed
  • src/librustc_parse/parser

1 file changed

+26
-21
lines changed

src/librustc_parse/parser/ty.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,7 @@ impl<'a> Parser<'a> {
121121
let (qself, path) = self.parse_qpath(PathStyle::Type)?;
122122
TyKind::Path(Some(qself), path)
123123
} else if self.token.is_path_start() {
124-
// Simple path
125-
let path = self.parse_path(PathStyle::Type)?;
126-
if self.eat(&token::Not) {
127-
// Macro invocation in type position
128-
let args = self.parse_mac_args()?;
129-
let mac = Mac {
130-
path,
131-
args,
132-
prior_type_ascription: self.last_type_ascription,
133-
};
134-
TyKind::Mac(mac)
135-
} else {
136-
// Just a type path or bound list (trait object type) starting with a trait.
137-
// `Type`
138-
// `Trait1 + Trait2 + 'a`
139-
if allow_plus && self.check_plus() {
140-
self.parse_remaining_bounds(Vec::new(), path, lo, true)?
141-
} else {
142-
TyKind::Path(None, path)
143-
}
144-
}
124+
self.parse_path_start_ty(lo, allow_plus)?
145125
} else if self.eat(&token::DotDotDot) {
146126
if allow_c_variadic {
147127
TyKind::CVarArgs
@@ -330,6 +310,31 @@ impl<'a> Parser<'a> {
330310
Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::Dyn))
331311
}
332312

313+
/// Parses a type starting with a path.
314+
///
315+
/// This can be:
316+
/// 1. a type macro, `mac!(...)`,
317+
/// 2. a bare trait object, `B0 + ... + Bn`,
318+
/// 3. or a path, `path::to::MyType`.
319+
fn parse_path_start_ty(&mut self, lo: Span, allow_plus: bool) -> PResult<'a, TyKind> {
320+
// Simple path
321+
let path = self.parse_path(PathStyle::Type)?;
322+
if self.eat(&token::Not) {
323+
// Macro invocation in type position
324+
Ok(TyKind::Mac(Mac {
325+
path,
326+
args: self.parse_mac_args()?,
327+
prior_type_ascription: self.last_type_ascription,
328+
}))
329+
} else if allow_plus && self.check_plus() {
330+
// `Trait1 + Trait2 + 'a`
331+
self.parse_remaining_bounds(Vec::new(), path, lo, true)
332+
} else {
333+
// Just a type path.
334+
Ok(TyKind::Path(None, path))
335+
}
336+
}
337+
333338
pub(super) fn parse_generic_bounds(&mut self,
334339
colon_span: Option<Span>) -> PResult<'a, GenericBounds> {
335340
self.parse_generic_bounds_common(true, colon_span)

0 commit comments

Comments
 (0)