Skip to content

Commit adb2bb6

Browse files
authored
Rollup merge of rust-lang#58167 - ljedrz:HirIdify_body_id, r=Zoxc
HirId-ify hir::BodyId Another step towards rust-lang#57578.
2 parents 78c60bb + eac43cc commit adb2bb6

File tree

35 files changed

+175
-147
lines changed

35 files changed

+175
-147
lines changed

src/librustc/hir/map/mod.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ impl<'hir> Entry<'hir> {
127127
}
128128
}
129129

130-
fn is_body_owner(self, node_id: NodeId) -> bool {
130+
fn is_body_owner(self, hir_id: HirId) -> bool {
131131
match self.associated_body() {
132-
Some(b) => b.node_id == node_id,
132+
Some(b) => b.hir_id == hir_id,
133133
None => false,
134134
}
135135
}
@@ -438,7 +438,7 @@ impl<'hir> Map<'hir> {
438438
}
439439

440440
pub fn body(&self, id: BodyId) -> &'hir Body {
441-
self.read(id.node_id);
441+
self.read_by_hir_id(id.hir_id);
442442

443443
// N.B., intentionally bypass `self.forest.krate()` so that we
444444
// do not trigger a read of the whole krate here
@@ -462,9 +462,10 @@ impl<'hir> Map<'hir> {
462462
/// Returns the `NodeId` that corresponds to the definition of
463463
/// which this is the body of, i.e., a `fn`, `const` or `static`
464464
/// item (possibly associated), a closure, or a `hir::AnonConst`.
465-
pub fn body_owner(&self, BodyId { node_id }: BodyId) -> NodeId {
465+
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> NodeId {
466+
let node_id = self.hir_to_node_id(hir_id);
466467
let parent = self.get_parent_node(node_id);
467-
assert!(self.map[parent.as_usize()].map_or(false, |e| e.is_body_owner(node_id)));
468+
assert!(self.map[parent.as_usize()].map_or(false, |e| e.is_body_owner(hir_id)));
468469
parent
469470
}
470471

@@ -488,6 +489,12 @@ impl<'hir> Map<'hir> {
488489
}
489490
}
490491

492+
// FIXME(@ljedrz): replace the NodeId variant
493+
pub fn maybe_body_owned_by_by_hir_id(&self, id: HirId) -> Option<BodyId> {
494+
let node_id = self.hir_to_node_id(id);
495+
self.maybe_body_owned_by(node_id)
496+
}
497+
491498
/// Given a body owner's id, returns the `BodyId` associated with it.
492499
pub fn body_owned_by(&self, id: NodeId) -> BodyId {
493500
self.maybe_body_owned_by(id).unwrap_or_else(|| {
@@ -521,6 +528,12 @@ impl<'hir> Map<'hir> {
521528
}
522529
}
523530

531+
// FIXME(@ljedrz): replace the NodeId variant
532+
pub fn body_owner_kind_by_hir_id(&self, id: HirId) -> BodyOwnerKind {
533+
let node_id = self.hir_to_node_id(id);
534+
self.body_owner_kind(node_id)
535+
}
536+
524537
pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
525538
match self.get(id) {
526539
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => id,
@@ -837,6 +850,12 @@ impl<'hir> Map<'hir> {
837850
self.local_def_id(self.get_module_parent_node(id))
838851
}
839852

853+
// FIXME(@ljedrz): replace the NodeId variant
854+
pub fn get_module_parent_by_hir_id(&self, id: HirId) -> DefId {
855+
let node_id = self.hir_to_node_id(id);
856+
self.get_module_parent(node_id)
857+
}
858+
840859
/// Returns the `NodeId` of `id`'s nearest module parent, or `id` itself if no
841860
/// module parent is in this map.
842861
pub fn get_module_parent_node(&self, id: NodeId) -> NodeId {

src/librustc/hir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub mod print;
7272
/// the `local_id` part of the `HirId` changing, which is a very useful property in
7373
/// incremental compilation where we have to persist things through changes to
7474
/// the code base.
75-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
75+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
7676
pub struct HirId {
7777
pub owner: DefIndex,
7878
pub local_id: ItemLocalId,
@@ -1234,7 +1234,7 @@ pub enum UnsafeSource {
12341234

12351235
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug)]
12361236
pub struct BodyId {
1237-
pub node_id: NodeId,
1237+
pub hir_id: HirId,
12381238
}
12391239

12401240
/// The body of a function, closure, or constant value. In the case of
@@ -1268,7 +1268,7 @@ pub struct Body {
12681268
impl Body {
12691269
pub fn id(&self) -> BodyId {
12701270
BodyId {
1271-
node_id: self.value.id
1271+
hir_id: self.value.hir_id,
12721272
}
12731273
}
12741274
}

src/librustc/ich/impls_hir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,8 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::BodyId {
989989
fn to_stable_hash_key(&self,
990990
hcx: &StableHashingContext<'a>)
991991
-> (DefPathHash, hir::ItemLocalId) {
992-
let hir::BodyId { node_id } = *self;
993-
node_id.to_stable_hash_key(hcx)
992+
let hir::BodyId { hir_id } = *self;
993+
hir_id.to_stable_hash_key(hcx)
994994
}
995995
}
996996

src/librustc/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
105105
};
106106

107107
if let Some(body_id) = body_id {
108-
let expr = self.tcx.hir().expect_expr(body_id.node_id);
108+
let expr = self.tcx.hir().expect_expr_by_hir_id(body_id.hir_id);
109109
local_visitor.visit_expr(expr);
110110
}
111111

src/librustc/infer/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use self::SubregionOrigin::*;
77
pub use self::ValuePairs::*;
88
pub use crate::ty::IntVarValue;
99

10+
use crate::hir;
1011
use crate::hir::def_id::DefId;
1112
use crate::infer::canonical::{Canonical, CanonicalVarValues};
1213
use crate::middle::free_region::RegionRelations;
@@ -203,7 +204,7 @@ pub struct InferCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
203204
// for each body-id in this map, which will process the
204205
// obligations within. This is expected to be done 'late enough'
205206
// that all type inference variables have been bound and so forth.
206-
pub region_obligations: RefCell<Vec<(ast::NodeId, RegionObligation<'tcx>)>>,
207+
pub region_obligations: RefCell<Vec<(hir::HirId, RegionObligation<'tcx>)>>,
207208

208209
/// What is the innermost universe we have created? Starts out as
209210
/// `UniverseIndex::root()` but grows from there as we enter
@@ -1433,7 +1434,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14331434
pub fn partially_normalize_associated_types_in<T>(
14341435
&self,
14351436
span: Span,
1436-
body_id: ast::NodeId,
1437+
body_id: hir::HirId,
14371438
param_env: ty::ParamEnv<'tcx>,
14381439
value: &T,
14391440
) -> InferOk<'tcx, T>

src/librustc/infer/opaque_types/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
9898
pub fn instantiate_opaque_types<T: TypeFoldable<'tcx>>(
9999
&self,
100100
parent_def_id: DefId,
101-
body_id: ast::NodeId,
101+
body_id: hir::HirId,
102102
param_env: ty::ParamEnv<'tcx>,
103103
value: &T,
104104
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> {
@@ -632,7 +632,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx>
632632
struct Instantiator<'a, 'gcx: 'tcx, 'tcx: 'a> {
633633
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
634634
parent_def_id: DefId,
635-
body_id: ast::NodeId,
635+
body_id: hir::HirId,
636636
param_env: ty::ParamEnv<'tcx>,
637637
opaque_types: OpaqueTypeMap<'tcx>,
638638
obligations: Vec<PredicateObligation<'tcx>>,

src/librustc/infer/outlives/env.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::infer::outlives::free_region_map::FreeRegionMap;
22
use crate::infer::{GenericKind, InferCtxt};
3+
use crate::hir;
34
use rustc_data_structures::fx::FxHashMap;
4-
use syntax::ast;
55
use syntax_pos::Span;
66
use crate::traits::query::outlives_bounds::{self, OutlivesBound};
77
use crate::ty::{self, Ty};
@@ -55,7 +55,7 @@ pub struct OutlivesEnvironment<'tcx> {
5555
// results when proving outlives obligations like `T: 'x` later
5656
// (e.g., if `T: 'x` must be proven within the body B1, then we
5757
// know it is true if either `'a: 'x` or `'b: 'x`).
58-
region_bound_pairs_map: FxHashMap<ast::NodeId, RegionBoundPairs<'tcx>>,
58+
region_bound_pairs_map: FxHashMap<hir::HirId, RegionBoundPairs<'tcx>>,
5959

6060
// Used to compute `region_bound_pairs_map`: contains the set of
6161
// in-scope region-bound pairs thus far.
@@ -87,7 +87,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> {
8787
}
8888

8989
/// Borrows current value of the `region_bound_pairs`.
90-
pub fn region_bound_pairs_map(&self) -> &FxHashMap<ast::NodeId, RegionBoundPairs<'tcx>> {
90+
pub fn region_bound_pairs_map(&self) -> &FxHashMap<hir::HirId, RegionBoundPairs<'tcx>> {
9191
&self.region_bound_pairs_map
9292
}
9393

@@ -162,7 +162,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> {
162162
&mut self,
163163
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
164164
fn_sig_tys: &[Ty<'tcx>],
165-
body_id: ast::NodeId,
165+
body_id: hir::HirId,
166166
span: Span,
167167
) {
168168
debug!("add_implied_bounds()");
@@ -176,7 +176,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> {
176176
}
177177

178178
/// Save the current set of region-bound pairs under the given `body_id`.
179-
pub fn save_implied_bounds(&mut self, body_id: ast::NodeId) {
179+
pub fn save_implied_bounds(&mut self, body_id: hir::HirId) {
180180
let old = self.region_bound_pairs_map.insert(
181181
body_id,
182182
self.region_bound_pairs_accum.clone(),

src/librustc/infer/outlives/obligations.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use crate::infer::outlives::env::RegionBoundPairs;
6363
use crate::infer::outlives::verify::VerifyBoundCx;
6464
use crate::infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound};
6565
use rustc_data_structures::fx::FxHashMap;
66-
use syntax::ast;
66+
use crate::hir;
6767
use crate::traits::ObligationCause;
6868
use crate::ty::outlives::Component;
6969
use crate::ty::{self, Region, Ty, TyCtxt, TypeFoldable};
@@ -76,7 +76,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
7676
/// information).
7777
pub fn register_region_obligation(
7878
&self,
79-
body_id: ast::NodeId,
79+
body_id: hir::HirId,
8080
obligation: RegionObligation<'tcx>,
8181
) {
8282
debug!(
@@ -110,7 +110,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
110110
}
111111

112112
/// Trait queries just want to pass back type obligations "as is"
113-
pub fn take_registered_region_obligations(&self) -> Vec<(ast::NodeId, RegionObligation<'tcx>)> {
113+
pub fn take_registered_region_obligations(&self) -> Vec<(hir::HirId, RegionObligation<'tcx>)> {
114114
::std::mem::replace(&mut *self.region_obligations.borrow_mut(), vec![])
115115
}
116116

@@ -149,7 +149,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
149149
/// processed.
150150
pub fn process_registered_region_obligations(
151151
&self,
152-
region_bound_pairs_map: &FxHashMap<ast::NodeId, RegionBoundPairs<'tcx>>,
152+
region_bound_pairs_map: &FxHashMap<hir::HirId, RegionBoundPairs<'tcx>>,
153153
implicit_region_bound: Option<ty::Region<'tcx>>,
154154
param_env: ty::ParamEnv<'tcx>,
155155
) {

src/librustc/traits/auto_trait.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
202202
full_env,
203203
ty,
204204
trait_did,
205-
ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID),
205+
ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID),
206206
);
207207
fulfill.select_all_or_error(&infcx).unwrap_or_else(|e| {
208208
panic!(
@@ -315,7 +315,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
315315
user_env.caller_bounds.iter().cloned().collect();
316316

317317
let mut new_env = param_env.clone();
318-
let dummy_cause = ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID);
318+
let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);
319319

320320
while let Some(pred) = predicates.pop_front() {
321321
infcx.clear_caches();
@@ -669,7 +669,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
669669
select: &mut SelectionContext<'c, 'd, 'cx>,
670670
only_projections: bool,
671671
) -> bool {
672-
let dummy_cause = ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID);
672+
let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);
673673

674674
for (obligation, mut predicate) in nested
675675
.map(|o| (o.clone(), o.predicate.clone()))

src/librustc/traits/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub struct ObligationCause<'tcx> {
132132
/// (in particular, closures can add new assumptions). See the
133133
/// field `region_obligations` of the `FulfillmentContext` for more
134134
/// information.
135-
pub body_id: ast::NodeId,
135+
pub body_id: hir::HirId,
136136

137137
pub code: ObligationCauseCode<'tcx>
138138
}
@@ -654,7 +654,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'gcx, 'tcx>(
654654
};
655655
let obligation = Obligation {
656656
param_env,
657-
cause: ObligationCause::misc(span, ast::DUMMY_NODE_ID),
657+
cause: ObligationCause::misc(span, hir::DUMMY_HIR_ID),
658658
recursion_depth: 0,
659659
predicate: trait_ref.to_predicate(),
660660
};
@@ -677,7 +677,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'gcx, 'tcx>(
677677
// We can use a dummy node-id here because we won't pay any mind
678678
// to region obligations that arise (there shouldn't really be any
679679
// anyhow).
680-
let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);
680+
let cause = ObligationCause::misc(span, hir::DUMMY_HIR_ID);
681681

682682
fulfill_cx.register_bound(infcx, param_env, ty, def_id, cause);
683683

@@ -1057,7 +1057,7 @@ impl<'tcx,O> Obligation<'tcx,O> {
10571057
}
10581058

10591059
pub fn misc(span: Span,
1060-
body_id: ast::NodeId,
1060+
body_id: hir::HirId,
10611061
param_env: ty::ParamEnv<'tcx>,
10621062
trait_ref: O)
10631063
-> Obligation<'tcx, O> {
@@ -1075,18 +1075,18 @@ impl<'tcx,O> Obligation<'tcx,O> {
10751075
impl<'tcx> ObligationCause<'tcx> {
10761076
#[inline]
10771077
pub fn new(span: Span,
1078-
body_id: ast::NodeId,
1078+
body_id: hir::HirId,
10791079
code: ObligationCauseCode<'tcx>)
10801080
-> ObligationCause<'tcx> {
1081-
ObligationCause { span: span, body_id: body_id, code: code }
1081+
ObligationCause { span, body_id, code }
10821082
}
10831083

1084-
pub fn misc(span: Span, body_id: ast::NodeId) -> ObligationCause<'tcx> {
1085-
ObligationCause { span: span, body_id: body_id, code: MiscObligation }
1084+
pub fn misc(span: Span, body_id: hir::HirId) -> ObligationCause<'tcx> {
1085+
ObligationCause { span, body_id, code: MiscObligation }
10861086
}
10871087

10881088
pub fn dummy() -> ObligationCause<'tcx> {
1089-
ObligationCause { span: DUMMY_SP, body_id: ast::CRATE_NODE_ID, code: MiscObligation }
1089+
ObligationCause { span: DUMMY_SP, body_id: hir::CRATE_HIR_ID, code: MiscObligation }
10901090
}
10911091
}
10921092

src/librustc/traits/query/outlives_bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::infer::InferCtxt;
22
use crate::infer::canonical::OriginalQueryValues;
3-
use syntax::ast;
3+
use crate::hir;
44
use syntax::source_map::Span;
55
use crate::traits::{FulfillmentContext, ObligationCause, TraitEngine, TraitEngineExt};
66
use crate::traits::query::NoSolution;
@@ -89,7 +89,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
8989
pub fn implied_outlives_bounds(
9090
&self,
9191
param_env: ty::ParamEnv<'tcx>,
92-
body_id: ast::NodeId,
92+
body_id: hir::HirId,
9393
ty: Ty<'tcx>,
9494
span: Span,
9595
) -> Vec<OutlivesBound<'tcx>> {

0 commit comments

Comments
 (0)