Skip to content

Commit d7120e4

Browse files
committed
hir: remove some obsolete NodeId methods
1 parent e780daf commit d7120e4

File tree

5 files changed

+35
-49
lines changed

5 files changed

+35
-49
lines changed

src/librustc/hir/map/mod.rs

+20-34
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,11 @@ impl<'hir> Map<'hir> {
618618
}
619619

620620
for id in &module.trait_items {
621-
visitor.visit_trait_item(self.expect_trait_item_by_hir_id(id.hir_id));
621+
visitor.visit_trait_item(self.expect_trait_item(id.hir_id));
622622
}
623623

624624
for id in &module.impl_items {
625-
visitor.visit_impl_item(self.expect_impl_item_by_hir_id(id.hir_id));
625+
visitor.visit_impl_item(self.expect_impl_item(id.hir_id));
626626
}
627627
}
628628

@@ -929,66 +929,52 @@ impl<'hir> Map<'hir> {
929929

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

936-
pub fn expect_impl_item(&self, id: NodeId) -> &'hir ImplItem {
937-
match self.find(id) {
938+
pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem {
939+
match self.find_by_hir_id(id) {
938940
Some(Node::ImplItem(item)) => item,
939-
_ => bug!("expected impl item, found {}", self.node_to_string(id))
941+
_ => bug!("expected impl item, found {}", self.hir_to_string(id))
940942
}
941943
}
942944

943-
// FIXME(@ljedrz): replace the NodeId variant
944-
pub fn expect_impl_item_by_hir_id(&self, id: HirId) -> &'hir ImplItem {
945-
let node_id = self.hir_to_node_id(id);
946-
self.expect_impl_item(node_id)
947-
}
948-
949-
// FIXME(@ljedrz): replace the NodeId variant
950-
pub fn expect_trait_item_by_hir_id(&self, id: HirId) -> &'hir TraitItem {
951-
let node_id = self.hir_to_node_id(id);
952-
self.expect_trait_item(node_id)
953-
}
954-
955-
pub fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem {
956-
match self.find(id) {
945+
pub fn expect_trait_item(&self, id: HirId) -> &'hir TraitItem {
946+
match self.find_by_hir_id(id) {
957947
Some(Node::TraitItem(item)) => item,
958-
_ => bug!("expected trait item, found {}", self.node_to_string(id))
948+
_ => bug!("expected trait item, found {}", self.hir_to_string(id))
959949
}
960950
}
961951

962952
pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData {
963-
let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible
964-
965-
match self.find(id) {
953+
match self.find_by_hir_id(id) {
966954
Some(Node::Item(i)) => {
967955
match i.node {
968956
ItemKind::Struct(ref struct_def, _) |
969957
ItemKind::Union(ref struct_def, _) => struct_def,
970-
_ => bug!("struct ID bound to non-struct {}", self.node_to_string(id))
958+
_ => bug!("struct ID bound to non-struct {}", self.hir_to_string(id))
971959
}
972960
}
973961
Some(Node::StructCtor(data)) => data,
974962
Some(Node::Variant(variant)) => &variant.node.data,
975-
_ => bug!("expected struct or variant, found {}", self.node_to_string(id))
963+
_ => bug!("expected struct or variant, found {}", self.hir_to_string(id))
976964
}
977965
}
978966

979967
pub fn expect_variant(&self, id: HirId) -> &'hir Variant {
980-
let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible
981-
982-
match self.find(id) {
968+
match self.find_by_hir_id(id) {
983969
Some(Node::Variant(variant)) => variant,
984-
_ => bug!("expected variant, found {}", self.node_to_string(id)),
970+
_ => bug!("expected variant, found {}", self.hir_to_string(id)),
985971
}
986972
}
987973

988-
pub fn expect_foreign_item(&self, id: NodeId) -> &'hir ForeignItem {
989-
match self.find(id) {
974+
pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem {
975+
match self.find_by_hir_id(id) {
990976
Some(Node::ForeignItem(item)) => item,
991-
_ => bug!("expected foreign item, found {}", self.node_to_string(id))
977+
_ => bug!("expected foreign item, found {}", self.hir_to_string(id))
992978
}
993979
}
994980

src/librustc_metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
780780
let tcx = self.tcx;
781781

782782
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
783-
let ast_item = tcx.hir().expect_trait_item_by_hir_id(hir_id);
783+
let ast_item = tcx.hir().expect_trait_item(hir_id);
784784
let trait_item = tcx.associated_item(def_id);
785785

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

892892
let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
893-
let ast_item = self.tcx.hir().expect_impl_item_by_hir_id(hir_id);
893+
let ast_item = self.tcx.hir().expect_impl_item(hir_id);
894894
let impl_item = self.tcx.associated_item(def_id);
895895

896896
let container = match impl_item.defaultness {

src/librustc_typeck/check/compare_method.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
417417
let tcx = infcx.tcx;
418418
let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id).unwrap();
419419
let (impl_m_output, impl_m_iter) = match tcx.hir()
420-
.expect_impl_item_by_hir_id(impl_m_hir_id)
420+
.expect_impl_item(impl_m_hir_id)
421421
.node {
422422
ImplItemKind::Method(ref impl_m_sig, _) => {
423423
(&impl_m_sig.decl.output, impl_m_sig.decl.inputs.iter())
@@ -429,7 +429,7 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
429429
TypeError::Mutability => {
430430
if let Some(trait_m_hir_id) = tcx.hir().as_local_hir_id(trait_m.def_id) {
431431
let trait_m_iter = match tcx.hir()
432-
.expect_trait_item_by_hir_id(trait_m_hir_id)
432+
.expect_trait_item(trait_m_hir_id)
433433
.node {
434434
TraitItemKind::Method(ref trait_m_sig, _) => {
435435
trait_m_sig.decl.inputs.iter()
@@ -456,7 +456,7 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
456456
TypeError::Sorts(ExpectedFound { .. }) => {
457457
if let Some(trait_m_hir_id) = tcx.hir().as_local_hir_id(trait_m.def_id) {
458458
let (trait_m_output, trait_m_iter) =
459-
match tcx.hir().expect_trait_item_by_hir_id(trait_m_hir_id).node {
459+
match tcx.hir().expect_trait_item(trait_m_hir_id).node {
460460
TraitItemKind::Method(ref trait_m_sig, _) => {
461461
(&trait_m_sig.decl.output, trait_m_sig.decl.inputs.iter())
462462
}
@@ -599,8 +599,8 @@ fn compare_number_of_generics<'a, 'tcx>(
599599
if impl_count != trait_count {
600600
err_occurred = true;
601601

602-
let impl_node_id = tcx.hir().as_local_node_id(impl_.def_id).unwrap();
603-
let impl_item = tcx.hir().expect_impl_item(impl_node_id);
602+
let impl_hir_id = tcx.hir().as_local_hir_id(impl_.def_id).unwrap();
603+
let impl_item = tcx.hir().expect_impl_item(impl_hir_id);
604604
let span = if impl_item.generics.params.is_empty()
605605
|| impl_item.generics.span.is_dummy() { // argument position impl Trait (#55374)
606606
impl_span
@@ -666,7 +666,7 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
666666
if trait_number_args != impl_number_args {
667667
let trait_m_hir_id = tcx.hir().as_local_hir_id(trait_m.def_id);
668668
let trait_span = if let Some(trait_id) = trait_m_hir_id {
669-
match tcx.hir().expect_trait_item_by_hir_id(trait_id).node {
669+
match tcx.hir().expect_trait_item(trait_id).node {
670670
TraitItemKind::Method(ref trait_m_sig, _) => {
671671
let pos = if trait_number_args > 0 {
672672
trait_number_args - 1
@@ -691,7 +691,7 @@ fn compare_number_of_method_arguments<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
691691
trait_item_span
692692
};
693693
let impl_m_hir_id = tcx.hir().as_local_hir_id(impl_m.def_id).unwrap();
694-
let impl_span = match tcx.hir().expect_impl_item_by_hir_id(impl_m_hir_id).node {
694+
let impl_span = match tcx.hir().expect_impl_item(impl_m_hir_id).node {
695695
ImplItemKind::Method(ref impl_m_sig, _) => {
696696
let pos = if impl_number_args > 0 {
697697
impl_number_args - 1
@@ -962,7 +962,7 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
962962
trait_ty);
963963

964964
// Locate the Span containing just the type of the offending impl
965-
match tcx.hir().expect_impl_item_by_hir_id(impl_c_hir_id).node {
965+
match tcx.hir().expect_impl_item(impl_c_hir_id).node {
966966
ImplItemKind::Const(ref ty, _) => cause.span = ty.span,
967967
_ => bug!("{:?} is not a impl const", impl_c),
968968
}
@@ -977,7 +977,7 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
977977
let trait_c_hir_id = tcx.hir().as_local_hir_id(trait_c.def_id);
978978
let trait_c_span = trait_c_hir_id.map(|trait_c_hir_id| {
979979
// Add a label to the Span containing just the type of the const
980-
match tcx.hir().expect_trait_item_by_hir_id(trait_c_hir_id).node {
980+
match tcx.hir().expect_trait_item(trait_c_hir_id).node {
981981
TraitItemKind::Const(ref ty, _) => ty.span,
982982
_ => bug!("{:?} is not a trait const", trait_c),
983983
}

src/librustc_typeck/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
152152

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

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

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

168168
let method_sig = match impl_item.node {
169169
hir::ImplItemKind::Method(ref sig, _) => Some(sig),

src/librustc_typeck/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: hir::HirId) {
479479
}
480480

481481
fn convert_trait_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_item_id: hir::HirId) {
482-
let trait_item = tcx.hir().expect_trait_item_by_hir_id(trait_item_id);
482+
let trait_item = tcx.hir().expect_trait_item(trait_item_id);
483483
let def_id = tcx.hir().local_def_id_from_hir_id(trait_item.hir_id);
484484
tcx.generics_of(def_id);
485485

@@ -504,7 +504,7 @@ fn convert_impl_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_item_id: hir::H
504504
tcx.generics_of(def_id);
505505
tcx.type_of(def_id);
506506
tcx.predicates_of(def_id);
507-
if let hir::ImplItemKind::Method(..) = tcx.hir().expect_impl_item_by_hir_id(impl_item_id).node {
507+
if let hir::ImplItemKind::Method(..) = tcx.hir().expect_impl_item(impl_item_id).node {
508508
tcx.fn_sig(def_id);
509509
}
510510
}

0 commit comments

Comments
 (0)