Use named fields for hir::ItemKind::Impl

This commit is contained in:
Dylan MacKenzie 2020-01-17 16:14:29 -08:00
parent d461e6d6cb
commit 4743995ed3
33 changed files with 166 additions and 161 deletions

View File

@ -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,
}
}
@ -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 {

View File

@ -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,
@ -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,
@ -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)
}

View File

@ -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",

View File

@ -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);
@ -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,
..
})

View File

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

View File

@ -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()
@ -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()

View File

@ -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[..],
_ => &[],
};
@ -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());

View File

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

View File

@ -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) => {

View File

@ -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);
@ -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);

View File

@ -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,

View File

@ -431,7 +431,7 @@ 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();
@ -439,7 +439,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
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);
}
}

View File

@ -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 {
@ -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| {
@ -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);
}
@ -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(..) => {
@ -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);
}
@ -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);

View File

@ -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);
}
@ -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 { .. } => {}
@ -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;

View File

@ -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,
@ -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

View File

@ -35,7 +35,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>, attrs: Codegen
hir::ItemKind::Fn(ref sig, ..) if sig.header.is_const() => {
return true;
}
hir::ItemKind::Impl(..) | hir::ItemKind::Fn(..) => {
hir::ItemKind::Impl { .. } | hir::ItemKind::Fn(..) => {
let generics = tcx.generics_of(tcx.hir().local_def_id(item.hir_id));
generics.requires_monomorphization(tcx)
}
@ -181,7 +181,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
// does too.
let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did).unwrap();
match self.tcx.hir().expect_item(impl_hir_id).kind {
hir::ItemKind::Impl(..) => {
hir::ItemKind::Impl { .. } => {
let generics = self.tcx.generics_of(impl_did);
generics.requires_monomorphization(self.tcx)
}
@ -266,7 +266,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
| hir::ItemKind::Static(..)
| hir::ItemKind::Mod(..)
| hir::ItemKind::ForeignMod(..)
| hir::ItemKind::Impl(..)
| hir::ItemKind::Impl { .. }
| hir::ItemKind::Trait(..)
| hir::ItemKind::TraitAlias(..)
| hir::ItemKind::Struct(..)
@ -349,9 +349,9 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
}
// We need only trait impls here, not inherent impls, and only non-exported ones
if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.kind {
if let hir::ItemKind::Impl { of_trait: Some(ref trait_ref), ref items, .. } = item.kind {
if !self.access_levels.is_reachable(item.hir_id) {
self.worklist.extend(impl_item_refs.iter().map(|ii_ref| ii_ref.id.hir_id));
self.worklist.extend(items.iter().map(|ii_ref| ii_ref.id.hir_id));
let trait_def_id = match trait_ref.path.res {
Res::Def(DefKind::Trait, def_id) => def_id,

View File

@ -219,11 +219,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
// they don't have their own stability. They still can be annotated as unstable
// and propagate this unstability to children, but this annotation is completely
// optional. They inherit stability from their parents when unannotated.
hir::ItemKind::Impl(.., None, _, _) | hir::ItemKind::ForeignMod(..) => {
hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod(..) => {
self.in_trait_impl = false;
kind = AnnotationKind::Container;
}
hir::ItemKind::Impl(.., Some(_), _, _) => {
hir::ItemKind::Impl { of_trait: Some(_), .. } => {
self.in_trait_impl = true;
}
hir::ItemKind::Struct(ref sd, _) => {
@ -308,7 +308,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
// they don't have their own stability. They still can be annotated as unstable
// and propagate this unstability to children, but this annotation is completely
// optional. They inherit stability from their parents when unannotated.
hir::ItemKind::Impl(.., None, _, _) | hir::ItemKind::ForeignMod(..) => {}
hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod(..) => {}
_ => self.check_missing_stability(i.hir_id, i.span, i.kind.descriptive_variant()),
}
@ -463,9 +463,9 @@ impl Visitor<'tcx> for Checker<'tcx> {
// For implementations of traits, check the stability of each item
// individually as it's possible to have a stable trait with unstable
// items.
hir::ItemKind::Impl(.., Some(ref t), _, impl_item_refs) => {
hir::ItemKind::Impl { of_trait: Some(ref t), items, .. } => {
if let Res::Def(DefKind::Trait, trait_did) = t.path.res {
for impl_item_ref in impl_item_refs {
for impl_item_ref in items {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
let trait_item_def_id = self
.tcx

View File

@ -255,8 +255,8 @@ fn def_id_visibility<'tcx>(
Node::ImplItem(impl_item) => {
match tcx.hir().get(tcx.hir().get_parent_item(hir_id)) {
Node::Item(item) => match &item.kind {
hir::ItemKind::Impl(.., None, _, _) => &impl_item.vis,
hir::ItemKind::Impl(.., Some(trait_ref), _, _) => {
hir::ItemKind::Impl { of_trait: None, .. } => &impl_item.vis,
hir::ItemKind::Impl { of_trait: Some(trait_ref), .. } => {
return def_id_visibility(tcx, trait_ref.path.res.def_id());
}
kind => bug!("unexpected item kind: {:?}", kind),
@ -686,7 +686,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let inherited_item_level = match item.kind {
hir::ItemKind::Impl(..) => {
hir::ItemKind::Impl { .. } => {
Option::<AccessLevel>::of_impl(item.hir_id, self.tcx, &self.access_levels)
}
// Foreign modules inherit level from parents.
@ -730,9 +730,9 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
}
}
}
hir::ItemKind::Impl(.., ref trait_ref, _, impl_item_refs) => {
for impl_item_ref in impl_item_refs {
if trait_ref.is_some() || impl_item_ref.vis.node.is_pub() {
hir::ItemKind::Impl { ref of_trait, items, .. } => {
for impl_item_ref in items {
if of_trait.is_some() || impl_item_ref.vis.node.is_pub() {
self.update(impl_item_ref.id.hir_id, item_level);
}
}
@ -827,11 +827,11 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
}
}
// Visit everything except for private impl items.
hir::ItemKind::Impl(.., impl_item_refs) => {
hir::ItemKind::Impl { items, .. } => {
if item_level.is_some() {
self.reach(item.hir_id, item_level).generics().predicates().ty().trait_ref();
for impl_item_ref in impl_item_refs {
for impl_item_ref in items {
let impl_item_level = self.get(impl_item_ref.id.hir_id);
if impl_item_level.is_some() {
self.reach(impl_item_ref.id.hir_id, impl_item_level)
@ -1510,7 +1510,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
// (i.e., we could just return here to not check them at
// all, or some worse estimation of whether an impl is
// publicly visible).
hir::ItemKind::Impl(.., ref g, ref trait_ref, ref self_, impl_item_refs) => {
hir::ItemKind::Impl { generics: ref g, ref of_trait, ref self_ty, items, .. } => {
// `impl [... for] Private` is never visible.
let self_contains_private;
// `impl [... for] Public<...>`, but not `impl [... for]
@ -1525,7 +1525,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
at_outer_type: true,
outer_type_is_public_path: false,
};
visitor.visit_ty(&self_);
visitor.visit_ty(&self_ty);
self_contains_private = visitor.contains_private;
self_is_public_path = visitor.outer_type_is_public_path;
}
@ -1533,7 +1533,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
// Miscellaneous info about the impl:
// `true` iff this is `impl Private for ...`.
let not_private_trait = trait_ref.as_ref().map_or(
let not_private_trait = of_trait.as_ref().map_or(
true, // no trait counts as public trait
|tr| {
let did = tr.path.res.def_id();
@ -1554,8 +1554,8 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
// directly because we might have `impl<T: Foo<Private>> ...`,
// and we shouldn't warn about the generics if all the methods
// are private (because `T` won't be visible externally).
let trait_or_some_public_method = trait_ref.is_some()
|| impl_item_refs.iter().any(|impl_item_ref| {
let trait_or_some_public_method = of_trait.is_some()
|| items.iter().any(|impl_item_ref| {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item.kind {
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Method(..) => {
@ -1570,9 +1570,9 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
if !self_contains_private && not_private_trait && trait_or_some_public_method {
intravisit::walk_generics(self, g);
match *trait_ref {
match of_trait {
None => {
for impl_item_ref in impl_item_refs {
for impl_item_ref in items {
// This is where we choose whether to walk down
// further into the impl to check its items. We
// should only walk into public items so that we
@ -1594,7 +1594,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
}
}
}
Some(ref tr) => {
Some(tr) => {
// Any private types in a trait impl fall into three
// categories.
// 1. mentioned in the trait definition
@ -1611,7 +1611,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
intravisit::walk_path(self, &tr.path);
// Those in 3. are warned with this call.
for impl_item_ref in impl_item_refs {
for impl_item_ref in items {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
if let hir::ImplItemKind::TyAlias(ref ty) = impl_item.kind {
self.visit_ty(ty);
@ -1619,11 +1619,11 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
}
}
}
} else if trait_ref.is_none() && self_is_public_path {
} else if of_trait.is_none() && self_is_public_path {
// `impl Public<Private> { ... }`. Any public static
// methods will be visible as `Public::foo`.
let mut found_pub_static = false;
for impl_item_ref in impl_item_refs {
for impl_item_ref in items {
if self.item_is_public(&impl_item_ref.id.hir_id, &impl_item_ref.vis) {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item_ref.kind {
@ -1997,12 +1997,12 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
// Subitems of inherent impls have their own publicity.
// A trait impl is public when both its type and its trait are public
// Subitems of trait impls have inherited publicity.
hir::ItemKind::Impl(.., ref trait_ref, _, impl_item_refs) => {
hir::ItemKind::Impl { ref of_trait, items, .. } => {
let impl_vis = ty::Visibility::of_impl(item.hir_id, tcx, &Default::default());
self.check(item.hir_id, impl_vis).generics().predicates();
for impl_item_ref in impl_item_refs {
for impl_item_ref in items {
let impl_item = tcx.hir().impl_item(impl_item_ref.id);
let impl_item_vis = if trait_ref.is_none() {
let impl_item_vis = if of_trait.is_none() {
min(
ty::Visibility::from_hir(&impl_item.vis, item.hir_id, tcx),
impl_vis,

View File

@ -416,11 +416,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
| hir::ItemKind::Union(_, ref generics)
| hir::ItemKind::Trait(_, _, ref generics, ..)
| hir::ItemKind::TraitAlias(ref generics, ..)
| hir::ItemKind::Impl(_, _, _, ref generics, ..) => {
| hir::ItemKind::Impl { ref generics, .. } => {
// Impls permit `'_` to be used and it is equivalent to "some fresh lifetime name".
// This is not true for other kinds of items.x
let track_lifetime_uses = match item.kind {
hir::ItemKind::Impl(..) => true,
hir::ItemKind::Impl { .. } => true,
_ => false,
};
// These kinds of items have only early-bound lifetime parameters.
@ -1638,7 +1638,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
match parent.kind {
hir::ItemKind::Trait(_, _, ref generics, ..)
| hir::ItemKind::Impl(_, _, _, ref generics, ..) => {
| hir::ItemKind::Impl { ref generics, .. } => {
index += generics.params.len() as u32;
}
_ => {}
@ -2067,12 +2067,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Method(_, body), .. }) => {
if let hir::ItemKind::Impl(.., ref self_ty, ref impl_items) =
if let hir::ItemKind::Impl { ref self_ty, ref items, .. } =
self.tcx.hir().expect_item(self.tcx.hir().get_parent_item(parent)).kind
{
impl_self = Some(self_ty);
assoc_item_kind =
impl_items.iter().find(|ii| ii.id.hir_id == parent).map(|ii| ii.kind);
items.iter().find(|ii| ii.id.hir_id == parent).map(|ii| ii.kind);
}
Some(body)
}

View File

@ -405,9 +405,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
{
Some(impl_id) => match self.tcx.hir().get_if_local(impl_id) {
Some(Node::Item(item)) => match item.kind {
hir::ItemKind::Impl(.., ref ty, _) => {
hir::ItemKind::Impl { ref self_ty, .. } => {
let mut qualname = String::from("<");
qualname.push_str(&self.tcx.hir().hir_to_pretty_string(ty.hir_id));
qualname.push_str(&self.tcx.hir().hir_to_pretty_string(self_ty.hir_id));
let trait_id = self.tcx.trait_id_of_impl(impl_id);
let mut decl_id = None;

View File

@ -195,8 +195,8 @@ crate fn environment(tcx: TyCtxt<'_>, def_id: DefId) -> Environment<'_> {
},
Node::Item(item) => match item.kind {
ItemKind::Impl(.., Some(..), _, _) => NodeKind::TraitImpl,
ItemKind::Impl(.., None, _, _) => NodeKind::InherentImpl,
ItemKind::Impl { of_trait: Some(_), .. } => NodeKind::TraitImpl,
ItemKind::Impl { of_trait: None, .. } => NodeKind::InherentImpl,
ItemKind::Fn(..) => NodeKind::Fn,
_ => NodeKind::Other,
},

View File

@ -128,8 +128,8 @@ fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
let parent_def_id = tcx.hir().local_def_id(parent_id);
let parent_item = tcx.hir().expect_item(parent_id);
match parent_item.kind {
hir::ItemKind::Impl(.., ref impl_item_refs) => {
if let Some(impl_item_ref) = impl_item_refs.iter().find(|i| i.id.hir_id == id) {
hir::ItemKind::Impl { ref items, .. } => {
if let Some(impl_item_ref) = items.iter().find(|i| i.id.hir_id == id) {
let assoc_item =
associated_item_from_impl_item_ref(tcx, parent_def_id, impl_item_ref);
debug_assert_eq!(assoc_item.def_id, def_id);
@ -194,8 +194,8 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
.map(|trait_item_ref| trait_item_ref.id)
.map(|id| tcx.hir().local_def_id(id.hir_id)),
),
hir::ItemKind::Impl(.., ref impl_item_refs) => tcx.arena.alloc_from_iter(
impl_item_refs
hir::ItemKind::Impl { ref items, .. } => tcx.arena.alloc_from_iter(
items
.iter()
.map(|impl_item_ref| impl_item_ref.id)
.map(|id| tcx.hir().local_def_id(id.hir_id)),

View File

@ -1709,17 +1709,11 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
check_enum(tcx, it.span, &enum_definition.variants, it.hir_id);
}
hir::ItemKind::Fn(..) => {} // entirely within check_item_body
hir::ItemKind::Impl(.., ref impl_item_refs) => {
hir::ItemKind::Impl { ref items, .. } => {
debug!("ItemKind::Impl {} with id {}", it.ident, it.hir_id);
let impl_def_id = tcx.hir().local_def_id(it.hir_id);
if let Some(impl_trait_ref) = tcx.impl_trait_ref(impl_def_id) {
check_impl_items_against_trait(
tcx,
it.span,
impl_def_id,
impl_trait_ref,
impl_item_refs,
);
check_impl_items_against_trait(tcx, it.span, impl_def_id, impl_trait_ref, items);
let trait_def_id = impl_trait_ref.def_id;
check_on_unimplemented(tcx, trait_def_id, it);
}

View File

@ -97,7 +97,7 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: DefId) {
//
// won't be allowed unless there's an *explicit* implementation of `Send`
// for `T`
hir::ItemKind::Impl(_, _, defaultness, _, ref trait_ref, ref self_ty, _) => {
hir::ItemKind::Impl { defaultness, ref of_trait, ref self_ty, .. } => {
let is_auto = tcx
.impl_trait_ref(tcx.hir().local_def_id(item.hir_id))
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
@ -107,11 +107,11 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: DefId) {
}
match polarity {
ty::ImplPolarity::Positive => {
check_impl(tcx, item, self_ty, trait_ref);
check_impl(tcx, item, self_ty, of_trait);
}
ty::ImplPolarity::Negative => {
// FIXME(#27579): what amount of WF checking do we need for neg impls?
if trait_ref.is_some() && !is_auto {
if of_trait.is_some() && !is_auto {
struct_span_err!(
tcx.sess,
item.span,

View File

@ -57,7 +57,7 @@ fn visit_implementation_of_drop(tcx: TyCtxt<'_>, impl_did: DefId) {
let impl_hir_id = tcx.hir().as_local_hir_id(impl_did).expect("foreign Drop impl on non-ADT");
let sp = match tcx.hir().expect_item(impl_hir_id).kind {
ItemKind::Impl(.., ty, _) => ty.span,
ItemKind::Impl { self_ty, .. } => self_ty.span,
_ => bug!("expected Drop impl item"),
};
@ -94,7 +94,7 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: DefId) {
Ok(()) => {}
Err(CopyImplementationError::InfrigingFields(fields)) => {
let item = tcx.hir().expect_item(impl_hir_id);
let span = if let ItemKind::Impl(.., Some(ref tr), _, _) = item.kind {
let span = if let ItemKind::Impl { of_trait: Some(ref tr), .. } = item.kind {
tr.path.span
} else {
span
@ -113,7 +113,8 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: DefId) {
}
Err(CopyImplementationError::NotAnAdt) => {
let item = tcx.hir().expect_item(impl_hir_id);
let span = if let ItemKind::Impl(.., ref ty, _) = item.kind { ty.span } else { span };
let span =
if let ItemKind::Impl { self_ty, .. } = item.kind { self_ty.span } else { span };
struct_span_err!(
tcx.sess,
@ -490,7 +491,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
return err_info;
} else if diff_fields.len() > 1 {
let item = tcx.hir().expect_item(impl_hir_id);
let span = if let ItemKind::Impl(.., Some(ref t), _, _) = item.kind {
let span = if let ItemKind::Impl { of_trait: Some(ref t), .. } = item.kind {
t.path.span
} else {
tcx.hir().span(impl_hir_id)

View File

@ -47,7 +47,7 @@ struct InherentCollect<'tcx> {
impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
let ty = match item.kind {
hir::ItemKind::Impl(.., None, ref ty, _) => ty,
hir::ItemKind::Impl { of_trait: None, ref self_ty, .. } => self_ty,
_ => return,
};

View File

@ -27,7 +27,7 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
// "Trait" impl
if let hir::ItemKind::Impl(.., generics, Some(tr), impl_ty, _) = &item.kind {
if let hir::ItemKind::Impl { generics, of_trait: Some(ref tr), self_ty, .. } = &item.kind {
debug!(
"coherence2::orphan check: trait impl {}",
self.tcx.hir().node_to_string(item.hir_id)
@ -72,7 +72,7 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
let msg = format!("{} is not defined in the current crate{}", ty, postfix);
if *is_target_ty {
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
err.span_label(impl_ty.span, &msg);
err.span_label(self_ty.span, &msg);
} else {
// Point at `C<B>` in `impl<A, B> for C<B> in D<A>`
err.span_label(tr.path.span, &msg);

View File

@ -88,7 +88,7 @@ impl UnsafetyChecker<'tcx> {
impl ItemLikeVisitor<'v> for UnsafetyChecker<'tcx> {
fn visit_item(&mut self, item: &'v hir::Item<'v>) {
if let hir::ItemKind::Impl(unsafety, polarity, _, ref generics, ..) = item.kind {
if let hir::ItemKind::Impl { unsafety, polarity, ref generics, .. } = item.kind {
self.check_unsafety_coherence(item, Some(generics), unsafety, polarity);
}
}

View File

@ -184,7 +184,7 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
| hir::ItemKind::Enum(_, generics)
| hir::ItemKind::TraitAlias(generics, _)
| hir::ItemKind::Trait(_, _, generics, ..)
| hir::ItemKind::Impl(_, _, _, generics, ..)
| hir::ItemKind::Impl { generics, .. }
| hir::ItemKind::Struct(_, generics) => (generics, true),
hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. })
| hir::ItemKind::TyAlias(_, generics) => (generics, false),
@ -401,7 +401,7 @@ fn type_param_predicates(
Node::Item(item) => {
match item.kind {
ItemKind::Fn(.., ref generics, _)
| ItemKind::Impl(_, _, _, ref generics, ..)
| ItemKind::Impl { ref generics, .. }
| ItemKind::TyAlias(_, ref generics)
| ItemKind::OpaqueTy(OpaqueTy { ref generics, impl_trait_fn: None, .. })
| ItemKind::Enum(_, ref generics)
@ -531,7 +531,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
tcx.predicates_of(def_id);
convert_enum_variant_types(tcx, def_id, &enum_definition.variants);
}
hir::ItemKind::Impl(..) => {
hir::ItemKind::Impl { .. } => {
tcx.generics_of(def_id);
tcx.type_of(def_id);
tcx.impl_trait_ref(def_id);
@ -1052,9 +1052,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
Node::Item(item) => {
match item.kind {
ItemKind::Fn(.., ref generics, _) | ItemKind::Impl(_, _, _, ref generics, ..) => {
generics
}
ItemKind::Fn(.., ref generics, _) | ItemKind::Impl { ref generics, .. } => generics,
ItemKind::TyAlias(_, ref generics)
| ItemKind::Enum(_, ref generics)
@ -1338,7 +1336,9 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
icx.to_ty(ty)
}
}
ItemKind::TyAlias(ref ty, _) | ItemKind::Impl(.., ref ty, _) => icx.to_ty(ty),
ItemKind::TyAlias(ref self_ty, _) | ItemKind::Impl { ref self_ty, .. } => {
icx.to_ty(self_ty)
}
ItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id, substs)
@ -1956,12 +1956,10 @@ fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::TraitRef<'_>> {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
match tcx.hir().expect_item(hir_id).kind {
hir::ItemKind::Impl(.., ref opt_trait_ref, _, _) => {
opt_trait_ref.as_ref().map(|ast_trait_ref| {
let selfty = tcx.type_of(def_id);
AstConv::instantiate_mono_trait_ref(&icx, ast_trait_ref, selfty)
})
}
hir::ItemKind::Impl { ref of_trait, .. } => of_trait.as_ref().map(|ast_trait_ref| {
let selfty = tcx.type_of(def_id);
AstConv::instantiate_mono_trait_ref(&icx, ast_trait_ref, selfty)
}),
_ => bug!(),
}
}
@ -1971,19 +1969,21 @@ fn impl_polarity(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ImplPolarity {
let is_rustc_reservation = tcx.has_attr(def_id, sym::rustc_reservation_impl);
let item = tcx.hir().expect_item(hir_id);
match &item.kind {
hir::ItemKind::Impl(_, hir::ImplPolarity::Negative, ..) => {
hir::ItemKind::Impl { polarity: hir::ImplPolarity::Negative, .. } => {
if is_rustc_reservation {
tcx.sess.span_err(item.span, "reservation impls can't be negative");
}
ty::ImplPolarity::Negative
}
hir::ItemKind::Impl(_, hir::ImplPolarity::Positive, _, _, None, _, _) => {
hir::ItemKind::Impl { polarity: hir::ImplPolarity::Positive, of_trait: None, .. } => {
if is_rustc_reservation {
tcx.sess.span_err(item.span, "reservation impls can't be inherent");
}
ty::ImplPolarity::Positive
}
hir::ItemKind::Impl(_, hir::ImplPolarity::Positive, _, _, Some(_tr), _, _) => {
hir::ItemKind::Impl {
polarity: hir::ImplPolarity::Positive, of_trait: Some(_), ..
} => {
if is_rustc_reservation {
ty::ImplPolarity::Reservation
} else {
@ -2142,7 +2142,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
Node::Item(item) => {
match item.kind {
ItemKind::Impl(_, _, defaultness, ref generics, ..) => {
ItemKind::Impl { defaultness, ref generics, .. } => {
if defaultness.is_default() {
is_default_impl_trait = tcx.impl_trait_ref(def_id);
}
@ -2359,7 +2359,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
// before uses of `U`. This avoids false ambiguity errors
// in trait checking. See `setup_constraining_predicates`
// for details.
if let Node::Item(&Item { kind: ItemKind::Impl(..), .. }) = node {
if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node {
let self_ty = tcx.type_of(def_id);
let trait_ref = tcx.impl_trait_ref(def_id);
cgp::setup_constraining_predicates(

View File

@ -75,10 +75,10 @@ struct ImplWfCheck<'tcx> {
impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
if let hir::ItemKind::Impl(.., ref impl_item_refs) = item.kind {
if let hir::ItemKind::Impl { ref items, .. } = item.kind {
let impl_def_id = self.tcx.hir().local_def_id(item.hir_id);
enforce_impl_params_are_constrained(self.tcx, impl_def_id, impl_item_refs);
enforce_impl_items_are_distinct(self.tcx, impl_item_refs);
enforce_impl_params_are_constrained(self.tcx, impl_def_id, items);
enforce_impl_items_are_distinct(self.tcx, items);
}
}

View File

@ -331,7 +331,7 @@ pub fn build_impl(
let for_ = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) {
match tcx.hir().expect_item(hir_id).kind {
hir::ItemKind::Impl(.., ref t, _) => t.clean(cx),
hir::ItemKind::Impl { self_ty, .. } => self_ty.clean(cx),
_ => panic!("did given to build_impl was not an impl"),
}
} else {
@ -351,9 +351,9 @@ pub fn build_impl(
let predicates = tcx.explicit_predicates_of(did);
let (trait_items, generics) = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) {
match tcx.hir().expect_item(hir_id).kind {
hir::ItemKind::Impl(.., ref gen, _, _, ref item_ids) => (
item_ids.iter().map(|ii| tcx.hir().impl_item(ii.id).clean(cx)).collect::<Vec<_>>(),
gen.clean(cx),
hir::ItemKind::Impl { ref generics, ref items, .. } => (
items.iter().map(|item| tcx.hir().impl_item(item.id).clean(cx)).collect::<Vec<_>>(),
generics.clean(cx),
),
_ => panic!("did given to build_impl was not an impl"),
}

View File

@ -905,8 +905,8 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> {
}
fn visit_item(&mut self, item: &'hir hir::Item) {
let name = if let hir::ItemKind::Impl(.., ref ty, _) = item.kind {
self.map.hir_to_pretty_string(ty.hir_id)
let name = if let hir::ItemKind::Impl { ref self_ty, .. } = item.kind {
self.map.hir_to_pretty_string(self_ty.hir_id)
} else {
item.ident.to_string()
};

View File

@ -558,27 +558,27 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
om.trait_aliases.push(t);
}
hir::ItemKind::Impl(
hir::ItemKind::Impl {
unsafety,
polarity,
defaultness,
ref generics,
ref trait_,
for_,
ref item_ids,
) => {
ref of_trait,
self_ty,
ref items,
} => {
// Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
// them up regardless of where they're located.
if !self.inlining && trait_.is_none() {
if !self.inlining && of_trait.is_none() {
let items =
item_ids.iter().map(|ii| self.cx.tcx.hir().impl_item(ii.id)).collect();
items.iter().map(|item| self.cx.tcx.hir().impl_item(item.id)).collect();
let i = Impl {
unsafety,
polarity,
defaultness,
generics,
trait_,
for_,
trait_: of_trait,
for_: self_ty,
items,
attrs: &item.attrs,
id: item.hir_id,