Skip to content

Commit 10270bc

Browse files
committed
Fuse associated type parsing.
1 parent 2d92aa5 commit 10270bc

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

src/librustc_parse/parser/item.rs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ impl<'a> Parser<'a> {
698698
let vis = self.parse_visibility(FollowedByType::No)?;
699699
let defaultness = self.parse_defaultness();
700700
let (name, kind, generics) = if self.eat_keyword(kw::Type) {
701-
self.parse_impl_assoc_ty()?
701+
self.parse_assoc_ty()?
702702
} else if self.is_const_item() {
703703
self.parse_assoc_const()?
704704
} else if let Some(mac) = self.parse_assoc_macro_invoc("impl", Some(&vis), at_end)? {
@@ -750,31 +750,6 @@ impl<'a> Parser<'a> {
750750
!self.is_keyword_ahead(1, &[kw::Fn, kw::Unsafe])
751751
}
752752

753-
/// Parses the following grammar:
754-
///
755-
/// AssocTy = Ident ["<"...">"] [":" [GenericBounds]] ["where" ...] ["=" Ty]
756-
fn parse_impl_assoc_ty(&mut self) -> PResult<'a, (Ident, ImplItemKind, Generics)> {
757-
let ident = self.parse_ident()?;
758-
let mut generics = self.parse_generics()?;
759-
760-
// Parse optional colon and param bounds.
761-
let bounds = if self.eat(&token::Colon) {
762-
self.parse_generic_bounds(None)?
763-
} else {
764-
Vec::new()
765-
};
766-
generics.where_clause = self.parse_where_clause()?;
767-
768-
let default = if self.eat(&token::Eq) {
769-
Some(self.parse_ty()?)
770-
} else {
771-
None
772-
};
773-
self.expect_semi()?;
774-
775-
Ok((ident, ImplItemKind::TyAlias(bounds, default), generics))
776-
}
777-
778753
/// Parses `auto? trait Foo { ... }` or `trait Foo = Bar;`.
779754
fn parse_item_trait(&mut self, lo: Span, unsafety: Unsafety) -> PResult<'a, ItemInfo> {
780755
// Parse optional `auto` prefix.
@@ -894,7 +869,7 @@ impl<'a> Parser<'a> {
894869
let vis = self.parse_visibility(FollowedByType::No)?;
895870
let defaultness = self.parse_defaultness();
896871
let (name, kind, generics) = if self.eat_keyword(kw::Type) {
897-
self.parse_trait_item_assoc_ty()?
872+
self.parse_assoc_ty()?
898873
} else if self.is_const_item() {
899874
self.parse_assoc_const()?
900875
} else if let Some(mac) = self.parse_assoc_macro_invoc("trait", None, &mut false)? {
@@ -937,7 +912,7 @@ impl<'a> Parser<'a> {
937912
/// Parses the following grammar:
938913
///
939914
/// AssocTy = Ident ["<"...">"] [":" [GenericBounds]] ["where" ...] ["=" Ty]
940-
fn parse_trait_item_assoc_ty(&mut self) -> PResult<'a, (Ident, TraitItemKind, Generics)> {
915+
fn parse_assoc_ty(&mut self) -> PResult<'a, (Ident, AssocItemKind, Generics)> {
941916
let ident = self.parse_ident()?;
942917
let mut generics = self.parse_generics()?;
943918

@@ -956,7 +931,7 @@ impl<'a> Parser<'a> {
956931
};
957932
self.expect_semi()?;
958933

959-
Ok((ident, TraitItemKind::TyAlias(bounds, default), generics))
934+
Ok((ident, AssocItemKind::TyAlias(bounds, default), generics))
960935
}
961936

962937
/// Parses a `UseTree`.

0 commit comments

Comments
 (0)