Skip to content

Remove NodeId from hir::Block #58651

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2816,10 +2816,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 @@ -3900,11 +3899,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 @@ -4978,12 +4976,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
7 changes: 6 additions & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ impl serialize::UseSpecializedDecodable for HirId {
}
}

impl fmt::Display for HirId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}

// hack to ensure that we don't try to access the private parts of `ItemLocalId` in this module
mod item_local_id_inner {
use rustc_data_structures::indexed_vec::Idx;
Expand Down Expand Up @@ -822,7 +828,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 @@ -421,7 +421,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
Loading