Skip to content

Commit 4743995

Browse files
Use named fields for hir::ItemKind::Impl
1 parent d461e6d commit 4743995

File tree

33 files changed

+166
-161
lines changed

33 files changed

+166
-161
lines changed

src/librustc/hir/check_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Target {
112112
ItemKind::Union(..) => Target::Union,
113113
ItemKind::Trait(..) => Target::Trait,
114114
ItemKind::TraitAlias(..) => Target::TraitAlias,
115-
ItemKind::Impl(..) => Target::Impl,
115+
ItemKind::Impl { .. } => Target::Impl,
116116
}
117117
}
118118

@@ -144,7 +144,7 @@ impl Target {
144144
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id);
145145
let containing_item = tcx.hir().expect_item(parent_hir_id);
146146
let containing_impl_is_for_trait = match &containing_item.kind {
147-
hir::ItemKind::Impl(_, _, _, _, tr, _, _) => tr.is_some(),
147+
hir::ItemKind::Impl { ref of_trait, .. } => of_trait.is_some(),
148148
_ => bug!("parent of an ImplItem must be an Impl"),
149149
};
150150
if containing_impl_is_for_trait {

src/librustc/hir/map/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'hir> Map<'hir> {
341341
| ItemKind::Use(..)
342342
| ItemKind::ForeignMod(..)
343343
| ItemKind::GlobalAsm(..)
344-
| ItemKind::Impl(..) => return None,
344+
| ItemKind::Impl { .. } => return None,
345345
},
346346
Node::ForeignItem(item) => match item.kind {
347347
ForeignItemKind::Fn(..) => DefKind::Fn,
@@ -604,7 +604,7 @@ impl<'hir> Map<'hir> {
604604
| ItemKind::Union(_, ref generics)
605605
| ItemKind::Trait(_, _, ref generics, ..)
606606
| ItemKind::TraitAlias(ref generics, _)
607-
| ItemKind::Impl(_, _, _, ref generics, ..) => Some(generics),
607+
| ItemKind::Impl { ref generics, .. } => Some(generics),
608608
_ => None,
609609
},
610610
_ => None,
@@ -1332,7 +1332,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
13321332
ItemKind::Union(..) => "union",
13331333
ItemKind::Trait(..) => "trait",
13341334
ItemKind::TraitAlias(..) => "trait alias",
1335-
ItemKind::Impl(..) => "impl",
1335+
ItemKind::Impl { .. } => "impl",
13361336
};
13371337
format!("{} {}{}", item_str, path_str(), id_str)
13381338
}

src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ fn emit_msg_span(
254254

255255
fn item_scope_tag(item: &hir::Item<'_>) -> &'static str {
256256
match item.kind {
257-
hir::ItemKind::Impl(..) => "impl",
257+
hir::ItemKind::Impl { .. } => "impl",
258258
hir::ItemKind::Struct(..) => "struct",
259259
hir::ItemKind::Union(..) => "union",
260260
hir::ItemKind::Enum(..) => "enum",

src/librustc/traits/error_reporting/suggestions.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
8888
..
8989
})
9090
| hir::Node::Item(hir::Item {
91-
kind: hir::ItemKind::Impl(_, _, _, generics, ..),
92-
..
91+
kind: hir::ItemKind::Impl { generics, .. }, ..
9392
}) if projection.is_some() => {
9493
// Missing associated type bound.
9594
suggest_restriction(&generics, "the associated type", err);
@@ -115,7 +114,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
115114
..
116115
})
117116
| hir::Node::Item(hir::Item {
118-
kind: hir::ItemKind::Impl(_, _, _, generics, ..),
117+
kind: hir::ItemKind::Impl { generics, .. },
119118
span,
120119
..
121120
})

src/librustc/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ pub fn impl_is_default(tcx: TyCtxt<'_>, node_item_def_id: DefId) -> bool {
651651
match tcx.hir().as_local_hir_id(node_item_def_id) {
652652
Some(hir_id) => {
653653
let item = tcx.hir().expect_item(hir_id);
654-
if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.kind {
654+
if let hir::ItemKind::Impl { defaultness, .. } = item.kind {
655655
defaultness.is_default()
656656
} else {
657657
false

src/librustc/traits/wf.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
229229
// |
230230
// = note: expected type `u32`
231231
// found type `()`
232-
if let Some(hir::ItemKind::Impl(.., impl_items)) = item.map(|i| &i.kind) {
232+
if let Some(hir::ItemKind::Impl { items, .. }) = item.map(|i| &i.kind) {
233233
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
234-
if let Some(impl_item) = impl_items
234+
if let Some(impl_item) = items
235235
.iter()
236236
.filter(|item| item.ident == trait_assoc_item.ident)
237237
.next()
@@ -279,14 +279,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
279279
// | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
280280
if let (
281281
ty::Projection(ty::ProjectionTy { item_def_id, .. }),
282-
Some(hir::ItemKind::Impl(.., impl_items)),
282+
Some(hir::ItemKind::Impl { items, .. }),
283283
) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind))
284284
{
285285
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
286286
.filter(|i| i.def_id == *item_def_id)
287287
.next()
288288
.and_then(|trait_assoc_item| {
289-
impl_items
289+
items
290290
.iter()
291291
.filter(|i| i.ident == trait_assoc_item.ident)
292292
.next()

src/librustc_ast_lowering/item.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
119119
let old_len = self.in_scope_lifetimes.len();
120120

121121
let parent_generics = match self.items.get(&parent_hir_id).unwrap().kind {
122-
hir::ItemKind::Impl(_, _, _, ref generics, ..)
122+
hir::ItemKind::Impl { ref generics, .. }
123123
| hir::ItemKind::Trait(_, _, ref generics, ..) => &generics.params[..],
124124
_ => &[],
125125
};
@@ -418,15 +418,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
418418
)
419419
});
420420

421-
hir::ItemKind::Impl(
421+
hir::ItemKind::Impl {
422422
unsafety,
423423
polarity,
424-
self.lower_defaultness(defaultness, true /* [1] */),
424+
defaultness: self.lower_defaultness(defaultness, true /* [1] */),
425425
generics,
426-
trait_ref,
427-
lowered_ty,
428-
new_impl_items,
429-
)
426+
of_trait: trait_ref,
427+
self_ty: lowered_ty,
428+
items: new_impl_items,
429+
}
430430
}
431431
ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref items) => {
432432
let bounds = self.lower_param_bounds(bounds, ImplTraitContext::disallowed());

src/librustc_hir/hir.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,15 +2436,18 @@ pub enum ItemKind<'hir> {
24362436
TraitAlias(Generics<'hir>, GenericBounds<'hir>),
24372437

24382438
/// An implementation, e.g., `impl<A> Trait for Foo { .. }`.
2439-
Impl(
2440-
Unsafety,
2441-
ImplPolarity,
2442-
Defaultness,
2443-
Generics<'hir>,
2444-
Option<TraitRef<'hir>>, // (optional) trait this impl implements
2445-
&'hir Ty<'hir>, // self
2446-
&'hir [ImplItemRef<'hir>],
2447-
),
2439+
Impl {
2440+
unsafety: Unsafety,
2441+
polarity: ImplPolarity,
2442+
defaultness: Defaultness,
2443+
generics: Generics<'hir>,
2444+
2445+
/// The trait being implemented, if any.
2446+
of_trait: Option<TraitRef<'hir>>,
2447+
2448+
self_ty: &'hir Ty<'hir>,
2449+
items: &'hir [ImplItemRef<'hir>],
2450+
},
24482451
}
24492452

24502453
impl ItemKind<'_> {
@@ -2465,7 +2468,7 @@ impl ItemKind<'_> {
24652468
ItemKind::Union(..) => "union",
24662469
ItemKind::Trait(..) => "trait",
24672470
ItemKind::TraitAlias(..) => "trait alias",
2468-
ItemKind::Impl(..) => "impl",
2471+
ItemKind::Impl { .. } => "impl",
24692472
}
24702473
}
24712474

@@ -2478,7 +2481,7 @@ impl ItemKind<'_> {
24782481
| ItemKind::Struct(_, ref generics)
24792482
| ItemKind::Union(_, ref generics)
24802483
| ItemKind::Trait(_, _, ref generics, _, _)
2481-
| ItemKind::Impl(_, _, _, ref generics, _, _, _) => generics,
2484+
| ItemKind::Impl { ref generics, .. } => generics,
24822485
_ => return None,
24832486
})
24842487
}

src/librustc_hir/intravisit.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,20 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
566566
// `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
567567
visitor.visit_enum_def(enum_definition, generics, item.hir_id, item.span)
568568
}
569-
ItemKind::Impl(.., ref generics, ref opt_trait_reference, ref typ, impl_item_refs) => {
569+
ItemKind::Impl {
570+
unsafety: _,
571+
defaultness: _,
572+
polarity: _,
573+
ref generics,
574+
ref of_trait,
575+
ref self_ty,
576+
items,
577+
} => {
570578
visitor.visit_id(item.hir_id);
571579
visitor.visit_generics(generics);
572-
walk_list!(visitor, visit_trait_ref, opt_trait_reference);
573-
visitor.visit_ty(typ);
574-
walk_list!(visitor, visit_impl_item_ref, impl_item_refs);
580+
walk_list!(visitor, visit_trait_ref, of_trait);
581+
visitor.visit_ty(self_ty);
582+
walk_list!(visitor, visit_impl_item_ref, items);
575583
}
576584
ItemKind::Struct(ref struct_definition, ref generics)
577585
| ItemKind::Union(ref struct_definition, ref generics) => {

src/librustc_hir/print.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -627,15 +627,15 @@ impl<'a> State<'a> {
627627
self.head(visibility_qualified(&item.vis, "union"));
628628
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
629629
}
630-
hir::ItemKind::Impl(
630+
hir::ItemKind::Impl {
631631
unsafety,
632632
polarity,
633633
defaultness,
634634
ref generics,
635-
ref opt_trait,
636-
ref ty,
637-
impl_items,
638-
) => {
635+
ref of_trait,
636+
ref self_ty,
637+
items,
638+
} => {
639639
self.head("");
640640
self.print_visibility(&item.vis);
641641
self.print_defaultness(defaultness);
@@ -651,19 +651,19 @@ impl<'a> State<'a> {
651651
self.s.word("!");
652652
}
653653

654-
if let Some(ref t) = opt_trait {
654+
if let Some(ref t) = of_trait {
655655
self.print_trait_ref(t);
656656
self.s.space();
657657
self.word_space("for");
658658
}
659659

660-
self.print_type(&ty);
660+
self.print_type(&self_ty);
661661
self.print_where_clause(&generics.where_clause);
662662

663663
self.s.space();
664664
self.bopen();
665665
self.print_inner_attributes(&item.attrs);
666-
for impl_item in impl_items {
666+
for impl_item in items {
667667
self.ann.nested(self, Nested::ImplItem(impl_item.id));
668668
}
669669
self.bclose(item.span);

0 commit comments

Comments
 (0)