Skip to content

Commit 21bf549

Browse files
committed
hir: remove NodeId from Block
1 parent 79c05cc commit 21bf549

File tree

24 files changed

+121
-135
lines changed

24 files changed

+121
-135
lines changed

src/librustc/hir/lowering.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -2816,10 +2816,9 @@ impl<'a> LoweringContext<'a> {
28162816
}
28172817
}
28182818

2819-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(b.id);
2819+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(b.id);
28202820

28212821
P(hir::Block {
2822-
id: node_id,
28232822
hir_id,
28242823
stmts: stmts.into(),
28252824
expr,
@@ -3900,11 +3899,10 @@ impl<'a> LoweringContext<'a> {
39003899
// Wrap the `if let` expr in a block.
39013900
let span = els.span;
39023901
let els = P(self.lower_expr(els));
3903-
let LoweredNodeId { node_id, hir_id } = self.next_id();
3902+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
39043903
let blk = P(hir::Block {
39053904
stmts: hir_vec![],
39063905
expr: Some(els),
3907-
id: node_id,
39083906
hir_id,
39093907
rules: hir::DefaultBlock,
39103908
span,
@@ -4978,12 +4976,11 @@ impl<'a> LoweringContext<'a> {
49784976
stmts: hir::HirVec<hir::Stmt>,
49794977
expr: Option<P<hir::Expr>>,
49804978
) -> hir::Block {
4981-
let LoweredNodeId { node_id, hir_id } = self.next_id();
4979+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
49824980

49834981
hir::Block {
49844982
stmts,
49854983
expr,
4986-
id: node_id,
49874984
hir_id,
49884985
rules: hir::DefaultBlock,
49894986
span,

src/librustc/hir/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,6 @@ pub struct Block {
828828
/// An expression at the end of the block
829829
/// without a semicolon, if any.
830830
pub expr: Option<P<Expr>>,
831-
pub id: NodeId,
832831
pub hir_id: HirId,
833832
/// Distinguishes between `unsafe { ... }` and `{ ... }`.
834833
pub rules: BlockCheckMode,

src/librustc/ich/impls_hir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ impl_stable_hash_for!(struct hir::MacroDef {
421421
impl_stable_hash_for!(struct hir::Block {
422422
stmts,
423423
expr,
424-
id -> _,
425424
hir_id -> _,
426425
rules,
427426
span,

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
629629
/// Indicates that the value of `blk` will be consumed, meaning either copied or moved
630630
/// depending on its type.
631631
fn walk_block(&mut self, blk: &hir::Block) {
632-
debug!("walk_block(blk.id={})", blk.id);
632+
debug!("walk_block(blk.hir_id={})", blk.hir_id);
633633

634634
for stmt in &blk.stmts {
635635
self.walk_stmt(stmt);

src/librustc/middle/liveness.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
950950
fn propagate_through_block(&mut self, blk: &hir::Block, succ: LiveNode)
951951
-> LiveNode {
952952
if blk.targeted_by_break {
953-
self.break_ln.insert(blk.id, succ);
953+
let node_id = self.ir.tcx.hir().hir_to_node_id(blk.hir_id);
954+
self.break_ln.insert(node_id, succ);
954955
}
955956
let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ);
956957
blk.stmts.iter().rev().fold(succ, |succ, stmt| {
@@ -1386,7 +1387,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
13861387
}
13871388
}
13881389
debug!("propagate_through_loop: using id for loop body {} {}",
1389-
expr.id, self.ir.tcx.hir().node_to_pretty_string(body.id));
1390+
expr.id, self.ir.tcx.hir().hir_to_pretty_string(body.hir_id));
13901391

13911392

13921393
self.break_ln.insert(expr.id, succ);

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ fn record_var_lifetime(visitor: &mut RegionResolutionVisitor<'_, '_>,
745745
}
746746

747747
fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk: &'tcx hir::Block) {
748-
debug!("resolve_block(blk.id={:?})", blk.id);
748+
debug!("resolve_block(blk.hir_id={:?})", blk.hir_id);
749749

750750
let prev_cx = visitor.cx;
751751

src/librustc/mir/interpret/error.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{fmt, env};
22

3+
use crate::hir;
34
use crate::hir::map::definitions::DefPathData;
45
use crate::mir;
56
use crate::ty::{self, Ty, layout};
@@ -14,7 +15,6 @@ use crate::ty::query::TyCtxtAt;
1415
use errors::DiagnosticBuilder;
1516

1617
use syntax_pos::{Pos, Span};
17-
use syntax::ast;
1818
use syntax::symbol::Symbol;
1919

2020
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@@ -50,7 +50,7 @@ pub struct ConstEvalErr<'tcx> {
5050
pub struct FrameInfo<'tcx> {
5151
pub call_site: Span, // this span is in the caller!
5252
pub instance: ty::Instance<'tcx>,
53-
pub lint_root: Option<ast::NodeId>,
53+
pub lint_root: Option<hir::HirId>,
5454
}
5555

5656
impl<'tcx> fmt::Display for FrameInfo<'tcx> {
@@ -98,7 +98,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
9898
pub fn report_as_lint(&self,
9999
tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
100100
message: &str,
101-
lint_root: ast::NodeId,
101+
lint_root: hir::HirId,
102102
) -> ErrorHandled {
103103
let lint = self.struct_generic(
104104
tcx,
@@ -118,7 +118,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
118118
&self,
119119
tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
120120
message: &str,
121-
lint_root: Option<ast::NodeId>,
121+
lint_root: Option<hir::HirId>,
122122
) -> Result<DiagnosticBuilder<'tcx>, ErrorHandled> {
123123
match self.error {
124124
EvalErrorKind::Layout(LayoutError::Unknown(_)) |
@@ -129,15 +129,15 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
129129
}
130130
trace!("reporting const eval failure at {:?}", self.span);
131131
let mut err = if let Some(lint_root) = lint_root {
132-
let node_id = self.stacktrace
132+
let hir_id = self.stacktrace
133133
.iter()
134134
.rev()
135135
.filter_map(|frame| frame.lint_root)
136136
.next()
137137
.unwrap_or(lint_root);
138-
tcx.struct_span_lint_node(
138+
tcx.struct_span_lint_hir(
139139
crate::rustc::lint::builtin::CONST_ERR,
140-
node_id,
140+
hir_id,
141141
tcx.span,
142142
message,
143143
)

src/librustc/mir/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pub enum Safety {
413413
/// Unsafe because of an unsafe fn
414414
FnUnsafe,
415415
/// Unsafe because of an `unsafe` block
416-
ExplicitUnsafe(ast::NodeId),
416+
ExplicitUnsafe(hir::HirId),
417417
}
418418

419419
impl_stable_hash_for!(struct Mir<'tcx> {
@@ -2098,8 +2098,8 @@ pub struct SourceScopeData {
20982098

20992099
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
21002100
pub struct SourceScopeLocalData {
2101-
/// A NodeId with lint levels equivalent to this scope's lint levels.
2102-
pub lint_root: ast::NodeId,
2101+
/// A HirId with lint levels equivalent to this scope's lint levels.
2102+
pub lint_root: hir::HirId,
21032103
/// The unsafe block that contains this node.
21042104
pub safety: Safety,
21052105
}
@@ -2849,8 +2849,8 @@ pub enum UnsafetyViolationKind {
28492849
General,
28502850
/// Permitted in const fn and regular fns.
28512851
GeneralAndConstFn,
2852-
ExternStatic(ast::NodeId),
2853-
BorrowPacked(ast::NodeId),
2852+
ExternStatic(hir::HirId),
2853+
BorrowPacked(hir::HirId),
28542854
}
28552855

28562856
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
@@ -2867,7 +2867,7 @@ pub struct UnsafetyCheckResult {
28672867
pub violations: Lrc<[UnsafetyViolation]>,
28682868
/// unsafe blocks in this function, along with whether they are used. This is
28692869
/// used for the "unused_unsafe" lint.
2870-
pub unsafe_blocks: Lrc<[(ast::NodeId, bool)]>,
2870+
pub unsafe_blocks: Lrc<[(hir::HirId, bool)]>,
28712871
}
28722872

28732873
/// The layout of generator state

src/librustc/traits/object_safety.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
use super::elaborate_predicates;
1212

13+
use crate::hir;
1314
use crate::hir::def_id::DefId;
1415
use crate::lint;
1516
use crate::traits::{self, Obligation, ObligationCause};
@@ -129,7 +130,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
129130
// It's also hard to get a use site span, so we use the method definition span.
130131
self.lint_node_note(
131132
lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY,
132-
ast::CRATE_NODE_ID,
133+
hir::CRATE_HIR_ID,
133134
*span,
134135
&format!("the trait `{}` cannot be made into an object",
135136
self.item_path_str(trait_def_id)),

src/librustc/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2859,11 +2859,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
28592859

28602860
pub fn lint_node_note<S: Into<MultiSpan>>(self,
28612861
lint: &'static Lint,
2862-
id: NodeId,
2862+
id: hir::HirId,
28632863
span: S,
28642864
msg: &str,
28652865
note: &str) {
2866-
let mut err = self.struct_span_lint_node(lint, id, span.into(), msg);
2866+
let mut err = self.struct_span_lint_hir(lint, id, span.into(), msg);
28672867
err.note(note);
28682868
err.emit()
28692869
}

src/librustc_driver/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> {
420420
}
421421
pprust_hir::AnnNode::Block(blk) => {
422422
s.s.space()?;
423-
s.synth_comment(format!("block node_id: {} hir local_id: {}",
424-
blk.id, blk.hir_id.local_id.as_u32()))
423+
s.synth_comment(format!("block hir_id: {} hir local_id: {}",
424+
blk.hir_id, blk.hir_id.local_id.as_u32()))
425425
}
426426
pprust_hir::AnnNode::Expr(expr) => {
427427
s.s.space()?;

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
301301
}
302302

303303
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
304-
tcx.struct_span_lint_node(
304+
tcx.struct_span_lint_hir(
305305
UNUSED_MUT,
306306
vsi[local_decl.source_info.scope].lint_root,
307307
span,

src/librustc_mir/build/block.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
206206
debug!("update_source_scope_for({:?}, {:?})", span, safety_mode);
207207
let new_unsafety = match safety_mode {
208208
BlockSafety::Safe => None,
209-
BlockSafety::ExplicitUnsafe(node_id) => {
209+
BlockSafety::ExplicitUnsafe(hir_id) => {
210210
assert_eq!(self.push_unsafe_count, 0);
211211
match self.unpushed_unsafe {
212212
Safety::Safe => {}
213213
_ => return
214214
}
215-
self.unpushed_unsafe = Safety::ExplicitUnsafe(node_id);
216-
Some(Safety::ExplicitUnsafe(node_id))
215+
self.unpushed_unsafe = Safety::ExplicitUnsafe(hir_id);
216+
Some(Safety::ExplicitUnsafe(hir_id))
217217
}
218218
BlockSafety::PushUnsafe => {
219219
self.push_unsafe_count += 1;

src/librustc_mir/build/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
7272
};
7373

7474
tcx.infer_ctxt().enter(|infcx| {
75-
let cx = Cx::new(&infcx, id);
75+
let fn_hir_id = tcx.hir().node_to_hir_id(id);
76+
let cx = Cx::new(&infcx, fn_hir_id);
7677
let mut mir = if cx.tables().tainted_by_errors {
7778
build::construct_error(cx, body_id)
7879
} else if cx.body_owner_kind.is_fn_or_closure() {
7980
// fetch the fully liberated fn signature (that is, all bound
8081
// types/lifetimes replaced)
81-
let fn_hir_id = tcx.hir().node_to_hir_id(id);
8282
let fn_sig = cx.tables().liberated_fn_sigs()[fn_hir_id].clone();
8383
let fn_def_id = tcx.hir().local_def_id(id);
8484

src/librustc_mir/build/scope.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
308308
debug!("in_scope(region_scope={:?}, block={:?})", region_scope, block);
309309
let source_scope = self.source_scope;
310310
let tcx = self.hir.tcx();
311-
if let LintLevel::Explicit(node_id) = lint_level {
311+
if let LintLevel::Explicit(current_hir_id) = lint_level {
312312
let same_lint_scopes = tcx.dep_graph.with_ignore(|| {
313313
let sets = tcx.lint_levels(LOCAL_CRATE);
314-
let parent_hir_id =
315-
tcx.hir().definitions().node_to_hir_id(
316-
self.source_scope_local_data[source_scope].lint_root
317-
);
318-
let current_hir_id =
319-
tcx.hir().definitions().node_to_hir_id(node_id);
320-
sets.lint_level_set(parent_hir_id) ==
321-
sets.lint_level_set(current_hir_id)
314+
let parent_hir_id = self.source_scope_local_data[source_scope].lint_root;
315+
sets.lint_level_set(parent_hir_id) == sets.lint_level_set(current_hir_id)
322316
});
323317

324318
if !same_lint_scopes {

src/librustc_mir/const_eval.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -663,11 +663,11 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
663663
// because any code that existed before validation could not have failed validation
664664
// thus preventing such a hard error from being a backwards compatibility hazard
665665
Some(Def::Const(_)) | Some(Def::AssociatedConst(_)) => {
666-
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
666+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
667667
err.report_as_lint(
668668
tcx.at(tcx.def_span(def_id)),
669669
"any use of this value will cause an error",
670-
node_id,
670+
hir_id,
671671
)
672672
},
673673
// promoting runtime code is only allowed to error if it references broken constants
@@ -683,7 +683,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
683683
err.report_as_lint(
684684
tcx.at(span),
685685
"reaching this expression at runtime will panic or abort",
686-
tcx.hir().as_local_node_id(def_id).unwrap(),
686+
tcx.hir().as_local_hir_id(def_id).unwrap(),
687687
)
688688
}
689689
// anything else (array lengths, enum initializers, constant patterns) are reported

src/librustc_mir/hair/cx/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block {
3030
hir::BlockCheckMode::DefaultBlock =>
3131
BlockSafety::Safe,
3232
hir::BlockCheckMode::UnsafeBlock(..) =>
33-
BlockSafety::ExplicitUnsafe(self.id),
33+
BlockSafety::ExplicitUnsafe(self.hir_id),
3434
hir::BlockCheckMode::PushUnsafeBlock(..) =>
3535
BlockSafety::PushUnsafe,
3636
hir::BlockCheckMode::PopUnsafeBlock(..) =>

src/librustc_mir/hair/cx/mod.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
2626
tcx: TyCtxt<'a, 'gcx, 'tcx>,
2727
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
2828

29-
pub root_lint_level: ast::NodeId,
29+
pub root_lint_level: hir::HirId,
3030
pub param_env: ty::ParamEnv<'gcx>,
3131

3232
/// Identity `Substs` for use with const-evaluation.
@@ -51,10 +51,10 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
5151

5252
impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
5353
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
54-
src_id: ast::NodeId) -> Cx<'a, 'gcx, 'tcx> {
54+
src_id: hir::HirId) -> Cx<'a, 'gcx, 'tcx> {
5555
let tcx = infcx.tcx;
56-
let src_def_id = tcx.hir().local_def_id(src_id);
57-
let body_owner_kind = tcx.hir().body_owner_kind(src_id);
56+
let src_def_id = tcx.hir().local_def_id_from_hir_id(src_id);
57+
let body_owner_kind = tcx.hir().body_owner_kind_by_hir_id(src_id);
5858

5959
let constness = match body_owner_kind {
6060
hir::BodyOwnerKind::Const |
@@ -63,7 +63,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
6363
hir::BodyOwnerKind::Fn => hir::Constness::NotConst,
6464
};
6565

66-
let attrs = tcx.hir().attrs(src_id);
66+
let attrs = tcx.hir().attrs_by_hir_id(src_id);
6767

6868
// Some functions always have overflow checks enabled,
6969
// however, they may not get codegen'd, depending on
@@ -204,7 +204,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
204204
});
205205

206206
if has_lint_level {
207-
LintLevel::Explicit(node_id)
207+
LintLevel::Explicit(hir_id)
208208
} else {
209209
LintLevel::Inherited
210210
}
@@ -237,7 +237,7 @@ impl UserAnnotatedTyHelpers<'gcx, 'tcx> for Cx<'_, 'gcx, 'tcx> {
237237
}
238238
}
239239

240-
fn lint_level_for_hir_id(tcx: TyCtxt<'_, '_, '_>, mut id: ast::NodeId) -> ast::NodeId {
240+
fn lint_level_for_hir_id(tcx: TyCtxt<'_, '_, '_>, mut id: hir::HirId) -> hir::HirId {
241241
// Right now we insert a `with_ignore` node in the dep graph here to
242242
// ignore the fact that `lint_levels` below depends on the entire crate.
243243
// For now this'll prevent false positives of recompiling too much when
@@ -249,11 +249,10 @@ fn lint_level_for_hir_id(tcx: TyCtxt<'_, '_, '_>, mut id: ast::NodeId) -> ast::N
249249
tcx.dep_graph.with_ignore(|| {
250250
let sets = tcx.lint_levels(LOCAL_CRATE);
251251
loop {
252-
let hir_id = tcx.hir().definitions().node_to_hir_id(id);
253-
if sets.lint_level_set(hir_id).is_some() {
252+
if sets.lint_level_set(id).is_some() {
254253
return id
255254
}
256-
let next = tcx.hir().get_parent_node(id);
255+
let next = tcx.hir().get_parent_node_by_hir_id(id);
257256
if next == id {
258257
bug!("lint traversal reached the root of the crate");
259258
}

0 commit comments

Comments
 (0)