Skip to content

Commit

Permalink
Use named fields for hir::ItemKind::Impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Jan 18, 2020
1 parent d461e6d commit 4743995
Show file tree
Hide file tree
Showing 33 changed files with 166 additions and 161 deletions.
4 changes: 2 additions & 2 deletions src/librustc/hir/check_attr.rs
Expand Up @@ -112,7 +112,7 @@ impl Target {
ItemKind::Union(..) => Target::Union,
ItemKind::Trait(..) => Target::Trait,
ItemKind::TraitAlias(..) => Target::TraitAlias,
ItemKind::Impl(..) => Target::Impl,
ItemKind::Impl { .. } => Target::Impl,
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@ impl Target {
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id);
let containing_item = tcx.hir().expect_item(parent_hir_id);
let containing_impl_is_for_trait = match &containing_item.kind {
hir::ItemKind::Impl(_, _, _, _, tr, _, _) => tr.is_some(),
hir::ItemKind::Impl { ref of_trait, .. } => of_trait.is_some(),
_ => bug!("parent of an ImplItem must be an Impl"),
};
if containing_impl_is_for_trait {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -341,7 +341,7 @@ impl<'hir> Map<'hir> {
| ItemKind::Use(..)
| ItemKind::ForeignMod(..)
| ItemKind::GlobalAsm(..)
| ItemKind::Impl(..) => return None,
| ItemKind::Impl { .. } => return None,
},
Node::ForeignItem(item) => match item.kind {
ForeignItemKind::Fn(..) => DefKind::Fn,
Expand Down Expand Up @@ -604,7 +604,7 @@ impl<'hir> Map<'hir> {
| ItemKind::Union(_, ref generics)
| ItemKind::Trait(_, _, ref generics, ..)
| ItemKind::TraitAlias(ref generics, _)
| ItemKind::Impl(_, _, _, ref generics, ..) => Some(generics),
| ItemKind::Impl { ref generics, .. } => Some(generics),
_ => None,
},
_ => None,
Expand Down Expand Up @@ -1332,7 +1332,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Impl(..) => "impl",
ItemKind::Impl { .. } => "impl",
};
format!("{} {}{}", item_str, path_str(), id_str)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Expand Up @@ -254,7 +254,7 @@ fn emit_msg_span(

fn item_scope_tag(item: &hir::Item<'_>) -> &'static str {
match item.kind {
hir::ItemKind::Impl(..) => "impl",
hir::ItemKind::Impl { .. } => "impl",
hir::ItemKind::Struct(..) => "struct",
hir::ItemKind::Union(..) => "union",
hir::ItemKind::Enum(..) => "enum",
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/traits/error_reporting/suggestions.rs
Expand Up @@ -88,8 +88,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
..
})
| hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(_, _, _, generics, ..),
..
kind: hir::ItemKind::Impl { generics, .. }, ..
}) if projection.is_some() => {
// Missing associated type bound.
suggest_restriction(&generics, "the associated type", err);
Expand All @@ -115,7 +114,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
..
})
| hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(_, _, _, generics, ..),
kind: hir::ItemKind::Impl { generics, .. },
span,
..
})
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/util.rs
Expand Up @@ -651,7 +651,7 @@ pub fn impl_is_default(tcx: TyCtxt<'_>, node_item_def_id: DefId) -> bool {
match tcx.hir().as_local_hir_id(node_item_def_id) {
Some(hir_id) => {
let item = tcx.hir().expect_item(hir_id);
if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.kind {
if let hir::ItemKind::Impl { defaultness, .. } = item.kind {
defaultness.is_default()
} else {
false
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/traits/wf.rs
Expand Up @@ -229,9 +229,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
// |
// = note: expected type `u32`
// found type `()`
if let Some(hir::ItemKind::Impl(.., impl_items)) = item.map(|i| &i.kind) {
if let Some(hir::ItemKind::Impl { items, .. }) = item.map(|i| &i.kind) {
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
if let Some(impl_item) = impl_items
if let Some(impl_item) = items
.iter()
.filter(|item| item.ident == trait_assoc_item.ident)
.next()
Expand Down Expand Up @@ -279,14 +279,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
// | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
if let (
ty::Projection(ty::ProjectionTy { item_def_id, .. }),
Some(hir::ItemKind::Impl(.., impl_items)),
Some(hir::ItemKind::Impl { items, .. }),
) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind))
{
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
.filter(|i| i.def_id == *item_def_id)
.next()
.and_then(|trait_assoc_item| {
impl_items
items
.iter()
.filter(|i| i.ident == trait_assoc_item.ident)
.next()
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_ast_lowering/item.rs
Expand Up @@ -119,7 +119,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let old_len = self.in_scope_lifetimes.len();

let parent_generics = match self.items.get(&parent_hir_id).unwrap().kind {
hir::ItemKind::Impl(_, _, _, ref generics, ..)
hir::ItemKind::Impl { ref generics, .. }
| hir::ItemKind::Trait(_, _, ref generics, ..) => &generics.params[..],
_ => &[],
};
Expand Down Expand Up @@ -418,15 +418,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
)
});

hir::ItemKind::Impl(
hir::ItemKind::Impl {
unsafety,
polarity,
self.lower_defaultness(defaultness, true /* [1] */),
defaultness: self.lower_defaultness(defaultness, true /* [1] */),
generics,
trait_ref,
lowered_ty,
new_impl_items,
)
of_trait: trait_ref,
self_ty: lowered_ty,
items: new_impl_items,
}
}
ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref items) => {
let bounds = self.lower_param_bounds(bounds, ImplTraitContext::disallowed());
Expand Down
25 changes: 14 additions & 11 deletions src/librustc_hir/hir.rs
Expand Up @@ -2436,15 +2436,18 @@ pub enum ItemKind<'hir> {
TraitAlias(Generics<'hir>, GenericBounds<'hir>),

/// An implementation, e.g., `impl<A> Trait for Foo { .. }`.
Impl(
Unsafety,
ImplPolarity,
Defaultness,
Generics<'hir>,
Option<TraitRef<'hir>>, // (optional) trait this impl implements
&'hir Ty<'hir>, // self
&'hir [ImplItemRef<'hir>],
),
Impl {
unsafety: Unsafety,
polarity: ImplPolarity,
defaultness: Defaultness,
generics: Generics<'hir>,

/// The trait being implemented, if any.
of_trait: Option<TraitRef<'hir>>,

self_ty: &'hir Ty<'hir>,
items: &'hir [ImplItemRef<'hir>],
},
}

impl ItemKind<'_> {
Expand All @@ -2465,7 +2468,7 @@ impl ItemKind<'_> {
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Impl(..) => "impl",
ItemKind::Impl { .. } => "impl",
}
}

Expand All @@ -2478,7 +2481,7 @@ impl ItemKind<'_> {
| ItemKind::Struct(_, ref generics)
| ItemKind::Union(_, ref generics)
| ItemKind::Trait(_, _, ref generics, _, _)
| ItemKind::Impl(_, _, _, ref generics, _, _, _) => generics,
| ItemKind::Impl { ref generics, .. } => generics,
_ => return None,
})
}
Expand Down
16 changes: 12 additions & 4 deletions src/librustc_hir/intravisit.rs
Expand Up @@ -566,12 +566,20 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
// `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
visitor.visit_enum_def(enum_definition, generics, item.hir_id, item.span)
}
ItemKind::Impl(.., ref generics, ref opt_trait_reference, ref typ, impl_item_refs) => {
ItemKind::Impl {
unsafety: _,
defaultness: _,
polarity: _,
ref generics,
ref of_trait,
ref self_ty,
items,
} => {
visitor.visit_id(item.hir_id);
visitor.visit_generics(generics);
walk_list!(visitor, visit_trait_ref, opt_trait_reference);
visitor.visit_ty(typ);
walk_list!(visitor, visit_impl_item_ref, impl_item_refs);
walk_list!(visitor, visit_trait_ref, of_trait);
visitor.visit_ty(self_ty);
walk_list!(visitor, visit_impl_item_ref, items);
}
ItemKind::Struct(ref struct_definition, ref generics)
| ItemKind::Union(ref struct_definition, ref generics) => {
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_hir/print.rs
Expand Up @@ -627,15 +627,15 @@ impl<'a> State<'a> {
self.head(visibility_qualified(&item.vis, "union"));
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
}
hir::ItemKind::Impl(
hir::ItemKind::Impl {
unsafety,
polarity,
defaultness,
ref generics,
ref opt_trait,
ref ty,
impl_items,
) => {
ref of_trait,
ref self_ty,
items,
} => {
self.head("");
self.print_visibility(&item.vis);
self.print_defaultness(defaultness);
Expand All @@ -651,19 +651,19 @@ impl<'a> State<'a> {
self.s.word("!");
}

if let Some(ref t) = opt_trait {
if let Some(ref t) = of_trait {
self.print_trait_ref(t);
self.s.space();
self.word_space("for");
}

self.print_type(&ty);
self.print_type(&self_ty);
self.print_where_clause(&generics.where_clause);

self.s.space();
self.bopen();
self.print_inner_attributes(&item.attrs);
for impl_item in impl_items {
for impl_item in items {
self.ann.nested(self, Nested::ImplItem(impl_item.id));
}
self.bclose(item.span);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/dirty_clean.rs
Expand Up @@ -315,7 +315,7 @@ impl DirtyCleanVisitor<'tcx> {
//HirItem::Trait(..) => ("ItemTrait", LABELS_TRAIT),

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

_ => self.tcx.sess.span_fatal(
attr.span,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_lint/builtin.rs
Expand Up @@ -431,15 +431,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
"a trait"
}
hir::ItemKind::TyAlias(..) => "a type alias",
hir::ItemKind::Impl(.., Some(ref trait_ref), _, impl_item_refs) => {
hir::ItemKind::Impl { of_trait: Some(ref trait_ref), items, .. } => {
// If the trait is private, add the impl items to `private_traits` so they don't get
// reported for missing docs.
let real_trait = trait_ref.path.res.def_id();
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(real_trait) {
match cx.tcx.hir().find(hir_id) {
Some(Node::Item(item)) => {
if let hir::VisibilityKind::Inherited = item.vis.node {
for impl_item_ref in impl_item_refs {
for impl_item_ref in items {
self.private_traits.insert(impl_item_ref.id.hir_id);
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_metadata/rmeta/encoder.rs
Expand Up @@ -1073,7 +1073,7 @@ impl EncodeContext<'tcx> {
ctor: None,
}), adt_def.repr)
}
hir::ItemKind::Impl(_, _, defaultness, ..) => {
hir::ItemKind::Impl { defaultness, .. } => {
let trait_ref = self.tcx.impl_trait_ref(def_id);
let polarity = self.tcx.impl_polarity(def_id);
let parent = if let Some(trait_ref) = trait_ref {
Expand Down Expand Up @@ -1149,7 +1149,7 @@ impl EncodeContext<'tcx> {
})
)
}
hir::ItemKind::Impl(..) | hir::ItemKind::Trait(..) => {
hir::ItemKind::Impl { .. } | hir::ItemKind::Trait(..) => {
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
record!(self.per_def.children[def_id] <-
associated_item_def_ids.iter().map(|&def_id| {
Expand All @@ -1172,13 +1172,13 @@ impl EncodeContext<'tcx> {
| hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..)
| hir::ItemKind::Impl(..) => self.encode_item_type(def_id),
| hir::ItemKind::Impl { .. } => self.encode_item_type(def_id),
_ => {}
}
if let hir::ItemKind::Fn(..) = item.kind {
record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id));
}
if let hir::ItemKind::Impl(..) = item.kind {
if let hir::ItemKind::Impl { .. } = item.kind {
if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) {
record!(self.per_def.impl_trait_ref[def_id] <- trait_ref);
}
Expand All @@ -1199,7 +1199,7 @@ impl EncodeContext<'tcx> {
| hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..)
| hir::ItemKind::Impl(..)
| hir::ItemKind::Impl { .. }
| hir::ItemKind::OpaqueTy(..)
| hir::ItemKind::Trait(..)
| hir::ItemKind::TraitAlias(..) => {
Expand Down Expand Up @@ -1645,7 +1645,7 @@ impl EncodeContext<'tcx> {
hir::ItemKind::Union(..) => {
self.encode_fields(def_id);
}
hir::ItemKind::Impl(..) => {
hir::ItemKind::Impl { .. } => {
for &trait_item_def_id in self.tcx.associated_item_def_ids(def_id).iter() {
self.encode_info_for_impl_item(trait_item_def_id);
}
Expand All @@ -1666,7 +1666,7 @@ struct ImplVisitor<'tcx> {

impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
if let hir::ItemKind::Impl(..) = item.kind {
if let hir::ItemKind::Impl { .. } = item.kind {
let impl_id = self.tcx.hir().local_def_id(item.hir_id);
if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_id) {
self.impls.entry(trait_ref.def_id).or_default().push(impl_id.index);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/monomorphize/collector.rs
Expand Up @@ -954,7 +954,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
// Nothing to do, just keep recursing.
}

hir::ItemKind::Impl(..) => {
hir::ItemKind::Impl { .. } => {
if self.mode == MonoItemCollectionMode::Eager {
create_mono_items_for_default_impls(self.tcx, item, self.output);
}
Expand Down Expand Up @@ -1098,7 +1098,7 @@ fn create_mono_items_for_default_impls<'tcx>(
output: &mut Vec<MonoItem<'tcx>>,
) {
match item.kind {
hir::ItemKind::Impl(_, _, _, ref generics, .., ref impl_item_refs) => {
hir::ItemKind::Impl { ref generics, ref items, .. } => {
for param in generics.params {
match param.kind {
hir::GenericParamKind::Lifetime { .. } => {}
Expand All @@ -1119,7 +1119,7 @@ fn create_mono_items_for_default_impls<'tcx>(
let param_env = ty::ParamEnv::reveal_all();
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
let overridden_methods: FxHashSet<_> =
impl_item_refs.iter().map(|iiref| iiref.ident.modern()).collect();
items.iter().map(|iiref| iiref.ident.modern()).collect();
for method in tcx.provided_trait_methods(trait_ref.def_id) {
if overridden_methods.contains(&method.ident.modern()) {
continue;
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_passes/dead.rs
Expand Up @@ -405,10 +405,10 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
}
}
}
hir::ItemKind::Impl(.., ref opt_trait, _, impl_item_refs) => {
for impl_item_ref in impl_item_refs {
hir::ItemKind::Impl { ref of_trait, items, .. } => {
for impl_item_ref in items {
let impl_item = self.krate.impl_item(impl_item_ref.id);
if opt_trait.is_some()
if of_trait.is_some()
|| has_allow_dead_code_or_lang_attr(
self.tcx,
impl_item.hir_id,
Expand Down Expand Up @@ -586,7 +586,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..)
| hir::ItemKind::Trait(..)
| hir::ItemKind::Impl(..) => {
| hir::ItemKind::Impl { .. } => {
// FIXME(66095): Because item.span is annotated with things
// like expansion data, and ident.span isn't, we use the
// def_span method if it's part of a macro invocation
Expand Down

0 comments on commit 4743995

Please sign in to comment.