Skip to content

Commit 2a65cbe

Browse files
committed
Auto merge of #58915 - ljedrz:deprecate_nodeid_methods, r=Zoxc
HirIdification: almost there The next iteration of HirIdification (#57578). Replaces a bunch of `NodeId` method calls (mostly `as_local_node_id`) with `HirId` ones. Removes `NodeId` from: - [x] `PathSegment` - [x] `PatKind` - [x] `Destination` (replaces it with `HirId`) In addition this PR also removes `Visitor::visit_def_mention`, which doesn't seem to be doing anything.
2 parents b58a006 + 24fad4c commit 2a65cbe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+438
-488
lines changed

Diff for: src/librustc/cfg/construct.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
571571
match destination.target_id {
572572
Ok(loop_id) => {
573573
for b in &self.breakable_block_scopes {
574-
if b.block_expr_id == self.tcx.hir().node_to_hir_id(loop_id).local_id {
574+
if b.block_expr_id == loop_id.local_id {
575575
let scope = region::Scope {
576-
id: self.tcx.hir().node_to_hir_id(loop_id).local_id,
576+
id: loop_id.local_id,
577577
data: region::ScopeData::Node
578578
};
579579
return (scope, match scope_cf_kind {
@@ -583,9 +583,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
583583
}
584584
}
585585
for l in &self.loop_scopes {
586-
if l.loop_id == self.tcx.hir().node_to_hir_id(loop_id).local_id {
586+
if l.loop_id == loop_id.local_id {
587587
let scope = region::Scope {
588-
id: self.tcx.hir().node_to_hir_id(loop_id).local_id,
588+
id: loop_id.local_id,
589589
data: region::ScopeData::Node
590590
};
591591
return (scope, match scope_cf_kind {

Diff for: src/librustc/hir/intravisit.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
use syntax::ast::{Ident, Name, Attribute};
3535
use syntax_pos::Span;
3636
use crate::hir::*;
37-
use crate::hir::def::Def;
3837
use crate::hir::map::Map;
3938
use super::itemlikevisit::DeepVisitor;
4039

@@ -228,9 +227,6 @@ pub trait Visitor<'v> : Sized {
228227
fn visit_id(&mut self, _hir_id: HirId) {
229228
// Nothing to do.
230229
}
231-
fn visit_def_mention(&mut self, _def: Def) {
232-
// Nothing to do.
233-
}
234230
fn visit_name(&mut self, _span: Span, _name: Name) {
235231
// Nothing to do.
236232
}
@@ -494,13 +490,10 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
494490
visitor.visit_ty(typ);
495491
visitor.visit_generics(type_parameters)
496492
}
497-
ItemKind::Existential(ExistTy {ref generics, ref bounds, impl_trait_fn}) => {
493+
ItemKind::Existential(ExistTy { ref generics, ref bounds, impl_trait_fn: _ }) => {
498494
visitor.visit_id(item.hir_id);
499495
walk_generics(visitor, generics);
500496
walk_list!(visitor, visit_param_bound, bounds);
501-
if let Some(impl_trait_fn) = impl_trait_fn {
502-
visitor.visit_def_mention(Def::Fn(impl_trait_fn))
503-
}
504497
}
505498
ItemKind::Enum(ref enum_definition, ref type_parameters) => {
506499
visitor.visit_generics(type_parameters);
@@ -640,7 +633,6 @@ pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: Hir
640633
}
641634

642635
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
643-
visitor.visit_def_mention(path.def);
644636
for segment in &path.segments {
645637
visitor.visit_path_segment(path.span, segment);
646638
}
@@ -697,8 +689,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
697689
PatKind::Ref(ref subpattern, _) => {
698690
visitor.visit_pat(subpattern)
699691
}
700-
PatKind::Binding(_, canonical_id, _hir_id, ident, ref optional_subpattern) => {
701-
visitor.visit_def_mention(Def::Local(canonical_id));
692+
PatKind::Binding(_, _hir_id, ident, ref optional_subpattern) => {
702693
visitor.visit_ident(ident);
703694
walk_list!(visitor, visit_pat, optional_subpattern);
704695
}
@@ -1064,18 +1055,12 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10641055
ExprKind::Break(ref destination, ref opt_expr) => {
10651056
if let Some(ref label) = destination.label {
10661057
visitor.visit_label(label);
1067-
if let Ok(node_id) = destination.target_id {
1068-
visitor.visit_def_mention(Def::Label(node_id))
1069-
}
10701058
}
10711059
walk_list!(visitor, visit_expr, opt_expr);
10721060
}
10731061
ExprKind::Continue(ref destination) => {
10741062
if let Some(ref label) = destination.label {
10751063
visitor.visit_label(label);
1076-
if let Ok(node_id) = destination.target_id {
1077-
visitor.visit_def_mention(Def::Label(node_id))
1078-
}
10791064
}
10801065
}
10811066
ExprKind::Ret(ref optional_expression) => {

Diff for: src/librustc/hir/lowering.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ impl<'a> LoweringContext<'a> {
10681068
let target_id = match destination {
10691069
Some((id, _)) => {
10701070
if let Def::Label(loop_id) = self.expect_full_def(id) {
1071-
Ok(self.lower_node_id(loop_id).node_id)
1071+
Ok(self.lower_node_id(loop_id).hir_id)
10721072
} else {
10731073
Err(hir::LoopIdError::UnresolvedLabel)
10741074
}
@@ -1077,7 +1077,7 @@ impl<'a> LoweringContext<'a> {
10771077
self.loop_scopes
10781078
.last()
10791079
.cloned()
1080-
.map(|id| Ok(self.lower_node_id(id).node_id))
1080+
.map(|id| Ok(self.lower_node_id(id).hir_id))
10811081
.unwrap_or(Err(hir::LoopIdError::OutsideLoopScope))
10821082
.into()
10831083
}
@@ -1932,7 +1932,6 @@ impl<'a> LoweringContext<'a> {
19321932

19331933
hir::PathSegment::new(
19341934
segment.ident,
1935-
Some(id.node_id),
19361935
Some(id.hir_id),
19371936
Some(def),
19381937
generic_args,
@@ -3276,10 +3275,8 @@ impl<'a> LoweringContext<'a> {
32763275
debug!("renumber_segment_ids(path = {:?})", path);
32773276
let mut path = path.clone();
32783277
for seg in path.segments.iter_mut() {
3279-
if seg.id.is_some() {
3280-
let next_id = self.next_id();
3281-
seg.id = Some(next_id.node_id);
3282-
seg.hir_id = Some(next_id.hir_id);
3278+
if seg.hir_id.is_some() {
3279+
seg.hir_id = Some(self.next_id().hir_id);
32833280
}
32843281
}
32853282
path
@@ -3682,11 +3679,10 @@ impl<'a> LoweringContext<'a> {
36823679
Some(Def::Local(id)) => id,
36833680
_ => p.id,
36843681
};
3685-
let hir_id = self.lower_node_id(canonical_id).hir_id;
3682+
36863683
hir::PatKind::Binding(
36873684
self.lower_binding_mode(binding_mode),
3688-
canonical_id,
3689-
hir_id,
3685+
self.lower_node_id(canonical_id).hir_id,
36903686
ident,
36913687
sub.as_ref().map(|x| self.lower_pat(x)),
36923688
)
@@ -4568,12 +4564,13 @@ impl<'a> LoweringContext<'a> {
45684564
let thin_attrs = ThinVec::from(attrs);
45694565
let catch_scope = self.catch_scopes.last().map(|x| *x);
45704566
let ret_expr = if let Some(catch_node) = catch_scope {
4567+
let target_id = Ok(self.lower_node_id(catch_node).hir_id);
45714568
P(self.expr(
45724569
e.span,
45734570
hir::ExprKind::Break(
45744571
hir::Destination {
45754572
label: None,
4576-
target_id: Ok(catch_node),
4573+
target_id,
45774574
},
45784575
Some(from_err_expr),
45794576
),
@@ -4988,7 +4985,7 @@ impl<'a> LoweringContext<'a> {
49884985
(
49894986
P(hir::Pat {
49904987
hir_id,
4991-
node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None),
4988+
node: hir::PatKind::Binding(bm, hir_id, ident.with_span_pos(span), None),
49924989
span,
49934990
}),
49944991
node_id
@@ -5024,8 +5021,8 @@ impl<'a> LoweringContext<'a> {
50245021

50255022

50265023
for seg in path.segments.iter_mut() {
5027-
if let Some(id) = seg.id {
5028-
seg.id = Some(self.lower_node_id(id).node_id);
5024+
if seg.hir_id.is_some() {
5025+
seg.hir_id = Some(self.next_id().hir_id);
50295026
}
50305027
}
50315028
path

Diff for: src/librustc/hir/map/mod.rs

+32-46
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,10 @@ impl<'hir> Map<'hir> {
501501
}
502502

503503
/// Given a body owner's id, returns the `BodyId` associated with it.
504-
pub fn body_owned_by(&self, id: NodeId) -> BodyId {
505-
self.maybe_body_owned_by(id).unwrap_or_else(|| {
506-
span_bug!(self.span(id), "body_owned_by: {} has no associated body",
507-
self.node_to_string(id));
504+
pub fn body_owned_by(&self, id: HirId) -> BodyId {
505+
self.maybe_body_owned_by_by_hir_id(id).unwrap_or_else(|| {
506+
span_bug!(self.span_by_hir_id(id), "body_owned_by: {} has no associated body",
507+
self.hir_to_string(id));
508508
})
509509
}
510510

@@ -539,19 +539,19 @@ impl<'hir> Map<'hir> {
539539
self.body_owner_kind(node_id)
540540
}
541541

542-
pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
543-
match self.get(id) {
542+
pub fn ty_param_owner(&self, id: HirId) -> HirId {
543+
match self.get_by_hir_id(id) {
544544
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => id,
545-
Node::GenericParam(_) => self.get_parent_node(id),
546-
_ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id))
545+
Node::GenericParam(_) => self.get_parent_node_by_hir_id(id),
546+
_ => bug!("ty_param_owner: {} not a type parameter", self.hir_to_string(id))
547547
}
548548
}
549549

550-
pub fn ty_param_name(&self, id: NodeId) -> Name {
551-
match self.get(id) {
550+
pub fn ty_param_name(&self, id: HirId) -> Name {
551+
match self.get_by_hir_id(id) {
552552
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => keywords::SelfUpper.name(),
553553
Node::GenericParam(param) => param.name.ident().name,
554-
_ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)),
554+
_ => bug!("ty_param_name: {} not a type parameter", self.hir_to_string(id)),
555555
}
556556
}
557557

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

@@ -1016,7 +1002,7 @@ impl<'hir> Map<'hir> {
10161002
Node::Field(f) => f.ident.name,
10171003
Node::Lifetime(lt) => lt.name.ident().name,
10181004
Node::GenericParam(param) => param.name.ident().name,
1019-
Node::Binding(&Pat { node: PatKind::Binding(_, _, _, l, _), .. }) => l.name,
1005+
Node::Binding(&Pat { node: PatKind::Binding(_, _, l, _), .. }) => l.name,
10201006
Node::StructCtor(_) => self.name(self.get_parent(id)),
10211007
_ => bug!("no name for {}", self.node_to_string(id))
10221008
}

Diff for: src/librustc/hir/mod.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ pub struct PathSegment {
328328
// therefore will not have 'jump to def' in IDEs, but otherwise will not be
329329
// affected. (In general, we don't bother to get the defs for synthesized
330330
// segments, only for segments which have come from the AST).
331-
pub id: Option<NodeId>,
332331
pub hir_id: Option<HirId>,
333332
pub def: Option<Def>,
334333

@@ -351,7 +350,6 @@ impl PathSegment {
351350
pub fn from_ident(ident: Ident) -> PathSegment {
352351
PathSegment {
353352
ident,
354-
id: None,
355353
hir_id: None,
356354
def: None,
357355
infer_types: true,
@@ -361,15 +359,13 @@ impl PathSegment {
361359

362360
pub fn new(
363361
ident: Ident,
364-
id: Option<NodeId>,
365362
hir_id: Option<HirId>,
366363
def: Option<Def>,
367364
args: GenericArgs,
368365
infer_types: bool,
369366
) -> Self {
370367
PathSegment {
371368
ident,
372-
id,
373369
hir_id,
374370
def,
375371
infer_types,
@@ -941,10 +937,10 @@ pub enum PatKind {
941937
Wild,
942938

943939
/// A fresh binding `ref mut binding @ OPT_SUBPATTERN`.
944-
/// The `NodeId` is the canonical ID for the variable being bound,
940+
/// The `HirId` is the canonical ID for the variable being bound,
945941
/// (e.g., in `Ok(x) | Err(x)`, both `x` use the same canonical ID),
946942
/// which is the pattern ID of the first `x`.
947-
Binding(BindingAnnotation, NodeId, HirId, Ident, Option<P<Pat>>),
943+
Binding(BindingAnnotation, HirId, Ident, Option<P<Pat>>),
948944

949945
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
950946
/// The `bool` is `true` in the presence of a `..`.
@@ -1623,7 +1619,7 @@ pub struct Destination {
16231619

16241620
// These errors are caught and then reported during the diagnostics pass in
16251621
// librustc_passes/loops.rs
1626-
pub target_id: Result<NodeId, LoopIdError>,
1622+
pub target_id: Result<HirId, LoopIdError>,
16271623
}
16281624

16291625
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]

0 commit comments

Comments
 (0)