From fb22315f0878b432e1e79f9825a4b94651a5d475 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Fri, 1 Mar 2019 09:52:20 +0100 Subject: [PATCH] hir: remove NodeId from VariantData --- src/librustc/hir/lowering.rs | 10 ++++------ src/librustc/hir/map/mod.rs | 4 ++-- src/librustc/hir/mod.rs | 19 ++++++------------- src/librustc/ich/impls_hir.rs | 6 +++--- src/librustc_metadata/encoder.rs | 4 ++-- src/librustc_mir/build/mod.rs | 4 ++-- src/librustc_mir/shim.rs | 5 ++--- src/librustc_mir/transform/mod.rs | 4 ++-- src/librustc_typeck/collect.rs | 12 ++++++------ src/librustdoc/clean/mod.rs | 2 +- 10 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 5a95681d667..27a7561e765 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -2674,7 +2674,7 @@ impl<'a> LoweringContext<'a> { fn lower_variant_data(&mut self, vdata: &VariantData) -> hir::VariantData { match *vdata { VariantData::Struct(ref fields, id) => { - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id); + let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id); hir::VariantData::Struct( fields @@ -2682,12 +2682,11 @@ impl<'a> LoweringContext<'a> { .enumerate() .map(|f| self.lower_struct_field(f)) .collect(), - node_id, hir_id, ) }, VariantData::Tuple(ref fields, id) => { - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id); + let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id); hir::VariantData::Tuple( fields @@ -2695,14 +2694,13 @@ impl<'a> LoweringContext<'a> { .enumerate() .map(|f| self.lower_struct_field(f)) .collect(), - node_id, hir_id, ) }, VariantData::Unit(id) => { - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id); + let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id); - hir::VariantData::Unit(node_id, hir_id) + hir::VariantData::Unit(hir_id) }, } } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index f8d1c949bdc..bec04b2e405 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -366,11 +366,11 @@ impl<'hir> Map<'hir> { } } Node::Variant(variant) => { - let def_id = self.local_def_id(variant.node.data.id()); + let def_id = self.local_def_id_from_hir_id(variant.node.data.hir_id()); Some(Def::Variant(def_id)) } Node::StructCtor(variant) => { - let def_id = self.local_def_id(variant.id()); + let def_id = self.local_def_id_from_hir_id(variant.hir_id()); Some(Def::StructCtor(def_id, def::CtorKind::from_hir(variant))) } Node::AnonConst(_) | diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index d632810d006..b0f362ca30a 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2156,9 +2156,9 @@ impl StructField { /// Id of the whole struct lives in `Item`. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum VariantData { - Struct(HirVec, NodeId, HirId), - Tuple(HirVec, NodeId, HirId), - Unit(NodeId, HirId), + Struct(HirVec, HirId), + Tuple(HirVec, HirId), + Unit(HirId), } impl VariantData { @@ -2168,18 +2168,11 @@ impl VariantData { _ => &[], } } - pub fn id(&self) -> NodeId { - match *self { - VariantData::Struct(_, id, ..) - | VariantData::Tuple(_, id, ..) - | VariantData::Unit(id, ..) => id, - } - } pub fn hir_id(&self) -> HirId { match *self { - VariantData::Struct(_, _, hir_id) - | VariantData::Tuple(_, _, hir_id) - | VariantData::Unit(_, hir_id) => hir_id, + VariantData::Struct(_, hir_id) + | VariantData::Tuple(_, hir_id) + | VariantData::Unit(hir_id) => hir_id, } } pub fn is_struct(&self) -> bool { diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index f46ef20aaf1..6a52b633c4f 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -842,9 +842,9 @@ impl_stable_hash_for!(struct hir::StructField { }); impl_stable_hash_for!(enum hir::VariantData { - Struct(fields, id, hir_id), - Tuple(fields, id, hir_id), - Unit(id, hir_id) + Struct(fields, hir_id), + Tuple(fields, hir_id), + Unit(hir_id) }); impl<'a> HashStable> for hir::Item { diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 541c7a78199..f79cfa3b773 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -1069,7 +1069,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { // for methods, write all the stuff get_trait_method // needs to know let struct_ctor = if !struct_def.is_struct() { - Some(tcx.hir().local_def_id(struct_def.id()).index) + Some(tcx.hir().local_def_id_from_hir_id(struct_def.hir_id()).index) } else { None }; @@ -1772,7 +1772,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> { // If the struct has a constructor, encode it. if !struct_def.is_struct() { - let ctor_def_id = self.tcx.hir().local_def_id(struct_def.id()); + let ctor_def_id = self.tcx.hir().local_def_id_from_hir_id(struct_def.hir_id()); self.record(ctor_def_id, IsolatedEncoder::encode_struct_ctor, (def_id, ctor_def_id)); diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index e4f85887841..61ead366a87 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -229,7 +229,7 @@ fn create_constructor_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, -> Mir<'tcx> { let span = tcx.hir().span(ctor_id); - if let hir::VariantData::Tuple(ref fields, ctor_id, _) = *v { + if let hir::VariantData::Tuple(ref fields, ctor_id) = *v { tcx.infer_ctxt().enter(|infcx| { let mut mir = shim::build_adt_ctor(&infcx, ctor_id, fields, span); @@ -245,7 +245,7 @@ fn create_constructor_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }; mir_util::dump_mir(tcx, None, "mir_map", &0, - MirSource::item(tcx.hir().local_def_id(ctor_id)), + MirSource::item(tcx.hir().local_def_id_from_hir_id(ctor_id)), &mir, |_, _| Ok(()) ); mir diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index adc328f1033..db8476f3be5 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -10,7 +10,6 @@ use rustc::ty::query::Providers; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; use rustc_target::spec::abi::Abi; -use syntax::ast; use syntax_pos::Span; use std::fmt; @@ -855,14 +854,14 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>, - ctor_id: ast::NodeId, + ctor_id: hir::HirId, fields: &[hir::StructField], span: Span) -> Mir<'tcx> { let tcx = infcx.tcx; let gcx = tcx.global_tcx(); - let def_id = tcx.hir().local_def_id(ctor_id); + let def_id = tcx.hir().local_def_id_from_hir_id(ctor_id); let param_env = gcx.param_env(def_id); // Normalize the sig. diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index c1bb31a49a4..8f5fc696377 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -80,8 +80,8 @@ fn mir_keys<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, krate: CrateNum) _: &'tcx hir::Generics, _: hir::HirId, _: Span) { - if let hir::VariantData::Tuple(_, node_id, _) = *v { - self.set.insert(self.tcx.hir().local_def_id(node_id)); + if let hir::VariantData::Tuple(_, hir_id) = *v { + self.set.insert(self.tcx.hir().local_def_id_from_hir_id(hir_id)); } intravisit::walk_struct_def(self, v) } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 95c0ad95bc1..594e29ab9dd 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -454,7 +454,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: hir::HirId) { } if !struct_def.is_struct() { - convert_variant_ctor(tcx, struct_def.id()); + convert_variant_ctor(tcx, struct_def.hir_id()); } } @@ -510,8 +510,8 @@ fn convert_impl_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_item_id: hir::H } } -fn convert_variant_ctor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ctor_id: ast::NodeId) { - let def_id = tcx.hir().local_def_id(ctor_id); +fn convert_variant_ctor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ctor_id: hir::HirId) { + let def_id = tcx.hir().local_def_id_from_hir_id(ctor_id); tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); @@ -563,7 +563,7 @@ fn convert_enum_variant_types<'a, 'tcx>( // Convert the ctor, if any. This also registers the variant as // an item. - convert_variant_ctor(tcx, variant.node.data.id()); + convert_variant_ctor(tcx, variant.node.data.hir_id()); } } @@ -634,7 +634,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad def.variants .iter() .map(|v| { - let did = tcx.hir().local_def_id(v.node.data.id()); + let did = tcx.hir().local_def_id_from_hir_id(v.node.data.hir_id()); let discr = if let Some(ref e) = v.node.disr_expr { distance_from_explicit = 0; ty::VariantDiscr::Explicit(tcx.hir().local_def_id_from_hir_id(e.hir_id)) @@ -652,7 +652,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad ItemKind::Struct(ref def, _) => { // Use separate constructor id for unit/tuple structs and reuse did for braced structs. let ctor_id = if !def.is_struct() { - Some(tcx.hir().local_def_id(def.id())) + Some(tcx.hir().local_def_id_from_hir_id(def.hir_id())) } else { None }; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7511ad5dd29..c64a73fa308 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -3088,7 +3088,7 @@ impl Clean for doctree::Variant { visibility: None, stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.def.id()), + def_id: cx.tcx.hir().local_def_id_from_hir_id(self.def.hir_id()), inner: VariantItem(Variant { kind: self.def.clean(cx), }),