Skip to content

Commit

Permalink
hir: remove NodeId from VariantData
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Mar 2, 2019
1 parent 50b8bc8 commit fb22315
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 40 deletions.
10 changes: 4 additions & 6 deletions src/librustc/hir/lowering.rs
Expand Up @@ -2674,35 +2674,33 @@ 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
.iter()
.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
.iter()
.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)
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -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(_) |
Expand Down
19 changes: 6 additions & 13 deletions src/librustc/hir/mod.rs
Expand Up @@ -2156,9 +2156,9 @@ impl StructField {
/// Id of the whole struct lives in `Item`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub enum VariantData {
Struct(HirVec<StructField>, NodeId, HirId),
Tuple(HirVec<StructField>, NodeId, HirId),
Unit(NodeId, HirId),
Struct(HirVec<StructField>, HirId),
Tuple(HirVec<StructField>, HirId),
Unit(HirId),
}

impl VariantData {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ich/impls_hir.rs
Expand Up @@ -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<StableHashingContext<'a>> for hir::Item {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/encoder.rs
Expand Up @@ -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
};
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/build/mod.rs
Expand Up @@ -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);

Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_mir/shim.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/mod.rs
Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_typeck/collect.rs
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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))
Expand All @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Expand Up @@ -3088,7 +3088,7 @@ impl Clean<Item> 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),
}),
Expand Down

0 comments on commit fb22315

Please sign in to comment.