diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index d55f62d3e1a59..e39b180b75ed4 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -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, @@ -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, @@ -4978,12 +4976,11 @@ impl<'a> LoweringContext<'a> { stmts: hir::HirVec, expr: Option>, ) -> 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, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index d0b92587b59f0..cbc2bf810d121 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -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; @@ -822,7 +828,6 @@ pub struct Block { /// An expression at the end of the block /// without a semicolon, if any. pub expr: Option>, - pub id: NodeId, pub hir_id: HirId, /// Distinguishes between `unsafe { ... }` and `{ ... }`. pub rules: BlockCheckMode, diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 727c441b0e8db..9653a3b9cfbcf 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -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, diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 8da20ba426663..29cb40a9a6731 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -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); diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 03e16494b0386..8cbc4bff3e15b 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -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| { @@ -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); diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index fd188b33d7e1f..3499138fb7915 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -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; diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 29beabdb2abdf..c4e1860bd8333 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -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}; @@ -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)] @@ -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, + pub lint_root: Option, } impl<'tcx> fmt::Display for FrameInfo<'tcx> { @@ -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, @@ -118,7 +118,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { &self, tcx: TyCtxtAt<'a, 'gcx, 'tcx>, message: &str, - lint_root: Option, + lint_root: Option, ) -> Result, ErrorHandled> { match self.error { EvalErrorKind::Layout(LayoutError::Unknown(_)) | @@ -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, ) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 3513d652b5346..f0bf31f47f598 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -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> { @@ -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, } @@ -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)] @@ -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 diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index b31aa5998f365..5c24b0ebfe05e 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -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}; @@ -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)), diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 6bb3222512565..a71c0d4ab963d 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2859,11 +2859,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn lint_node_note>(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() } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 4caf2ec676f07..b0b5594b93eac 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -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()?; diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index f7d079c5494ef..7fce5f92e0cae 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -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, diff --git a/src/librustc_mir/build/block.rs b/src/librustc_mir/build/block.rs index 7d93e131a6ca9..499ec1900473f 100644 --- a/src/librustc_mir/build/block.rs +++ b/src/librustc_mir/build/block.rs @@ -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; diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 64ab491cbd5b0..5d8dc6ef8e454 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -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); diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index 3392495f7a11b..71acf747d0856 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -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 { diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 7be7f4b439289..1eb129c6fc3ac 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -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 @@ -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 diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 4a64ddb73fc2e..b63bf4bc24684 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -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(..) => diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index cd937d702fd77..d24a70528ec4d 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -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. @@ -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 | @@ -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 @@ -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 } @@ -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 @@ -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"); } diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index e615b009cf370..22e44ae85a463 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -28,7 +28,7 @@ mod util; #[derive(Copy, Clone, Debug)] pub enum LintLevel { Inherited, - Explicit(ast::NodeId) + Explicit(hir::HirId) } impl LintLevel { @@ -54,7 +54,7 @@ pub struct Block<'tcx> { #[derive(Copy, Clone, Debug)] pub enum BlockSafety { Safe, - ExplicitUnsafe(ast::NodeId), + ExplicitUnsafe(hir::HirId), PushUnsafe, PopUnsafe } diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 66529e579835d..3ed63d749cd35 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -12,7 +12,6 @@ use rustc::lint::builtin::{SAFE_EXTERN_STATICS, SAFE_PACKED_BORROWS, UNUSED_UNSA use rustc::mir::*; use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext}; -use syntax::ast; use syntax::symbol::Symbol; use std::ops::Bound; @@ -29,8 +28,8 @@ pub struct UnsafetyChecker<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, /// Mark an `unsafe` block as used, so we don't lint it. - used_unsafe: FxHashSet, - inherited_blocks: Vec<(ast::NodeId, bool)>, + used_unsafe: FxHashSet, + inherited_blocks: Vec<(hir::HirId, bool)>, } impl<'a, 'gcx, 'tcx> UnsafetyChecker<'a, 'tcx> { @@ -349,7 +348,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { fn register_violations(&mut self, violations: &[UnsafetyViolation], - unsafe_blocks: &[(ast::NodeId, bool)]) { + unsafe_blocks: &[(hir::HirId, bool)]) { let safety = self.source_scope_local_data[self.source_info.scope].safety; let within_unsafe = match safety { // `unsafe` blocks are required in safe code @@ -375,10 +374,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { } // `unsafe` function bodies allow unsafe without additional unsafe blocks Safety::BuiltinUnsafe | Safety::FnUnsafe => true, - Safety::ExplicitUnsafe(node_id) => { + Safety::ExplicitUnsafe(hir_id) => { // mark unsafe block as used if there are any unsafe operations inside if !violations.is_empty() { - self.used_unsafe.insert(node_id); + self.used_unsafe.insert(hir_id); } // only some unsafety is allowed in const fn if self.min_const_fn { @@ -405,8 +404,8 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { true } }; - self.inherited_blocks.extend(unsafe_blocks.iter().map(|&(node_id, is_used)| { - (node_id, is_used && !within_unsafe) + self.inherited_blocks.extend(unsafe_blocks.iter().map(|&(hir_id, is_used)| { + (hir_id, is_used && !within_unsafe) })); } fn check_mut_borrowing_layout_constrained_field( @@ -467,8 +466,8 @@ pub(crate) fn provide(providers: &mut Providers<'_>) { } struct UnusedUnsafeVisitor<'a> { - used_unsafe: &'a FxHashSet, - unsafe_blocks: &'a mut Vec<(ast::NodeId, bool)>, + used_unsafe: &'a FxHashSet, + unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>, } impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> { @@ -482,19 +481,19 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> { hir::intravisit::walk_block(self, block); if let hir::UnsafeBlock(hir::UserProvided) = block.rules { - self.unsafe_blocks.push((block.id, self.used_unsafe.contains(&block.id))); + self.unsafe_blocks.push((block.hir_id, self.used_unsafe.contains(&block.hir_id))); } } } fn check_unused_unsafe<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, - used_unsafe: &FxHashSet, - unsafe_blocks: &'a mut Vec<(ast::NodeId, bool)>) + used_unsafe: &FxHashSet, + unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>) { let body_id = - tcx.hir().as_local_node_id(def_id).and_then(|node_id| { - tcx.hir().maybe_body_owned_by(node_id) + tcx.hir().as_local_hir_id(def_id).and_then(|hir_id| { + tcx.hir().maybe_body_owned_by_by_hir_id(hir_id) }); let body_id = match body_id { @@ -574,18 +573,18 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D &message); } -/// Returns the `NodeId` for an enclosing scope that is also `unsafe`. +/// Returns the `HirId` for an enclosing scope that is also `unsafe`. fn is_enclosed(tcx: TyCtxt<'_, '_, '_>, - used_unsafe: &FxHashSet, - id: ast::NodeId) -> Option<(String, ast::NodeId)> { - let parent_id = tcx.hir().get_parent_node(id); + used_unsafe: &FxHashSet, + id: hir::HirId) -> Option<(String, hir::HirId)> { + let parent_id = tcx.hir().get_parent_node_by_hir_id(id); if parent_id != id { if used_unsafe.contains(&parent_id) { Some(("block".to_string(), parent_id)) } else if let Some(Node::Item(&hir::Item { node: hir::ItemKind::Fn(_, header, _, _), .. - })) = tcx.hir().find(parent_id) { + })) = tcx.hir().find_by_hir_id(parent_id) { match header.unsafety { hir::Unsafety::Unsafe => Some(("fn".to_string(), parent_id)), hir::Unsafety::Normal => None, @@ -599,14 +598,14 @@ fn is_enclosed(tcx: TyCtxt<'_, '_, '_>, } fn report_unused_unsafe(tcx: TyCtxt<'_, '_, '_>, - used_unsafe: &FxHashSet, - id: ast::NodeId) { - let span = tcx.sess.source_map().def_span(tcx.hir().span(id)); + used_unsafe: &FxHashSet, + id: hir::HirId) { + let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id)); let msg = "unnecessary `unsafe` block"; - let mut db = tcx.struct_span_lint_node(UNUSED_UNSAFE, id, span, msg); + let mut db = tcx.struct_span_lint_hir(UNUSED_UNSAFE, id, span, msg); db.span_label(span, msg); if let Some((kind, id)) = is_enclosed(tcx, used_unsafe, id) { - db.span_label(tcx.sess.source_map().def_span(tcx.hir().span(id)), + db.span_label(tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id)), format!("because it's nested under this `unsafe` {}", kind)); } db.emit(); @@ -655,20 +654,20 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { .note(&details.as_str()[..]) .emit(); } - UnsafetyViolationKind::ExternStatic(lint_node_id) => { + UnsafetyViolationKind::ExternStatic(lint_hir_id) => { tcx.lint_node_note(SAFE_EXTERN_STATICS, - lint_node_id, + lint_hir_id, source_info.span, &format!("{} is unsafe and requires unsafe function or block \ (error E0133)", &description.as_str()[..]), &details.as_str()[..]); } - UnsafetyViolationKind::BorrowPacked(lint_node_id) => { + UnsafetyViolationKind::BorrowPacked(lint_hir_id) => { if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) { tcx.unsafe_derive_on_repr_packed(impl_def_id); } else { tcx.lint_node_note(SAFE_PACKED_BORROWS, - lint_node_id, + lint_hir_id, source_info.span, &format!("{} is unsafe and requires unsafe function or block \ (error E0133)", &description.as_str()[..]), @@ -679,7 +678,7 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { } let mut unsafe_blocks: Vec<_> = unsafe_blocks.into_iter().collect(); - unsafe_blocks.sort(); + unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_to_node_id(*hir_id)); let used_unsafe: FxHashSet<_> = unsafe_blocks.iter() .flat_map(|&&(id, used)| if used { Some(id) } else { None }) .collect(); diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 7da00c4ea0c36..24fe7d43883fe 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -430,10 +430,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { } else { "left" }; - let node_id = source_scope_local_data[source_info.scope].lint_root; - self.tcx.lint_node( + let hir_id = source_scope_local_data[source_info.scope].lint_root; + self.tcx.lint_hir( ::rustc::lint::builtin::EXCEEDING_BITSHIFTS, - node_id, + hir_id, span, &format!("attempt to shift {} with overflow", dir)); return None; diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 4071b5902b030..c74314ce0c4b5 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -2,7 +2,7 @@ // pieces of AST and HIR. The resulting numbers are good approximations but not // completely accurate (some things might be counted twice, others missed). -use rustc::hir; +use rustc::hir::{self, HirId}; use rustc::hir::intravisit as hir_visit; use rustc::util::common::to_readable_str; use rustc::util::nodemap::{FxHashMap, FxHashSet}; @@ -12,7 +12,7 @@ use syntax_pos::Span; #[derive(Copy, Clone, PartialEq, Eq, Hash)] enum Id { - Node(NodeId), + Node(HirId), Attr(AttrId), None, } @@ -119,7 +119,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_item(&mut self, i: &'v hir::Item) { - self.record("Item", Id::Node(i.id), i); + self.record("Item", Id::Node(i.hir_id), i); hir_visit::walk_item(self, i) } @@ -129,22 +129,22 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem) { - self.record("ForeignItem", Id::Node(i.id), i); + self.record("ForeignItem", Id::Node(i.hir_id), i); hir_visit::walk_foreign_item(self, i) } fn visit_local(&mut self, l: &'v hir::Local) { - self.record("Local", Id::Node(l.id), l); + self.record("Local", Id::Node(l.hir_id), l); hir_visit::walk_local(self, l) } fn visit_block(&mut self, b: &'v hir::Block) { - self.record("Block", Id::Node(b.id), b); + self.record("Block", Id::Node(b.hir_id), b); hir_visit::walk_block(self, b) } fn visit_stmt(&mut self, s: &'v hir::Stmt) { - self.record("Stmt", Id::Node(s.id), s); + self.record("Stmt", Id::Node(s.hir_id), s); hir_visit::walk_stmt(self, s) } @@ -154,17 +154,17 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_pat(&mut self, p: &'v hir::Pat) { - self.record("Pat", Id::Node(p.id), p); + self.record("Pat", Id::Node(p.hir_id), p); hir_visit::walk_pat(self, p) } fn visit_expr(&mut self, ex: &'v hir::Expr) { - self.record("Expr", Id::Node(ex.id), ex); + self.record("Expr", Id::Node(ex.hir_id), ex); hir_visit::walk_expr(self, ex) } fn visit_ty(&mut self, t: &'v hir::Ty) { - self.record("Ty", Id::Node(t.id), t); + self.record("Ty", Id::Node(t.hir_id), t); hir_visit::walk_ty(self, t) } @@ -184,12 +184,12 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_trait_item(&mut self, ti: &'v hir::TraitItem) { - self.record("TraitItem", Id::Node(ti.id), ti); + self.record("TraitItem", Id::Node(ti.hir_id), ti); hir_visit::walk_trait_item(self, ti) } fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) { - self.record("ImplItem", Id::Node(ii.id), ii); + self.record("ImplItem", Id::Node(ii.hir_id), ii); hir_visit::walk_impl_item(self, ii) } @@ -199,7 +199,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_struct_field(&mut self, s: &'v hir::StructField) { - self.record("StructField", Id::Node(s.id), s); + self.record("StructField", Id::Node(s.hir_id), s); hir_visit::walk_struct_field(self, s) } @@ -212,7 +212,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) { - self.record("Lifetime", Id::Node(lifetime.id), lifetime); + self.record("Lifetime", Id::Node(lifetime.hir_id), lifetime); hir_visit::walk_lifetime(self, lifetime) } @@ -234,7 +234,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_assoc_type_binding(&mut self, type_binding: &'v hir::TypeBinding) { - self.record("TypeBinding", Id::Node(type_binding.id), type_binding); + self.record("TypeBinding", Id::Node(type_binding.hir_id), type_binding); hir_visit::walk_assoc_type_binding(self, type_binding) } @@ -243,7 +243,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef) { - self.record("MacroDef", Id::Node(macro_def.id), macro_def); + self.record("MacroDef", Id::Node(macro_def.hir_id), macro_def); hir_visit::walk_macro_def(self, macro_def) } } diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 722af8f0e778d..f602ed24acd4e 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -86,7 +86,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.param_env, liberated_sig, decl, - expr.id, + expr.hir_id, body, gen, ).1; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 6ac0c79b1f2ea..838a1607ed5dc 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -388,14 +388,14 @@ impl Needs { #[derive(Copy, Clone)] pub struct UnsafetyState { - pub def: ast::NodeId, + pub def: hir::HirId, pub unsafety: hir::Unsafety, pub unsafe_push_count: u32, from_fn: bool } impl UnsafetyState { - pub fn function(unsafety: hir::Unsafety, def: ast::NodeId) -> UnsafetyState { + pub fn function(unsafety: hir::Unsafety, def: hir::HirId) -> UnsafetyState { UnsafetyState { def: def, unsafety: unsafety, unsafe_push_count: 0, from_fn: true } } @@ -410,11 +410,11 @@ impl UnsafetyState { unsafety => { let (unsafety, def, count) = match blk.rules { hir::PushUnsafeBlock(..) => - (unsafety, blk.id, self.unsafe_push_count.checked_add(1).unwrap()), + (unsafety, blk.hir_id, self.unsafe_push_count.checked_add(1).unwrap()), hir::PopUnsafeBlock(..) => - (unsafety, blk.id, self.unsafe_push_count.checked_sub(1).unwrap()), + (unsafety, blk.hir_id, self.unsafe_push_count.checked_sub(1).unwrap()), hir::UnsafeBlock(..) => - (hir::Unsafety::Unsafe, blk.id, self.unsafe_push_count), + (hir::Unsafety::Unsafe, blk.hir_id, self.unsafe_push_count), hir::DefaultBlock => (unsafety, self.def, self.unsafe_push_count), }; @@ -770,10 +770,10 @@ fn adt_destructor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, /// (notably closures), `typeck_tables(def_id)` would wind up /// redirecting to the owning function. fn primary_body_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - id: ast::NodeId) + id: hir::HirId) -> Option<(hir::BodyId, Option<&'tcx hir::FnDecl>)> { - match tcx.hir().get(id) { + match tcx.hir().get_by_hir_id(id) { Node::Item(item) => { match item.node { hir::ItemKind::Const(_, body) | @@ -820,7 +820,7 @@ fn has_typeck_tables<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, return tcx.has_typeck_tables(outer_def_id); } - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); primary_body_of(tcx, id).is_some() } @@ -840,8 +840,8 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, return tcx.typeck_tables_of(outer_def_id); } - let id = tcx.hir().as_local_node_id(def_id).unwrap(); - let span = tcx.hir().span(id); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let span = tcx.hir().span_by_hir_id(id); // Figure out what primary body this item has. let (body_id, fn_decl) = primary_body_of(tcx, id).unwrap_or_else(|| { @@ -925,8 +925,8 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Consistency check our TypeckTables instance can hold all ItemLocalIds // it will need to hold. - assert_eq!(tables.local_id_root, - Some(DefId::local(tcx.hir().definitions().node_to_hir_id(id).owner))); + assert_eq!(tables.local_id_root, Some(DefId::local(id.owner))); + tables } @@ -939,7 +939,7 @@ fn check_abi<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, abi: Abi) { struct GatherLocalsVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, - parent_id: ast::NodeId, + parent_id: hir::HirId, } impl<'a, 'gcx, 'tcx> GatherLocalsVisitor<'a, 'gcx, 'tcx> { @@ -1051,7 +1051,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, fn_sig: ty::FnSig<'tcx>, decl: &'gcx hir::FnDecl, - fn_id: ast::NodeId, + fn_id: hir::HirId, body: &'gcx hir::Body, can_be_generator: Option) -> (FnCtxt<'a, 'gcx, 'tcx>, Option>) @@ -1085,9 +1085,9 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, fcx.yield_ty = Some(yield_ty); } - let outer_def_id = fcx.tcx.closure_base_def_id(fcx.tcx.hir().local_def_id(fn_id)); - let outer_node_id = fcx.tcx.hir().as_local_node_id(outer_def_id).unwrap(); - GatherLocalsVisitor { fcx: &fcx, parent_id: outer_node_id, }.visit_body(body); + let outer_def_id = fcx.tcx.closure_base_def_id(fcx.tcx.hir().local_def_id_from_hir_id(fn_id)); + let outer_hir_id = fcx.tcx.hir().as_local_hir_id(outer_def_id).unwrap(); + GatherLocalsVisitor { fcx: &fcx, parent_id: outer_hir_id, }.visit_body(body); // Add formal parameters. for (arg_ty, arg) in fn_sig.inputs().iter().zip(&body.arguments) { @@ -1110,8 +1110,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, fcx.write_ty(arg.hir_id, arg_ty); } - let fn_hir_id = fcx.tcx.hir().node_to_hir_id(fn_id); - inherited.tables.borrow_mut().liberated_fn_sigs_mut().insert(fn_hir_id, fn_sig); + inherited.tables.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig); fcx.check_return_expr(&body.value); @@ -1164,14 +1163,13 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, // Check that the main return type implements the termination trait. if let Some(term_id) = fcx.tcx.lang_items().termination() { if let Some((def_id, EntryFnType::Main)) = fcx.tcx.entry_fn(LOCAL_CRATE) { - let main_id = fcx.tcx.hir().as_local_node_id(def_id).unwrap(); + let main_id = fcx.tcx.hir().as_local_hir_id(def_id).unwrap(); if main_id == fn_id { let substs = fcx.tcx.mk_substs_trait(declared_ret_ty, &[]); let trait_ref = ty::TraitRef::new(term_id, substs); let return_ty_span = decl.output.span(); - let fn_hir_id = fcx.tcx.hir().node_to_hir_id(fn_id); let cause = traits::ObligationCause::new( - return_ty_span, fn_hir_id, ObligationCauseCode::MainFunctionType); + return_ty_span, fn_id, ObligationCauseCode::MainFunctionType); inherited.register_predicate( traits::Obligation::new( @@ -1182,7 +1180,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, // Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !` if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() { - if panic_impl_did == fcx.tcx.hir().local_def_id(fn_id) { + if panic_impl_did == fcx.tcx.hir().local_def_id_from_hir_id(fn_id) { if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() { // at this point we don't care if there are duplicate handlers or if the handler has // the wrong signature as this value we'll be used when writing metadata and that @@ -1197,7 +1195,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, } let inputs = fn_sig.inputs(); - let span = fcx.tcx.hir().span(fn_id); + let span = fcx.tcx.hir().span_by_hir_id(fn_id); if inputs.len() == 1 { let arg_is_panic_info = match inputs[0].sty { ty::Ref(region, ty, mutbl) => match ty.sty { @@ -1218,7 +1216,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, ); } - if let Node::Item(item) = fcx.tcx.hir().get(fn_id) { + if let Node::Item(item) = fcx.tcx.hir().get_by_hir_id(fn_id) { if let ItemKind::Fn(_, _, ref generics, _) = item.node { if !generics.params.is_empty() { fcx.tcx.sess.span_err( @@ -1240,7 +1238,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, // Check that a function marked as `#[alloc_error_handler]` has signature `fn(Layout) -> !` if let Some(alloc_error_handler_did) = fcx.tcx.lang_items().oom() { - if alloc_error_handler_did == fcx.tcx.hir().local_def_id(fn_id) { + if alloc_error_handler_did == fcx.tcx.hir().local_def_id_from_hir_id(fn_id) { if let Some(alloc_layout_did) = fcx.tcx.lang_items().alloc_layout() { if declared_ret_ty.sty != ty::Never { fcx.tcx.sess.span_err( @@ -1250,7 +1248,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, } let inputs = fn_sig.inputs(); - let span = fcx.tcx.hir().span(fn_id); + let span = fcx.tcx.hir().span_by_hir_id(fn_id); if inputs.len() == 1 { let arg_is_alloc_layout = match inputs[0].sty { ty::Adt(ref adt, _) => { @@ -1266,7 +1264,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, ); } - if let Node::Item(item) = fcx.tcx.hir().get(fn_id) { + if let Node::Item(item) = fcx.tcx.hir().get_by_hir_id(fn_id) { if let ItemKind::Fn(_, _, ref generics, _) = item.node { if !generics.params.is_empty() { fcx.tcx.sess.span_err( @@ -2030,7 +2028,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ret_coercion_span: RefCell::new(None), yield_ty: None, ps: RefCell::new(UnsafetyState::function(hir::Unsafety::Normal, - ast::CRATE_NODE_ID)), + hir::CRATE_HIR_ID)), diverges: Cell::new(Diverges::Maybe), has_errors: Cell::new(false), enclosing_breakables: RefCell::new(EnclosingBreakables { @@ -2339,10 +2337,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// `InferCtxt::instantiate_opaque_types` for more details. fn instantiate_opaque_types_from_value>( &self, - parent_id: ast::NodeId, + parent_id: hir::HirId, value: &T, ) -> T { - let parent_def_id = self.tcx.hir().local_def_id(parent_id); + let parent_def_id = self.tcx.hir().local_def_id_from_hir_id(parent_id); debug!("instantiate_opaque_types_from_value(parent_def_id={:?}, value={:?})", parent_def_id, value); @@ -4936,7 +4934,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { may_break: false, }; - let (ctxt, ()) = self.with_breakable_ctxt(blk.id, ctxt, || { + let blk_node_id = self.tcx.hir().hir_to_node_id(blk.hir_id); + let (ctxt, ()) = self.with_breakable_ctxt(blk_node_id, ctxt, || { for s in &blk.stmts { self.check_stmt(s); } @@ -4946,12 +4945,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let tail_expr_ty = tail_expr.map(|t| self.check_expr_with_expectation(t, expected)); let mut enclosing_breakables = self.enclosing_breakables.borrow_mut(); - let ctxt = enclosing_breakables.find_breakable(blk.id); + let ctxt = enclosing_breakables.find_breakable(blk_node_id); let coerce = ctxt.coerce.as_mut().unwrap(); if let Some(tail_expr_ty) = tail_expr_ty { let tail_expr = tail_expr.unwrap(); let cause = self.cause(tail_expr.span, - ObligationCauseCode::BlockTailExpression(blk.id)); + ObligationCauseCode::BlockTailExpression(blk_node_id)); coerce.coerce(self, &cause, tail_expr, @@ -4975,9 +4974,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // that highlight errors inline. let mut sp = blk.span; let mut fn_span = None; - if let Some((decl, ident)) = self.get_parent_fn_decl(blk.id) { + if let Some((decl, ident)) = self.get_parent_fn_decl(blk_node_id) { let ret_sp = decl.output.span(); - if let Some(block_sp) = self.parent_item_span(blk.id) { + if let Some(block_sp) = self.parent_item_span(blk_node_id) { // HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the // output would otherwise be incorrect and even misleading. Make sure // the span we're aiming at correspond to a `fn` body. diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 08bc861766b8e..5279fbd9cf6eb 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -90,7 +90,6 @@ use rustc_data_structures::sync::Lrc; use std::mem; use std::ops::Deref; use std::rc::Rc; -use syntax::ast; use syntax_pos::Span; // a variation on try that just returns unit @@ -163,7 +162,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// rest of type check and because sometimes we need type /// inference to have completed before we can determine which /// constraints to add. - pub fn regionck_fn(&self, fn_id: ast::NodeId, body: &'gcx hir::Body) { + pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'gcx hir::Body) { debug!("regionck_fn(id={})", fn_id); let subject = self.tcx.hir().body_owner_def_id(body.id()); let hir_id = body.value.hir_id; @@ -176,9 +175,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ); if self.err_count_since_creation() == 0 { - let fn_hir_id = self.tcx.hir().node_to_hir_id(fn_id); // regionck assumes typeck succeeded - rcx.visit_fn_body(fn_hir_id, body, self.tcx.hir().span_by_hir_id(fn_hir_id)); + rcx.visit_fn_body(fn_id, body, self.tcx.hir().span_by_hir_id(fn_id)); } rcx.resolve_regions_and_report_errors(SuppressRegionErrors::when_nll_is_enabled(self.tcx));