Skip to content

Commit ee9ef82

Browse files
committed
Factor out some repeated code in parse_item_impl.
1 parent ed10418 commit ee9ef82

File tree

1 file changed

+13
-24
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+13
-24
lines changed

compiler/rustc_parse/src/parser/item.rs

+13-24
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ impl<'a> Parser<'a> {
646646

647647
let impl_items = self.parse_item_list(attrs, |p| p.parse_impl_item(ForceCollect::No))?;
648648

649-
let item_kind = match ty_second {
649+
let (of_trait, self_ty) = match ty_second {
650650
Some(ty_second) => {
651651
// impl Trait for Type
652652
if !has_for {
@@ -679,31 +679,20 @@ impl<'a> Parser<'a> {
679679
};
680680
let trait_ref = TraitRef { path, ref_id: ty_first.id };
681681

682-
ItemKind::Impl(Box::new(Impl {
683-
safety,
684-
polarity,
685-
defaultness,
686-
constness,
687-
generics,
688-
of_trait: Some(trait_ref),
689-
self_ty: ty_second,
690-
items: impl_items,
691-
}))
692-
}
693-
None => {
694-
// impl Type
695-
ItemKind::Impl(Box::new(Impl {
696-
safety,
697-
polarity,
698-
defaultness,
699-
constness,
700-
generics,
701-
of_trait: None,
702-
self_ty: ty_first,
703-
items: impl_items,
704-
}))
682+
(Some(trait_ref), ty_second)
705683
}
684+
None => (None, ty_first), // impl Type
706685
};
686+
let item_kind = ItemKind::Impl(Box::new(Impl {
687+
safety,
688+
polarity,
689+
defaultness,
690+
constness,
691+
generics,
692+
of_trait,
693+
self_ty,
694+
items: impl_items,
695+
}));
707696

708697
Ok((Ident::empty(), item_kind))
709698
}

0 commit comments

Comments
 (0)