Skip to content

Commit 4743995

Browse files
committedJan 18, 2020
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

+2-2
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

+3-3
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

+1-1
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

+2-3
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

+1-1
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

+4-4
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

+7-7
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

+14-11
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

+12-4
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

+8-8
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);

‎src/librustc_incremental/persist/dirty_clean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl DirtyCleanVisitor<'tcx> {
315315
//HirItem::Trait(..) => ("ItemTrait", LABELS_TRAIT),
316316

317317
// An implementation, eg `impl<A> Trait for Foo { .. }`
318-
HirItem::Impl(..) => ("ItemKind::Impl", LABELS_IMPL),
318+
HirItem::Impl { .. } => ("ItemKind::Impl", LABELS_IMPL),
319319

320320
_ => self.tcx.sess.span_fatal(
321321
attr.span,

‎src/librustc_lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
431431
"a trait"
432432
}
433433
hir::ItemKind::TyAlias(..) => "a type alias",
434-
hir::ItemKind::Impl(.., Some(ref trait_ref), _, impl_item_refs) => {
434+
hir::ItemKind::Impl { of_trait: Some(ref trait_ref), items, .. } => {
435435
// If the trait is private, add the impl items to `private_traits` so they don't get
436436
// reported for missing docs.
437437
let real_trait = trait_ref.path.res.def_id();
438438
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(real_trait) {
439439
match cx.tcx.hir().find(hir_id) {
440440
Some(Node::Item(item)) => {
441441
if let hir::VisibilityKind::Inherited = item.vis.node {
442-
for impl_item_ref in impl_item_refs {
442+
for impl_item_ref in items {
443443
self.private_traits.insert(impl_item_ref.id.hir_id);
444444
}
445445
}

‎src/librustc_metadata/rmeta/encoder.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ impl EncodeContext<'tcx> {
10731073
ctor: None,
10741074
}), adt_def.repr)
10751075
}
1076-
hir::ItemKind::Impl(_, _, defaultness, ..) => {
1076+
hir::ItemKind::Impl { defaultness, .. } => {
10771077
let trait_ref = self.tcx.impl_trait_ref(def_id);
10781078
let polarity = self.tcx.impl_polarity(def_id);
10791079
let parent = if let Some(trait_ref) = trait_ref {
@@ -1149,7 +1149,7 @@ impl EncodeContext<'tcx> {
11491149
})
11501150
)
11511151
}
1152-
hir::ItemKind::Impl(..) | hir::ItemKind::Trait(..) => {
1152+
hir::ItemKind::Impl { .. } | hir::ItemKind::Trait(..) => {
11531153
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
11541154
record!(self.per_def.children[def_id] <-
11551155
associated_item_def_ids.iter().map(|&def_id| {
@@ -1172,13 +1172,13 @@ impl EncodeContext<'tcx> {
11721172
| hir::ItemKind::Enum(..)
11731173
| hir::ItemKind::Struct(..)
11741174
| hir::ItemKind::Union(..)
1175-
| hir::ItemKind::Impl(..) => self.encode_item_type(def_id),
1175+
| hir::ItemKind::Impl { .. } => self.encode_item_type(def_id),
11761176
_ => {}
11771177
}
11781178
if let hir::ItemKind::Fn(..) = item.kind {
11791179
record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id));
11801180
}
1181-
if let hir::ItemKind::Impl(..) = item.kind {
1181+
if let hir::ItemKind::Impl { .. } = item.kind {
11821182
if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) {
11831183
record!(self.per_def.impl_trait_ref[def_id] <- trait_ref);
11841184
}
@@ -1199,7 +1199,7 @@ impl EncodeContext<'tcx> {
11991199
| hir::ItemKind::Enum(..)
12001200
| hir::ItemKind::Struct(..)
12011201
| hir::ItemKind::Union(..)
1202-
| hir::ItemKind::Impl(..)
1202+
| hir::ItemKind::Impl { .. }
12031203
| hir::ItemKind::OpaqueTy(..)
12041204
| hir::ItemKind::Trait(..)
12051205
| hir::ItemKind::TraitAlias(..) => {
@@ -1645,7 +1645,7 @@ impl EncodeContext<'tcx> {
16451645
hir::ItemKind::Union(..) => {
16461646
self.encode_fields(def_id);
16471647
}
1648-
hir::ItemKind::Impl(..) => {
1648+
hir::ItemKind::Impl { .. } => {
16491649
for &trait_item_def_id in self.tcx.associated_item_def_ids(def_id).iter() {
16501650
self.encode_info_for_impl_item(trait_item_def_id);
16511651
}
@@ -1666,7 +1666,7 @@ struct ImplVisitor<'tcx> {
16661666

16671667
impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> {
16681668
fn visit_item(&mut self, item: &hir::Item<'_>) {
1669-
if let hir::ItemKind::Impl(..) = item.kind {
1669+
if let hir::ItemKind::Impl { .. } = item.kind {
16701670
let impl_id = self.tcx.hir().local_def_id(item.hir_id);
16711671
if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_id) {
16721672
self.impls.entry(trait_ref.def_id).or_default().push(impl_id.index);

‎src/librustc_mir/monomorphize/collector.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
954954
// Nothing to do, just keep recursing.
955955
}
956956

957-
hir::ItemKind::Impl(..) => {
957+
hir::ItemKind::Impl { .. } => {
958958
if self.mode == MonoItemCollectionMode::Eager {
959959
create_mono_items_for_default_impls(self.tcx, item, self.output);
960960
}
@@ -1098,7 +1098,7 @@ fn create_mono_items_for_default_impls<'tcx>(
10981098
output: &mut Vec<MonoItem<'tcx>>,
10991099
) {
11001100
match item.kind {
1101-
hir::ItemKind::Impl(_, _, _, ref generics, .., ref impl_item_refs) => {
1101+
hir::ItemKind::Impl { ref generics, ref items, .. } => {
11021102
for param in generics.params {
11031103
match param.kind {
11041104
hir::GenericParamKind::Lifetime { .. } => {}
@@ -1119,7 +1119,7 @@ fn create_mono_items_for_default_impls<'tcx>(
11191119
let param_env = ty::ParamEnv::reveal_all();
11201120
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
11211121
let overridden_methods: FxHashSet<_> =
1122-
impl_item_refs.iter().map(|iiref| iiref.ident.modern()).collect();
1122+
items.iter().map(|iiref| iiref.ident.modern()).collect();
11231123
for method in tcx.provided_trait_methods(trait_ref.def_id) {
11241124
if overridden_methods.contains(&method.ident.modern()) {
11251125
continue;

‎src/librustc_passes/dead.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,10 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
405405
}
406406
}
407407
}
408-
hir::ItemKind::Impl(.., ref opt_trait, _, impl_item_refs) => {
409-
for impl_item_ref in impl_item_refs {
408+
hir::ItemKind::Impl { ref of_trait, items, .. } => {
409+
for impl_item_ref in items {
410410
let impl_item = self.krate.impl_item(impl_item_ref.id);
411-
if opt_trait.is_some()
411+
if of_trait.is_some()
412412
|| has_allow_dead_code_or_lang_attr(
413413
self.tcx,
414414
impl_item.hir_id,
@@ -586,7 +586,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
586586
| hir::ItemKind::Struct(..)
587587
| hir::ItemKind::Union(..)
588588
| hir::ItemKind::Trait(..)
589-
| hir::ItemKind::Impl(..) => {
589+
| hir::ItemKind::Impl { .. } => {
590590
// FIXME(66095): Because item.span is annotated with things
591591
// like expansion data, and ident.span isn't, we use the
592592
// def_span method if it's part of a macro invocation

0 commit comments

Comments
 (0)