Skip to content

Commit 34dbc22

Browse files
authored
Unrolled build for rust-lang#138376
Rollup merge of rust-lang#138376 - nnethercote:hir-ItemKind-ident-precursors, r=compiler-errors Item-related cleanups I have been looking at `hir::Item` closely and found a few minor cleanup opportunities. r? ```@spastorino```
2 parents a21d978 + ee9ef82 commit 34dbc22

File tree

3 files changed

+24
-56
lines changed

3 files changed

+24
-56
lines changed

compiler/rustc_hir/src/hir.rs

-10
Original file line numberDiff line numberDiff line change
@@ -4332,16 +4332,6 @@ pub enum OwnerNode<'hir> {
43324332
}
43334333

43344334
impl<'hir> OwnerNode<'hir> {
4335-
pub fn ident(&self) -> Option<Ident> {
4336-
match self {
4337-
OwnerNode::Item(Item { ident, .. })
4338-
| OwnerNode::ForeignItem(ForeignItem { ident, .. })
4339-
| OwnerNode::ImplItem(ImplItem { ident, .. })
4340-
| OwnerNode::TraitItem(TraitItem { ident, .. }) => Some(*ident),
4341-
OwnerNode::Crate(..) | OwnerNode::Synthetic => None,
4342-
}
4343-
}
4344-
43454335
pub fn span(&self) -> Span {
43464336
match self {
43474337
OwnerNode::Item(Item { span, .. })

compiler/rustc_hir_pretty/src/lib.rs

+11-22
Original file line numberDiff line numberDiff line change
@@ -553,24 +553,6 @@ impl<'a> State<'a> {
553553
self.word(";")
554554
}
555555

556-
fn print_item_type(
557-
&mut self,
558-
item: &hir::Item<'_>,
559-
generics: &hir::Generics<'_>,
560-
inner: impl Fn(&mut Self),
561-
) {
562-
self.head("type");
563-
self.print_ident(item.ident);
564-
self.print_generic_params(generics.params);
565-
self.end(); // end the inner ibox
566-
567-
self.print_where_clause(generics);
568-
self.space();
569-
inner(self);
570-
self.word(";");
571-
self.end(); // end the outer ibox
572-
}
573-
574556
fn print_item(&mut self, item: &hir::Item<'_>) {
575557
self.hardbreak_if_not_bol();
576558
self.maybe_print_comment(item.span.lo());
@@ -683,10 +665,17 @@ impl<'a> State<'a> {
683665
self.end()
684666
}
685667
hir::ItemKind::TyAlias(ty, generics) => {
686-
self.print_item_type(item, generics, |state| {
687-
state.word_space("=");
688-
state.print_type(ty);
689-
});
668+
self.head("type");
669+
self.print_ident(item.ident);
670+
self.print_generic_params(generics.params);
671+
self.end(); // end the inner ibox
672+
673+
self.print_where_clause(generics);
674+
self.space();
675+
self.word_space("=");
676+
self.print_type(ty);
677+
self.word(";");
678+
self.end(); // end the outer ibox
690679
}
691680
hir::ItemKind::Enum(ref enum_definition, params) => {
692681
self.print_enum_def(enum_definition, params, item.ident.name, item.span);

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)