Skip to content

Commit

Permalink
hir: remove some obsolete NodeId methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Mar 7, 2019
1 parent e780daf commit d7120e4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 49 deletions.
54 changes: 20 additions & 34 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,11 @@ impl<'hir> Map<'hir> {
}

for id in &module.trait_items {
visitor.visit_trait_item(self.expect_trait_item_by_hir_id(id.hir_id));
visitor.visit_trait_item(self.expect_trait_item(id.hir_id));
}

for id in &module.impl_items {
visitor.visit_impl_item(self.expect_impl_item_by_hir_id(id.hir_id));
visitor.visit_impl_item(self.expect_impl_item(id.hir_id));
}
}

Expand Down Expand Up @@ -929,66 +929,52 @@ impl<'hir> Map<'hir> {

// FIXME(@ljedrz): replace the NodeId variant
pub fn expect_item_by_hir_id(&self, id: HirId) -> &'hir Item {
let node_id = self.hir_to_node_id(id);
self.expect_item(node_id)
match self.find_by_hir_id(id) { // read recorded by `find`
Some(Node::Item(item)) => item,
_ => bug!("expected item, found {}", self.hir_to_string(id))
}
}

pub fn expect_impl_item(&self, id: NodeId) -> &'hir ImplItem {
match self.find(id) {
pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem {
match self.find_by_hir_id(id) {
Some(Node::ImplItem(item)) => item,
_ => bug!("expected impl item, found {}", self.node_to_string(id))
_ => bug!("expected impl item, found {}", self.hir_to_string(id))
}
}

// FIXME(@ljedrz): replace the NodeId variant
pub fn expect_impl_item_by_hir_id(&self, id: HirId) -> &'hir ImplItem {
let node_id = self.hir_to_node_id(id);
self.expect_impl_item(node_id)
}

// FIXME(@ljedrz): replace the NodeId variant
pub fn expect_trait_item_by_hir_id(&self, id: HirId) -> &'hir TraitItem {
let node_id = self.hir_to_node_id(id);
self.expect_trait_item(node_id)
}

pub fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem {
match self.find(id) {
pub fn expect_trait_item(&self, id: HirId) -> &'hir TraitItem {
match self.find_by_hir_id(id) {
Some(Node::TraitItem(item)) => item,
_ => bug!("expected trait item, found {}", self.node_to_string(id))
_ => bug!("expected trait item, found {}", self.hir_to_string(id))
}
}

pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData {
let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible

match self.find(id) {
match self.find_by_hir_id(id) {
Some(Node::Item(i)) => {
match i.node {
ItemKind::Struct(ref struct_def, _) |
ItemKind::Union(ref struct_def, _) => struct_def,
_ => bug!("struct ID bound to non-struct {}", self.node_to_string(id))
_ => bug!("struct ID bound to non-struct {}", self.hir_to_string(id))
}
}
Some(Node::StructCtor(data)) => data,
Some(Node::Variant(variant)) => &variant.node.data,
_ => bug!("expected struct or variant, found {}", self.node_to_string(id))
_ => bug!("expected struct or variant, found {}", self.hir_to_string(id))
}
}

pub fn expect_variant(&self, id: HirId) -> &'hir Variant {
let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible

match self.find(id) {
match self.find_by_hir_id(id) {
Some(Node::Variant(variant)) => variant,
_ => bug!("expected variant, found {}", self.node_to_string(id)),
_ => bug!("expected variant, found {}", self.hir_to_string(id)),
}
}

pub fn expect_foreign_item(&self, id: NodeId) -> &'hir ForeignItem {
match self.find(id) {
pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem {
match self.find_by_hir_id(id) {
Some(Node::ForeignItem(item)) => item,
_ => bug!("expected foreign item, found {}", self.node_to_string(id))
_ => bug!("expected foreign item, found {}", self.hir_to_string(id))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
let tcx = self.tcx;

let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let ast_item = tcx.hir().expect_trait_item_by_hir_id(hir_id);
let ast_item = tcx.hir().expect_trait_item(hir_id);
let trait_item = tcx.associated_item(def_id);

let container = match trait_item.defaultness {
Expand Down Expand Up @@ -890,7 +890,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
let tcx = self.tcx;

let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
let ast_item = self.tcx.hir().expect_impl_item_by_hir_id(hir_id);
let ast_item = self.tcx.hir().expect_impl_item(hir_id);
let impl_item = self.tcx.associated_item(def_id);

let container = match impl_item.defaultness {
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
let tcx = infcx.tcx;
let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id).unwrap();
let (impl_m_output, impl_m_iter) = match tcx.hir()
.expect_impl_item_by_hir_id(impl_m_hir_id)
.expect_impl_item(impl_m_hir_id)
.node {
ImplItemKind::Method(ref impl_m_sig, _) => {
(&impl_m_sig.decl.output, impl_m_sig.decl.inputs.iter())
Expand All @@ -429,7 +429,7 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
TypeError::Mutability => {
if let Some(trait_m_hir_id) = tcx.hir().as_local_hir_id(trait_m.def_id) {
let trait_m_iter = match tcx.hir()
.expect_trait_item_by_hir_id(trait_m_hir_id)
.expect_trait_item(trait_m_hir_id)
.node {
TraitItemKind::Method(ref trait_m_sig, _) => {
trait_m_sig.decl.inputs.iter()
Expand All @@ -456,7 +456,7 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
TypeError::Sorts(ExpectedFound { .. }) => {
if let Some(trait_m_hir_id) = tcx.hir().as_local_hir_id(trait_m.def_id) {
let (trait_m_output, trait_m_iter) =
match tcx.hir().expect_trait_item_by_hir_id(trait_m_hir_id).node {
match tcx.hir().expect_trait_item(trait_m_hir_id).node {
TraitItemKind::Method(ref trait_m_sig, _) => {
(&trait_m_sig.decl.output, trait_m_sig.decl.inputs.iter())
}
Expand Down Expand Up @@ -599,8 +599,8 @@ fn compare_number_of_generics<'a, 'tcx>(
if impl_count != trait_count {
err_occurred = true;

let impl_node_id = tcx.hir().as_local_node_id(impl_.def_id).unwrap();
let impl_item = tcx.hir().expect_impl_item(impl_node_id);
let impl_hir_id = tcx.hir().as_local_hir_id(impl_.def_id).unwrap();
let impl_item = tcx.hir().expect_impl_item(impl_hir_id);
let span = if impl_item.generics.params.is_empty()
|| impl_item.generics.span.is_dummy() { // argument position impl Trait (#55374)
impl_span
Expand Down Expand Up @@ -666,7 +666,7 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if trait_number_args != impl_number_args {
let trait_m_hir_id = tcx.hir().as_local_hir_id(trait_m.def_id);
let trait_span = if let Some(trait_id) = trait_m_hir_id {
match tcx.hir().expect_trait_item_by_hir_id(trait_id).node {
match tcx.hir().expect_trait_item(trait_id).node {
TraitItemKind::Method(ref trait_m_sig, _) => {
let pos = if trait_number_args > 0 {
trait_number_args - 1
Expand All @@ -691,7 +691,7 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_item_span
};
let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id).unwrap();
let impl_span = match tcx.hir().expect_impl_item_by_hir_id(impl_m_hir_id).node {
let impl_span = match tcx.hir().expect_impl_item(impl_m_hir_id).node {
ImplItemKind::Method(ref impl_m_sig, _) => {
let pos = if impl_number_args > 0 {
impl_number_args - 1
Expand Down Expand Up @@ -962,7 +962,7 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_ty);

// Locate the Span containing just the type of the offending impl
match tcx.hir().expect_impl_item_by_hir_id(impl_c_hir_id).node {
match tcx.hir().expect_impl_item(impl_c_hir_id).node {
ImplItemKind::Const(ref ty, _) => cause.span = ty.span,
_ => bug!("{:?} is not a impl const", impl_c),
}
Expand All @@ -977,7 +977,7 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let trait_c_hir_id = tcx.hir().as_local_hir_id(trait_c.def_id);
let trait_c_span = trait_c_hir_id.map(|trait_c_hir_id| {
// Add a label to the Span containing just the type of the const
match tcx.hir().expect_trait_item_by_hir_id(trait_c_hir_id).node {
match tcx.hir().expect_trait_item(trait_c_hir_id).node {
TraitItemKind::Const(ref ty, _) => ty.span,
_ => bug!("{:?} is not a trait const", trait_c),
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def

pub fn check_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let trait_item = tcx.hir().expect_trait_item_by_hir_id(hir_id);
let trait_item = tcx.hir().expect_trait_item(hir_id);

let method_sig = match trait_item.node {
hir::TraitItemKind::Method(ref sig, _) => Some(sig),
Expand All @@ -163,7 +163,7 @@ pub fn check_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {

pub fn check_impl_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let impl_item = tcx.hir().expect_impl_item_by_hir_id(hir_id);
let impl_item = tcx.hir().expect_impl_item(hir_id);

let method_sig = match impl_item.node {
hir::ImplItemKind::Method(ref sig, _) => Some(sig),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: hir::HirId) {
}

fn convert_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_item_id: hir::HirId) {
let trait_item = tcx.hir().expect_trait_item_by_hir_id(trait_item_id);
let trait_item = tcx.hir().expect_trait_item(trait_item_id);
let def_id = tcx.hir().local_def_id_from_hir_id(trait_item.hir_id);
tcx.generics_of(def_id);

Expand All @@ -504,7 +504,7 @@ fn convert_impl_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_item_id: hir::H
tcx.generics_of(def_id);
tcx.type_of(def_id);
tcx.predicates_of(def_id);
if let hir::ImplItemKind::Method(..) = tcx.hir().expect_impl_item_by_hir_id(impl_item_id).node {
if let hir::ImplItemKind::Method(..) = tcx.hir().expect_impl_item(impl_item_id).node {
tcx.fn_sig(def_id);
}
}
Expand Down

0 comments on commit d7120e4

Please sign in to comment.