Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NodeId from Block and Expr #58698

Closed
wants to merge 12 commits into from
9 changes: 3 additions & 6 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2804,10 +2804,9 @@ impl<'a> LoweringContext<'a> {
}
}

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

P(hir::Block {
id: node_id,
hir_id,
stmts: stmts.into(),
expr,
Expand Down Expand Up @@ -3887,11 +3886,10 @@ impl<'a> LoweringContext<'a> {
// Wrap the `if let` expr in a block.
let span = els.span;
let els = P(self.lower_expr(els));
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
let blk = P(hir::Block {
stmts: hir_vec![],
expr: Some(els),
id: node_id,
hir_id,
rules: hir::DefaultBlock,
span,
Expand Down Expand Up @@ -4965,12 +4963,11 @@ impl<'a> LoweringContext<'a> {
stmts: hir::HirVec<hir::Stmt>,
expr: Option<P<hir::Expr>>,
) -> hir::Block {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();

hir::Block {
stmts,
expr,
id: node_id,
hir_id,
rules: hir::DefaultBlock,
span,
Expand Down
1 change: 0 additions & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,6 @@ pub struct Block {
/// An expression at the end of the block
/// without a semicolon, if any.
pub expr: Option<P<Expr>>,
pub id: NodeId,
pub hir_id: HirId,
/// Distinguishes between `unsafe { ... }` and `{ ... }`.
pub rules: BlockCheckMode,
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ impl_stable_hash_for!(struct hir::MacroDef {
impl_stable_hash_for!(struct hir::Block {
stmts,
expr,
id -> _,
hir_id -> _,
rules,
span,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
/// Indicates that the value of `blk` will be consumed, meaning either copied or moved
/// depending on its type.
fn walk_block(&mut self, blk: &hir::Block) {
debug!("walk_block(blk.id={})", blk.id);
debug!("walk_block(blk.hir_id={})", blk.hir_id);

for stmt in &blk.stmts {
self.walk_stmt(stmt);
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn propagate_through_block(&mut self, blk: &hir::Block, succ: LiveNode)
-> LiveNode {
if blk.targeted_by_break {
self.break_ln.insert(blk.id, succ);
let node_id = self.ir.tcx.hir().hir_to_node_id(blk.hir_id);
self.break_ln.insert(node_id, succ);
}
let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ);
blk.stmts.iter().rev().fold(succ, |succ, stmt| {
Expand Down Expand Up @@ -1386,7 +1387,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
}
debug!("propagate_through_loop: using id for loop body {} {}",
expr.id, self.ir.tcx.hir().node_to_pretty_string(body.id));
expr.id, self.ir.tcx.hir().hir_to_pretty_string(body.hir_id));


self.break_ln.insert(expr.id, succ);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ fn record_var_lifetime(visitor: &mut RegionResolutionVisitor<'_, '_>,
}

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

let prev_cx = visitor.cx;

Expand Down
14 changes: 7 additions & 7 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{fmt, env};

use crate::hir;
use crate::hir::map::definitions::DefPathData;
use crate::mir;
use crate::ty::{self, Ty, layout};
Expand All @@ -14,7 +15,6 @@ use crate::ty::query::TyCtxtAt;
use errors::DiagnosticBuilder;

use syntax_pos::{Pos, Span};
use syntax::ast;
use syntax::symbol::Symbol;

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

impl<'tcx> fmt::Display for FrameInfo<'tcx> {
Expand Down Expand Up @@ -98,7 +98,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
pub fn report_as_lint(&self,
tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
message: &str,
lint_root: ast::NodeId,
lint_root: hir::HirId,
) -> ErrorHandled {
let lint = self.struct_generic(
tcx,
Expand All @@ -118,7 +118,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
&self,
tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
message: &str,
lint_root: Option<ast::NodeId>,
lint_root: Option<hir::HirId>,
) -> Result<DiagnosticBuilder<'tcx>, ErrorHandled> {
match self.error {
EvalErrorKind::Layout(LayoutError::Unknown(_)) |
Expand All @@ -129,15 +129,15 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
}
trace!("reporting const eval failure at {:?}", self.span);
let mut err = if let Some(lint_root) = lint_root {
let node_id = self.stacktrace
let hir_id = self.stacktrace
.iter()
.rev()
.filter_map(|frame| frame.lint_root)
.next()
.unwrap_or(lint_root);
tcx.struct_span_lint_node(
tcx.struct_span_lint_hir(
crate::rustc::lint::builtin::CONST_ERR,
node_id,
hir_id,
tcx.span,
message,
)
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ pub enum Safety {
/// Unsafe because of an unsafe fn
FnUnsafe,
/// Unsafe because of an `unsafe` block
ExplicitUnsafe(ast::NodeId),
ExplicitUnsafe(hir::HirId),
}

impl_stable_hash_for!(struct Mir<'tcx> {
Expand Down Expand Up @@ -2098,8 +2098,8 @@ pub struct SourceScopeData {

#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub struct SourceScopeLocalData {
/// A NodeId with lint levels equivalent to this scope's lint levels.
pub lint_root: ast::NodeId,
/// A HirId with lint levels equivalent to this scope's lint levels.
pub lint_root: hir::HirId,
/// The unsafe block that contains this node.
pub safety: Safety,
}
Expand Down Expand Up @@ -2849,8 +2849,8 @@ pub enum UnsafetyViolationKind {
General,
/// Permitted in const fn and regular fns.
GeneralAndConstFn,
ExternStatic(ast::NodeId),
BorrowPacked(ast::NodeId),
ExternStatic(hir::HirId),
BorrowPacked(hir::HirId),
}

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

/// The layout of generator state
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use super::elaborate_predicates;

use crate::hir;
use crate::hir::def_id::DefId;
use crate::lint;
use crate::traits::{self, Obligation, ObligationCause};
Expand Down Expand Up @@ -129,7 +130,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
// It's also hard to get a use site span, so we use the method definition span.
self.lint_node_note(
lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY,
ast::CRATE_NODE_ID,
hir::CRATE_HIR_ID,
*span,
&format!("the trait `{}` cannot be made into an object",
self.item_path_str(trait_def_id)),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2859,11 +2859,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

pub fn lint_node_note<S: Into<MultiSpan>>(self,
lint: &'static Lint,
id: NodeId,
id: hir::HirId,
span: S,
msg: &str,
note: &str) {
let mut err = self.struct_span_lint_node(lint, id, span.into(), msg);
let mut err = self.struct_span_lint_hir(lint, id, span.into(), msg);
err.note(note);
err.emit()
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> {
}
pprust_hir::AnnNode::Block(blk) => {
s.s.space()?;
s.synth_comment(format!("block node_id: {} hir local_id: {}",
blk.id, blk.hir_id.local_id.as_u32()))
s.synth_comment(format!("block hir_id: {} hir local_id: {}",
blk.hir_id, blk.hir_id.local_id.as_u32()))
}
pprust_hir::AnnNode::Expr(expr) => {
s.s.space()?;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
}

let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
tcx.struct_span_lint_node(
tcx.struct_span_lint_hir(
UNUSED_MUT,
vsi[local_decl.source_info.scope].lint_root,
span,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/build/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
debug!("update_source_scope_for({:?}, {:?})", span, safety_mode);
let new_unsafety = match safety_mode {
BlockSafety::Safe => None,
BlockSafety::ExplicitUnsafe(node_id) => {
BlockSafety::ExplicitUnsafe(hir_id) => {
assert_eq!(self.push_unsafe_count, 0);
match self.unpushed_unsafe {
Safety::Safe => {}
_ => return
}
self.unpushed_unsafe = Safety::ExplicitUnsafe(node_id);
Some(Safety::ExplicitUnsafe(node_id))
self.unpushed_unsafe = Safety::ExplicitUnsafe(hir_id);
Some(Safety::ExplicitUnsafe(hir_id))
}
BlockSafety::PushUnsafe => {
self.push_unsafe_count += 1;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
};

tcx.infer_ctxt().enter(|infcx| {
let cx = Cx::new(&infcx, id);
let fn_hir_id = tcx.hir().node_to_hir_id(id);
let cx = Cx::new(&infcx, fn_hir_id);
let mut mir = if cx.tables().tainted_by_errors {
build::construct_error(cx, body_id)
} else if cx.body_owner_kind.is_fn_or_closure() {
// fetch the fully liberated fn signature (that is, all bound
// types/lifetimes replaced)
let fn_hir_id = tcx.hir().node_to_hir_id(id);
let fn_sig = cx.tables().liberated_fn_sigs()[fn_hir_id].clone();
let fn_def_id = tcx.hir().local_def_id(id);

Expand Down
12 changes: 3 additions & 9 deletions src/librustc_mir/build/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
debug!("in_scope(region_scope={:?}, block={:?})", region_scope, block);
let source_scope = self.source_scope;
let tcx = self.hir.tcx();
if let LintLevel::Explicit(node_id) = lint_level {
if let LintLevel::Explicit(current_hir_id) = lint_level {
let same_lint_scopes = tcx.dep_graph.with_ignore(|| {
let sets = tcx.lint_levels(LOCAL_CRATE);
let parent_hir_id =
tcx.hir().definitions().node_to_hir_id(
self.source_scope_local_data[source_scope].lint_root
);
let current_hir_id =
tcx.hir().definitions().node_to_hir_id(node_id);
sets.lint_level_set(parent_hir_id) ==
sets.lint_level_set(current_hir_id)
let parent_hir_id = self.source_scope_local_data[source_scope].lint_root;
sets.lint_level_set(parent_hir_id) == sets.lint_level_set(current_hir_id)
});

if !same_lint_scopes {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,11 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
// because any code that existed before validation could not have failed validation
// thus preventing such a hard error from being a backwards compatibility hazard
Some(Def::Const(_)) | Some(Def::AssociatedConst(_)) => {
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
err.report_as_lint(
tcx.at(tcx.def_span(def_id)),
"any use of this value will cause an error",
node_id,
hir_id,
)
},
// promoting runtime code is only allowed to error if it references broken constants
Expand All @@ -683,7 +683,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
err.report_as_lint(
tcx.at(span),
"reaching this expression at runtime will panic or abort",
tcx.hir().as_local_node_id(def_id).unwrap(),
tcx.hir().as_local_hir_id(def_id).unwrap(),
)
}
// anything else (array lengths, enum initializers, constant patterns) are reported
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/hair/cx/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block {
hir::BlockCheckMode::DefaultBlock =>
BlockSafety::Safe,
hir::BlockCheckMode::UnsafeBlock(..) =>
BlockSafety::ExplicitUnsafe(self.id),
BlockSafety::ExplicitUnsafe(self.hir_id),
hir::BlockCheckMode::PushUnsafeBlock(..) =>
BlockSafety::PushUnsafe,
hir::BlockCheckMode::PopUnsafeBlock(..) =>
Expand Down
19 changes: 9 additions & 10 deletions src/librustc_mir/hair/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
tcx: TyCtxt<'a, 'gcx, 'tcx>,
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,

pub root_lint_level: ast::NodeId,
pub root_lint_level: hir::HirId,
pub param_env: ty::ParamEnv<'gcx>,

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

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

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

let attrs = tcx.hir().attrs(src_id);
let attrs = tcx.hir().attrs_by_hir_id(src_id);

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

if has_lint_level {
LintLevel::Explicit(node_id)
LintLevel::Explicit(hir_id)
} else {
LintLevel::Inherited
}
Expand Down Expand Up @@ -237,7 +237,7 @@ impl UserAnnotatedTyHelpers<'gcx, 'tcx> for Cx<'_, 'gcx, 'tcx> {
}
}

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