From 85d44c42764fb87e1f581fa6206727e82cd7d52d Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 28 May 2018 14:16:09 +0300 Subject: [PATCH 1/7] rustc: rename mir::VisibilityScope to mir::SourceScope. --- src/librustc/ich/impls_mir.rs | 6 +- src/librustc/mir/mod.rs | 74 ++++++++++--------- src/librustc/mir/visit.rs | 36 ++++----- .../debuginfo/create_scope_map.rs | 18 ++--- src/librustc_codegen_llvm/mir/mod.rs | 10 +-- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/build/block.rs | 24 +++--- src/librustc_mir/build/matches/mod.rs | 26 +++---- src/librustc_mir/build/mod.rs | 32 ++++---- src/librustc_mir/build/scope.rs | 54 +++++++------- src/librustc_mir/shim.rs | 20 ++--- src/librustc_mir/transform/add_validation.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 18 ++--- src/librustc_mir/transform/const_prop.rs | 2 +- src/librustc_mir/transform/generator.rs | 8 +- src/librustc_mir/transform/inline.rs | 10 +-- src/librustc_mir/transform/promote_consts.rs | 8 +- src/librustc_mir/util/patch.rs | 2 +- src/librustc_mir/util/pretty.rs | 16 ++-- src/librustc_passes/mir_stats.rs | 16 ++-- 20 files changed, 193 insertions(+), 191 deletions(-) diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index e77d38de582..d4081d29c25 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -127,7 +127,7 @@ impl<'a> HashStable> for mir::Field { } impl<'a> HashStable> -for mir::VisibilityScope { +for mir::SourceScope { #[inline] fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, @@ -363,8 +363,8 @@ for mir::ProjectionElem<'gcx, V, T> } } -impl_stable_hash_for!(struct mir::VisibilityScopeData { span, parent_scope }); -impl_stable_hash_for!(struct mir::VisibilityScopeInfo { +impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope }); +impl_stable_hash_for!(struct mir::SourceScopeInfo { lint_root, safety }); diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index a94e5e793b4..3956d150232 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -78,13 +78,13 @@ pub struct Mir<'tcx> { /// that indexes into this vector. basic_blocks: IndexVec>, - /// List of visibility (lexical) scopes; these are referenced by statements - /// and used (eventually) for debuginfo. Indexed by a `VisibilityScope`. - pub visibility_scopes: IndexVec, + /// List of source scopes; these are referenced by statements + /// and used for debuginfo. Indexed by a `SourceScope`. + pub source_scopes: IndexVec, - /// Crate-local information for each visibility scope, that can't (and + /// Crate-local information for each source scope, that can't (and /// needn't) be tracked across crates. - pub visibility_scope_info: ClearCrossCrate>, + pub source_scope_info: ClearCrossCrate>, /// Rvalues promoted from this function, such as borrows of constants. /// Each of them is the Mir of a constant with the fn's type parameters @@ -137,9 +137,9 @@ pub const START_BLOCK: BasicBlock = BasicBlock(0); impl<'tcx> Mir<'tcx> { pub fn new(basic_blocks: IndexVec>, - visibility_scopes: IndexVec, - visibility_scope_info: ClearCrossCrate>, + source_scopes: IndexVec, + source_scope_info: ClearCrossCrate>, promoted: IndexVec>, yield_ty: Option>, local_decls: IndexVec>, @@ -153,8 +153,8 @@ impl<'tcx> Mir<'tcx> { Mir { basic_blocks, - visibility_scopes, - visibility_scope_info, + source_scopes, + source_scope_info, promoted, yield_ty, generator_drop: None, @@ -309,7 +309,7 @@ impl<'tcx> Mir<'tcx> { } #[derive(Clone, Debug, RustcEncodable, RustcDecodable)] -pub struct VisibilityScopeInfo { +pub struct SourceScopeInfo { /// A NodeId with lint levels equivalent to this scope's lint levels. pub lint_root: ast::NodeId, /// The unsafe block that contains this node. @@ -329,8 +329,8 @@ pub enum Safety { impl_stable_hash_for!(struct Mir<'tcx> { basic_blocks, - visibility_scopes, - visibility_scope_info, + source_scopes, + source_scope_info, promoted, yield_ty, generator_drop, @@ -376,8 +376,9 @@ pub struct SourceInfo { /// Source span for the AST pertaining to this MIR entity. pub span: Span, - /// The lexical visibility scope, i.e. which bindings can be seen. - pub scope: VisibilityScope + /// The source scope, keeping track of which bindings can be + /// seen by debuginfo, active lint levels, `unsafe {...}`, etc. + pub scope: SourceScope } /////////////////////////////////////////////////////////////////////////// @@ -512,16 +513,17 @@ pub struct LocalDecl<'tcx> { /// to generate better debuginfo. pub name: Option, - /// Source info of the local. + /// Source info of the local. The `SourceScope` is the *visibility* one, + /// not the the *syntactic* one (see `syntactic_scope` for more details). pub source_info: SourceInfo, - /// The *syntactic* visibility scope the local is defined + /// The *syntactic* (i.e. not visibility) source scope the local is defined /// in. If the local was defined in a let-statement, this /// is *within* the let-statement, rather than outside /// of it. /// - /// This is needed because visibility scope of locals within a let-statement - /// is weird. + /// This is needed because the visibility source scope of locals within + /// a let-statement is weird. /// /// The reason is that we want the local to be *within* the let-statement /// for lint purposes, but we want the local to be *after* the let-statement @@ -594,7 +596,7 @@ pub struct LocalDecl<'tcx> { /// │ │← x.source_info.scope /// │ │← `drop(x)` // this accesses `x: u32` /// ``` - pub syntactic_scope: VisibilityScope, + pub syntactic_scope: SourceScope, } impl<'tcx> LocalDecl<'tcx> { @@ -607,9 +609,9 @@ impl<'tcx> LocalDecl<'tcx> { name: None, source_info: SourceInfo { span, - scope: ARGUMENT_VISIBILITY_SCOPE + scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_scope: ARGUMENT_VISIBILITY_SCOPE, + syntactic_scope: OUTERMOST_SOURCE_SCOPE, internal: false, is_user_variable: false } @@ -624,9 +626,9 @@ impl<'tcx> LocalDecl<'tcx> { name: None, source_info: SourceInfo { span, - scope: ARGUMENT_VISIBILITY_SCOPE + scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_scope: ARGUMENT_VISIBILITY_SCOPE, + syntactic_scope: OUTERMOST_SOURCE_SCOPE, internal: true, is_user_variable: false } @@ -642,9 +644,9 @@ impl<'tcx> LocalDecl<'tcx> { ty: return_ty, source_info: SourceInfo { span, - scope: ARGUMENT_VISIBILITY_SCOPE + scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_scope: ARGUMENT_VISIBILITY_SCOPE, + syntactic_scope: OUTERMOST_SOURCE_SCOPE, internal: false, name: None, // FIXME maybe we do want some name here? is_user_variable: false @@ -1047,7 +1049,7 @@ impl<'tcx> BasicBlockData<'tcx> { self.statements.resize(gap.end, Statement { source_info: SourceInfo { span: DUMMY_SP, - scope: ARGUMENT_VISIBILITY_SCOPE + scope: OUTERMOST_SOURCE_SCOPE }, kind: StatementKind::Nop }); @@ -1501,16 +1503,16 @@ impl<'tcx> Debug for Place<'tcx> { /////////////////////////////////////////////////////////////////////////// // Scopes -newtype_index!(VisibilityScope +newtype_index!(SourceScope { DEBUG_FORMAT = "scope[{}]", - const ARGUMENT_VISIBILITY_SCOPE = 0, + const OUTERMOST_SOURCE_SCOPE = 0, }); #[derive(Clone, Debug, RustcEncodable, RustcDecodable)] -pub struct VisibilityScopeData { +pub struct SourceScopeData { pub span: Span, - pub parent_scope: Option, + pub parent_scope: Option, } /////////////////////////////////////////////////////////////////////////// @@ -2153,16 +2155,16 @@ CloneTypeFoldableAndLiftImpls! { SourceInfo, UpvarDecl, ValidationOp, - VisibilityScopeData, - VisibilityScope, - VisibilityScopeInfo, + SourceScopeData, + SourceScope, + SourceScopeInfo, } BraceStructTypeFoldableImpl! { impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> { basic_blocks, - visibility_scopes, - visibility_scope_info, + source_scopes, + source_scope_info, promoted, yield_ty, generator_drop, diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 9dd1432167a..0b50d55b1af 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -92,9 +92,9 @@ macro_rules! make_mir_visitor { self.super_basic_block_data(block, data); } - fn visit_visibility_scope_data(&mut self, - scope_data: & $($mutability)* VisibilityScopeData) { - self.super_visibility_scope_data(scope_data); + fn visit_source_scope_data(&mut self, + scope_data: & $($mutability)* SourceScopeData) { + self.super_source_scope_data(scope_data); } fn visit_statement(&mut self, @@ -261,9 +261,9 @@ macro_rules! make_mir_visitor { _location: Location) { } - fn visit_visibility_scope(&mut self, - scope: & $($mutability)* VisibilityScope) { - self.super_visibility_scope(scope); + fn visit_source_scope(&mut self, + scope: & $($mutability)* SourceScope) { + self.super_source_scope(scope); } // The `super_xxx` methods comprise the default behavior and are @@ -274,7 +274,7 @@ macro_rules! make_mir_visitor { if let Some(yield_ty) = &$($mutability)* mir.yield_ty { self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo { span: mir.span, - scope: ARGUMENT_VISIBILITY_SCOPE, + scope: OUTERMOST_SOURCE_SCOPE, })); } @@ -289,13 +289,13 @@ macro_rules! make_mir_visitor { self.visit_basic_block_data(bb, data); } - for scope in &$($mutability)* mir.visibility_scopes { - self.visit_visibility_scope_data(scope); + for scope in &$($mutability)* mir.source_scopes { + self.visit_source_scope_data(scope); } self.visit_ty(&$($mutability)* mir.return_ty(), TyContext::ReturnTy(SourceInfo { span: mir.span, - scope: ARGUMENT_VISIBILITY_SCOPE, + scope: OUTERMOST_SOURCE_SCOPE, })); for local in mir.local_decls.indices() { @@ -327,16 +327,16 @@ macro_rules! make_mir_visitor { } } - fn super_visibility_scope_data(&mut self, - scope_data: & $($mutability)* VisibilityScopeData) { - let VisibilityScopeData { + fn super_source_scope_data(&mut self, + scope_data: & $($mutability)* SourceScopeData) { + let SourceScopeData { ref $($mutability)* span, ref $($mutability)* parent_scope, } = *scope_data; self.visit_span(span); if let Some(ref $($mutability)* parent_scope) = *parent_scope { - self.visit_visibility_scope(parent_scope); + self.visit_source_scope(parent_scope); } } @@ -725,11 +725,11 @@ macro_rules! make_mir_visitor { source_info: *source_info, }); self.visit_source_info(source_info); - self.visit_visibility_scope(syntactic_scope); + self.visit_source_scope(syntactic_scope); } - fn super_visibility_scope(&mut self, - _scope: & $($mutability)* VisibilityScope) { + fn super_source_scope(&mut self, + _scope: & $($mutability)* SourceScope) { } fn super_branch(&mut self, @@ -775,7 +775,7 @@ macro_rules! make_mir_visitor { } = *source_info; self.visit_span(span); - self.visit_visibility_scope(scope); + self.visit_source_scope(scope); } fn super_ty(&mut self, _ty: & $($mutability)* Ty<'tcx>) { diff --git a/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs b/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs index bddb3d90940..24d9ff492d5 100644 --- a/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs +++ b/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs @@ -15,7 +15,7 @@ use super::utils::{DIB, span_start}; use llvm; use llvm::debuginfo::DIScope; use common::CodegenCx; -use rustc::mir::{Mir, VisibilityScope}; +use rustc::mir::{Mir, SourceScope}; use libc::c_uint; use std::ptr; @@ -45,13 +45,13 @@ impl MirDebugScope { /// Produce DIScope DIEs for each MIR Scope which has variables defined in it. /// If debuginfo is disabled, the returned vector is empty. pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebugContext) - -> IndexVec { + -> IndexVec { let null_scope = MirDebugScope { scope_metadata: ptr::null_mut(), file_start_pos: BytePos(0), file_end_pos: BytePos(0) }; - let mut scopes = IndexVec::from_elem(null_scope, &mir.visibility_scopes); + let mut scopes = IndexVec::from_elem(null_scope, &mir.source_scopes); let debug_context = match *debug_context { FunctionDebugContext::RegularContext(ref data) => data, @@ -62,15 +62,15 @@ pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebu }; // Find all the scopes with variables defined in them. - let mut has_variables = BitVector::new(mir.visibility_scopes.len()); + let mut has_variables = BitVector::new(mir.source_scopes.len()); for var in mir.vars_iter() { let decl = &mir.local_decls[var]; has_variables.insert(decl.source_info.scope.index()); } // Instantiate all scopes. - for idx in 0..mir.visibility_scopes.len() { - let scope = VisibilityScope::new(idx); + for idx in 0..mir.source_scopes.len() { + let scope = SourceScope::new(idx); make_mir_scope(cx, &mir, &has_variables, debug_context, scope, &mut scopes); } @@ -81,13 +81,13 @@ fn make_mir_scope(cx: &CodegenCx, mir: &Mir, has_variables: &BitVector, debug_context: &FunctionDebugContextData, - scope: VisibilityScope, - scopes: &mut IndexVec) { + scope: SourceScope, + scopes: &mut IndexVec) { if scopes[scope].is_valid() { return; } - let scope_data = &mir.visibility_scopes[scope]; + let scope_data = &mir.source_scopes[scope]; let parent_scope = if let Some(parent) = scope_data.parent_scope { make_mir_scope(cx, mir, has_variables, debug_context, parent, scopes); scopes[parent] diff --git a/src/librustc_codegen_llvm/mir/mod.rs b/src/librustc_codegen_llvm/mir/mod.rs index d34f881bf9d..4c0d7fee783 100644 --- a/src/librustc_codegen_llvm/mir/mod.rs +++ b/src/librustc_codegen_llvm/mir/mod.rs @@ -99,7 +99,7 @@ pub struct FunctionCx<'a, 'tcx:'a> { locals: IndexVec>, /// Debug information for MIR scopes. - scopes: IndexVec, + scopes: IndexVec, /// If this function is being monomorphized, this contains the type substitutions used. param_substs: &'tcx Substs<'tcx>, @@ -158,9 +158,9 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> { // DILocations inherit source file name from the parent DIScope. Due to macro expansions // it may so happen that the current span belongs to a different file than the DIScope - // corresponding to span's containing visibility scope. If so, we need to create a DIScope + // corresponding to span's containing source scope. If so, we need to create a DIScope // "extension" into that file. - fn scope_metadata_for_loc(&self, scope_id: mir::VisibilityScope, pos: BytePos) + fn scope_metadata_for_loc(&self, scope_id: mir::SourceScope, pos: BytePos) -> llvm::debuginfo::DIScope { let scope_metadata = self.scopes[scope_id].scope_metadata; if pos < self.scopes[scope_id].file_start_pos || @@ -411,7 +411,7 @@ fn create_funclets<'a, 'tcx>( /// indirect. fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>, fx: &FunctionCx<'a, 'tcx>, - scopes: &IndexVec, + scopes: &IndexVec, memory_locals: &BitVector) -> Vec> { let mir = fx.mir; @@ -420,7 +420,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>, let mut llarg_idx = fx.fn_ty.ret.is_indirect() as usize; // Get the argument scope, if it exists and if we need it. - let arg_scope = scopes[mir::ARGUMENT_VISIBILITY_SCOPE]; + let arg_scope = scopes[mir::OUTERMOST_SOURCE_SCOPE]; let arg_scope = if arg_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo { Some(arg_scope.scope_metadata) } else { diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 20eb084e1a1..d18c9d72c6d 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -292,7 +292,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( debug!("mbcx.used_mut: {:?}", mbcx.used_mut); for local in mbcx.mir.mut_vars_and_args_iter().filter(|local| !mbcx.used_mut.contains(local)) { - if let ClearCrossCrate::Set(ref vsi) = mbcx.mir.visibility_scope_info { + if let ClearCrossCrate::Set(ref vsi) = mbcx.mir.source_scope_info { let local_decl = &mbcx.mir.local_decls[local]; // Skip implicit `self` argument for closures diff --git a/src/librustc_mir/build/block.rs b/src/librustc_mir/build/block.rs index c9f86d43998..7096f91dc1d 100644 --- a/src/librustc_mir/build/block.rs +++ b/src/librustc_mir/build/block.rs @@ -81,10 +81,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { // // First we build all the statements in the block. let mut let_scope_stack = Vec::with_capacity(8); - let outer_visibility_scope = this.visibility_scope; + let outer_source_scope = this.source_scope; let outer_push_unsafe_count = this.push_unsafe_count; let outer_unpushed_unsafe = this.unpushed_unsafe; - this.update_visibility_scope_for_safety_mode(span, safety_mode); + this.update_source_scope_for_safety_mode(span, safety_mode); let source_info = this.source_info(span); for stmt in stmts { @@ -112,7 +112,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { this.push_scope((remainder_scope, source_info)); let_scope_stack.push(remainder_scope); - // Declare the bindings, which may create a visibility scope. + // Declare the bindings, which may create a source scope. let remainder_span = remainder_scope.span(this.hir.tcx(), &this.hir.region_scope_tree); let scope = this.declare_bindings(None, remainder_span, lint_level, &pattern, @@ -143,9 +143,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { }) } - // Enter the visibility scope, after evaluating the initializer. - if let Some(visibility_scope) = scope { - this.visibility_scope = visibility_scope; + // Enter the source scope, after evaluating the initializer. + if let Some(source_scope) = scope { + this.source_scope = source_scope; } } } @@ -172,19 +172,19 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { for scope in let_scope_stack.into_iter().rev() { unpack!(block = this.pop_scope((scope, source_info), block)); } - // Restore the original visibility scope. - this.visibility_scope = outer_visibility_scope; + // Restore the original source scope. + this.source_scope = outer_source_scope; this.push_unsafe_count = outer_push_unsafe_count; this.unpushed_unsafe = outer_unpushed_unsafe; block.unit() } - /// If we are changing the safety mode, create a new visibility scope - fn update_visibility_scope_for_safety_mode(&mut self, + /// If we are changing the safety mode, create a new source scope + fn update_source_scope_for_safety_mode(&mut self, span: Span, safety_mode: BlockSafety) { - debug!("update_visibility_scope_for({:?}, {:?})", span, safety_mode); + debug!("update_source_scope_for({:?}, {:?})", span, safety_mode); let new_unsafety = match safety_mode { BlockSafety::Safe => None, BlockSafety::ExplicitUnsafe(node_id) => { @@ -214,7 +214,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { }; if let Some(unsafety) = new_unsafety { - self.visibility_scope = self.new_visibility_scope( + self.source_scope = self.new_source_scope( span, LintLevel::Inherited, Some(unsafety)); } } diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index a3c7bcfbd0b..6d731da0cfb 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -97,7 +97,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { LintLevel::Inherited, &arm.patterns[0], ArmHasGuard(arm.guard.is_some())); - (body, scope.unwrap_or(self.visibility_scope)) + (body, scope.unwrap_or(self.source_scope)) }).collect(); // create binding start block for link them by false edges @@ -200,15 +200,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let end_block = self.cfg.start_new_block(); let outer_source_info = self.source_info(span); - for (arm_index, (body, visibility_scope)) in arm_bodies.into_iter().enumerate() { + for (arm_index, (body, source_scope)) in arm_bodies.into_iter().enumerate() { let mut arm_block = arm_blocks.blocks[arm_index]; - // Re-enter the visibility scope we created the bindings in. - self.visibility_scope = visibility_scope; + // Re-enter the source scope we created the bindings in. + self.source_scope = source_scope; unpack!(arm_block = self.into(destination, arm_block, body)); self.cfg.terminate(arm_block, outer_source_info, TerminatorKind::Goto { target: end_block }); } - self.visibility_scope = outer_source_info.scope; + self.source_scope = outer_source_info.scope; end_block.unit() } @@ -294,30 +294,30 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { block.unit() } - /// Declares the bindings of the given pattern and returns the visibility scope + /// Declares the bindings of the given pattern and returns the source scope /// for the bindings in this patterns, if such a scope had to be created. /// NOTE: Declaring the bindings should always be done in their drop scope. pub fn declare_bindings(&mut self, - mut var_scope: Option, + mut var_scope: Option, scope_span: Span, lint_level: LintLevel, pattern: &Pattern<'tcx>, has_guard: ArmHasGuard) - -> Option { + -> Option { assert!(!(var_scope.is_some() && lint_level.is_explicit()), "can't have both a var and a lint scope at the same time"); - let mut syntactic_scope = self.visibility_scope; + let mut syntactic_scope = self.source_scope; self.visit_bindings(pattern, &mut |this, mutability, name, var, span, ty| { if var_scope.is_none() { - var_scope = Some(this.new_visibility_scope(scope_span, + var_scope = Some(this.new_source_scope(scope_span, LintLevel::Inherited, None)); - // If we have lints, create a new visibility scope + // If we have lints, create a new source scope // that marks the lints for the locals. See the comment // on the `syntactic_scope` field for why this is needed. if lint_level.is_explicit() { syntactic_scope = - this.new_visibility_scope(scope_span, lint_level, None); + this.new_source_scope(scope_span, lint_level, None); } } let source_info = SourceInfo { @@ -1114,7 +1114,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// in the arm body, which will have type `T`. fn declare_binding(&mut self, source_info: SourceInfo, - syntactic_scope: VisibilityScope, + syntactic_scope: SourceScope, mutability: Mutability, name: Name, var_id: NodeId, diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 4822b9e4dfd..2bc885fb442 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -256,9 +256,9 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { /// the vector of all scopes that we have created thus far; /// we track this for debuginfo later - visibility_scopes: IndexVec, - visibility_scope_info: IndexVec, - visibility_scope: VisibilityScope, + source_scopes: IndexVec, + source_scope_info: IndexVec, + source_scope: SourceScope, /// the guard-context: each time we build the guard expression for /// a match arm, we push onto this stack, and then pop when we @@ -593,9 +593,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { fn_span: span, arg_count, scopes: vec![], - visibility_scopes: IndexVec::new(), - visibility_scope: ARGUMENT_VISIBILITY_SCOPE, - visibility_scope_info: IndexVec::new(), + source_scopes: IndexVec::new(), + source_scope: OUTERMOST_SOURCE_SCOPE, + source_scope_info: IndexVec::new(), guard_context: vec![], push_unsafe_count: 0, unpushed_unsafe: safety, @@ -611,9 +611,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { assert_eq!(builder.cfg.start_new_block(), START_BLOCK); assert_eq!( - builder.new_visibility_scope(span, lint_level, Some(safety)), - ARGUMENT_VISIBILITY_SCOPE); - builder.visibility_scopes[ARGUMENT_VISIBILITY_SCOPE].parent_scope = None; + builder.new_source_scope(span, lint_level, Some(safety)), + OUTERMOST_SOURCE_SCOPE); + builder.source_scopes[OUTERMOST_SOURCE_SCOPE].parent_scope = None; builder } @@ -629,8 +629,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { } Mir::new(self.cfg.basic_blocks, - self.visibility_scopes, - ClearCrossCrate::Set(self.visibility_scope_info), + self.source_scopes, + ClearCrossCrate::Set(self.source_scope_info), IndexVec::new(), yield_ty, self.local_decls, @@ -661,10 +661,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { mutability: Mutability::Mut, ty, source_info: SourceInfo { - scope: ARGUMENT_VISIBILITY_SCOPE, + scope: OUTERMOST_SOURCE_SCOPE, span: pattern.map_or(self.fn_span, |pat| pat.span) }, - syntactic_scope: ARGUMENT_VISIBILITY_SCOPE, + syntactic_scope: OUTERMOST_SOURCE_SCOPE, name, internal: false, is_user_variable: false, @@ -702,9 +702,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { } - // Enter the argument pattern bindings visibility scope, if it exists. - if let Some(visibility_scope) = scope { - self.visibility_scope = visibility_scope; + // Enter the argument pattern bindings source scope, if it exists. + if let Some(source_scope) = scope { + self.source_scope = source_scope; } let body = self.hir.mirror(ast_body); diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index 5dc59ac9f41..a1eb8bcdf7c 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -100,8 +100,8 @@ use rustc_data_structures::fx::FxHashMap; #[derive(Debug)] pub struct Scope<'tcx> { - /// The visibility scope this scope was created in. - visibility_scope: VisibilityScope, + /// The source scope this scope was created in. + source_scope: SourceScope, /// the region span of this scope within source code. region_scope: region::Scope, @@ -251,11 +251,11 @@ impl<'tcx> Scope<'tcx> { } } - /// Given a span and this scope's visibility scope, make a SourceInfo. + /// Given a span and this scope's source scope, make a SourceInfo. fn source_info(&self, span: Span) -> SourceInfo { SourceInfo { span, - scope: self.visibility_scope + scope: self.source_scope } } } @@ -316,14 +316,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { where F: FnOnce(&mut Builder<'a, 'gcx, 'tcx>) -> BlockAnd { debug!("in_scope(region_scope={:?}, block={:?})", region_scope, block); - let visibility_scope = self.visibility_scope; + let source_scope = self.source_scope; let tcx = self.hir.tcx(); if let LintLevel::Explicit(node_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.visibility_scope_info[visibility_scope].lint_root + self.source_scope_info[source_scope].lint_root ); let current_hir_id = tcx.hir.definitions().node_to_hir_id(node_id); @@ -332,15 +332,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { }); if !same_lint_scopes { - self.visibility_scope = - self.new_visibility_scope(region_scope.1.span, lint_level, + self.source_scope = + self.new_source_scope(region_scope.1.span, lint_level, None); } } self.push_scope(region_scope); let rv = unpack!(block = f(self)); unpack!(block = self.pop_scope(region_scope, block)); - self.visibility_scope = visibility_scope; + self.source_scope = source_scope; debug!("in_scope: exiting region_scope={:?} block={:?}", region_scope, block); block.and(rv) } @@ -351,9 +351,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// wrapper maybe preferable. pub fn push_scope(&mut self, region_scope: (region::Scope, SourceInfo)) { debug!("push_scope({:?})", region_scope); - let vis_scope = self.visibility_scope; + let vis_scope = self.source_scope; self.scopes.push(Scope { - visibility_scope: vis_scope, + source_scope: vis_scope, region_scope: region_scope.0, region_scope_span: region_scope.1.span, needs_cleanup: false, @@ -509,30 +509,30 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { Some(result) } - /// Creates a new visibility scope, nested in the current one. - pub fn new_visibility_scope(&mut self, + /// Creates a new source scope, nested in the current one. + pub fn new_source_scope(&mut self, span: Span, lint_level: LintLevel, - safety: Option) -> VisibilityScope { - let parent = self.visibility_scope; - debug!("new_visibility_scope({:?}, {:?}, {:?}) - parent({:?})={:?}", + safety: Option) -> SourceScope { + let parent = self.source_scope; + debug!("new_source_scope({:?}, {:?}, {:?}) - parent({:?})={:?}", span, lint_level, safety, - parent, self.visibility_scope_info.get(parent)); - let scope = self.visibility_scopes.push(VisibilityScopeData { + parent, self.source_scope_info.get(parent)); + let scope = self.source_scopes.push(SourceScopeData { span, parent_scope: Some(parent), }); - let scope_info = VisibilityScopeInfo { + let scope_info = SourceScopeInfo { lint_root: if let LintLevel::Explicit(lint_root) = lint_level { lint_root } else { - self.visibility_scope_info[parent].lint_root + self.source_scope_info[parent].lint_root }, safety: safety.unwrap_or_else(|| { - self.visibility_scope_info[parent].safety + self.source_scope_info[parent].safety }) }; - self.visibility_scope_info.push(scope_info); + self.source_scope_info.push(scope_info); scope } @@ -552,11 +552,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { .unwrap_or_else(|| span_bug!(span, "no enclosing breakable scope found")) } - /// Given a span and the current visibility scope, make a SourceInfo. + /// Given a span and the current source scope, make a SourceInfo. pub fn source_info(&self, span: Span) -> SourceInfo { SourceInfo { span, - scope: self.visibility_scope + scope: self.source_scope } } @@ -730,7 +730,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let resumeblk = self.cfg.start_new_cleanup_block(); self.cfg.terminate(resumeblk, SourceInfo { - scope: ARGUMENT_VISIBILITY_SCOPE, + scope: OUTERMOST_SOURCE_SCOPE, span: self.fn_span }, TerminatorKind::Resume); @@ -939,10 +939,10 @@ fn build_diverge_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, // remainder. If everything is cached, we'll just walk right to // left reading the cached results but never create anything. - let visibility_scope = scope.visibility_scope; + let source_scope = scope.source_scope; let source_info = |span| SourceInfo { span, - scope: visibility_scope + scope: source_scope }; // Next, build up the drops. Here we iterate the vector in diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 8375a5fb334..71f76f47afe 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -140,8 +140,8 @@ enum CallKind { fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl { LocalDecl { mutability, ty, name: None, - source_info: SourceInfo { scope: ARGUMENT_VISIBILITY_SCOPE, span }, - syntactic_scope: ARGUMENT_VISIBILITY_SCOPE, + source_info: SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span }, + syntactic_scope: OUTERMOST_SOURCE_SCOPE, internal: false, is_user_variable: false } @@ -178,7 +178,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let sig = tcx.erase_late_bound_regions(&sig); let span = tcx.def_span(def_id); - let source_info = SourceInfo { span, scope: ARGUMENT_VISIBILITY_SCOPE }; + let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }; let return_block = BasicBlock::new(1); let mut blocks = IndexVec::new(); @@ -195,7 +195,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mut mir = Mir::new( blocks, IndexVec::from_elem_n( - VisibilityScopeData { span: span, parent_scope: None }, 1 + SourceScopeData { span: span, parent_scope: None }, 1 ), ClearCrossCrate::Clear, IndexVec::new(), @@ -354,7 +354,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> { Mir::new( self.blocks, IndexVec::from_elem_n( - VisibilityScopeData { span: self.span, parent_scope: None }, 1 + SourceScopeData { span: self.span, parent_scope: None }, 1 ), ClearCrossCrate::Clear, IndexVec::new(), @@ -367,7 +367,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> { } fn source_info(&self) -> SourceInfo { - SourceInfo { span: self.span, scope: ARGUMENT_VISIBILITY_SCOPE } + SourceInfo { span: self.span, scope: OUTERMOST_SOURCE_SCOPE } } fn block( @@ -688,7 +688,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, debug!("build_call_shim: sig={:?}", sig); let mut local_decls = local_decls_for_sig(&sig, span); - let source_info = SourceInfo { span, scope: ARGUMENT_VISIBILITY_SCOPE }; + let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }; let rcvr_arg = Local::new(1+0); let rcvr_l = Place::Local(rcvr_arg); @@ -794,7 +794,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mut mir = Mir::new( blocks, IndexVec::from_elem_n( - VisibilityScopeData { span: span, parent_scope: None }, 1 + SourceScopeData { span: span, parent_scope: None }, 1 ), ClearCrossCrate::Clear, IndexVec::new(), @@ -836,7 +836,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>, let source_info = SourceInfo { span, - scope: ARGUMENT_VISIBILITY_SCOPE + scope: OUTERMOST_SOURCE_SCOPE }; let variant_no = if adt_def.is_enum() { @@ -869,7 +869,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>, Mir::new( IndexVec::from_elem_n(start_block, 1), IndexVec::from_elem_n( - VisibilityScopeData { span: span, parent_scope: None }, 1 + SourceScopeData { span: span, parent_scope: None }, 1 ), ClearCrossCrate::Clear, IndexVec::new(), diff --git a/src/librustc_mir/transform/add_validation.rs b/src/librustc_mir/transform/add_validation.rs index 85af00956c9..44f9477c2ec 100644 --- a/src/librustc_mir/transform/add_validation.rs +++ b/src/librustc_mir/transform/add_validation.rs @@ -231,7 +231,7 @@ impl MirPass for AddValidation { // Add an AcquireValid at the beginning of the start block. { let source_info = SourceInfo { - scope: ARGUMENT_VISIBILITY_SCOPE, + scope: OUTERMOST_SOURCE_SCOPE, span: mir.span, // FIXME: Consider using just the span covering the function // argument declaration. }; diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 4081f827d4b..e5a71c6ac3a 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -27,7 +27,7 @@ use util; pub struct UnsafetyChecker<'a, 'tcx: 'a> { mir: &'a Mir<'tcx>, - visibility_scope_info: &'a IndexVec, + source_scope_info: &'a IndexVec, violations: Vec, source_info: SourceInfo, tcx: TyCtxt<'a, 'tcx, 'tcx>, @@ -38,16 +38,16 @@ pub struct UnsafetyChecker<'a, 'tcx: 'a> { impl<'a, 'gcx, 'tcx> UnsafetyChecker<'a, 'tcx> { fn new(mir: &'a Mir<'tcx>, - visibility_scope_info: &'a IndexVec, + source_scope_info: &'a IndexVec, tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self { Self { mir, - visibility_scope_info, + source_scope_info, violations: vec![], source_info: SourceInfo { span: mir.span, - scope: ARGUMENT_VISIBILITY_SCOPE + scope: OUTERMOST_SOURCE_SCOPE }, tcx, param_env, @@ -147,7 +147,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { if util::is_disaligned(self.tcx, self.mir, self.param_env, place) { let source_info = self.source_info; let lint_root = - self.visibility_scope_info[source_info.scope].lint_root; + self.source_scope_info[source_info.scope].lint_root; self.register_violations(&[UnsafetyViolation { source_info, description: Symbol::intern("borrow of packed field").as_interned_str(), @@ -212,7 +212,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { } else if self.tcx.is_foreign_item(def_id) { let source_info = self.source_info; let lint_root = - self.visibility_scope_info[source_info.scope].lint_root; + self.source_scope_info[source_info.scope].lint_root; self.register_violations(&[UnsafetyViolation { source_info, description: Symbol::intern("use of extern static").as_interned_str(), @@ -240,7 +240,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { fn register_violations(&mut self, violations: &[UnsafetyViolation], unsafe_blocks: &[(ast::NodeId, bool)]) { - let within_unsafe = match self.visibility_scope_info[self.source_info.scope].safety { + let within_unsafe = match self.source_scope_info[self.source_info.scope].safety { Safety::Safe => { for violation in violations { if !self.violations.contains(violation) { @@ -327,7 +327,7 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) // `mir_built` force this. let mir = &tcx.mir_built(def_id).borrow(); - let visibility_scope_info = match mir.visibility_scope_info { + let source_scope_info = match mir.source_scope_info { ClearCrossCrate::Set(ref data) => data, ClearCrossCrate::Clear => { debug!("unsafety_violations: {:?} - remote, skipping", def_id); @@ -340,7 +340,7 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) let param_env = tcx.param_env(def_id); let mut checker = UnsafetyChecker::new( - mir, visibility_scope_info, tcx, param_env); + mir, source_scope_info, tcx, param_env); checker.visit_mir(mir); check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks); diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index fa740876091..580b7e208f9 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -338,7 +338,7 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> { .bits(); let right_size = self.tcx.layout_of(self.param_env.and(right.1)).unwrap().size; if r.to_bits(right_size).ok().map_or(false, |b| b >= left_bits as u128) { - let scope_info = match self.mir.visibility_scope_info { + let scope_info = match self.mir.source_scope_info { ClearCrossCrate::Set(ref data) => data, ClearCrossCrate::Clear => return None, }; diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 74b6d721882..f7ee6276aaa 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -300,7 +300,7 @@ fn replace_result_variable<'tcx>(ret_ty: Ty<'tcx>, ty: ret_ty, name: None, source_info: source_info(mir), - syntactic_scope: ARGUMENT_VISIBILITY_SCOPE, + syntactic_scope: OUTERMOST_SOURCE_SCOPE, internal: false, is_user_variable: false, }; @@ -641,7 +641,7 @@ fn create_generator_drop_shim<'a, 'tcx>( ty: tcx.mk_nil(), name: None, source_info, - syntactic_scope: ARGUMENT_VISIBILITY_SCOPE, + syntactic_scope: OUTERMOST_SOURCE_SCOPE, internal: false, is_user_variable: false, }; @@ -657,7 +657,7 @@ fn create_generator_drop_shim<'a, 'tcx>( }), name: None, source_info, - syntactic_scope: ARGUMENT_VISIBILITY_SCOPE, + syntactic_scope: OUTERMOST_SOURCE_SCOPE, internal: false, is_user_variable: false, }; @@ -762,7 +762,7 @@ fn create_generator_resume_function<'a, 'tcx>( fn source_info<'a, 'tcx>(mir: &Mir<'tcx>) -> SourceInfo { SourceInfo { span: mir.span, - scope: ARGUMENT_VISIBILITY_SCOPE, + scope: OUTERMOST_SOURCE_SCOPE, } } diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 5fb9148d49a..9fa078f8dab 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -380,10 +380,10 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { debug!("Inlined {:?} into {:?}", callsite.callee, self.source); let mut local_map = IndexVec::with_capacity(callee_mir.local_decls.len()); - let mut scope_map = IndexVec::with_capacity(callee_mir.visibility_scopes.len()); + let mut scope_map = IndexVec::with_capacity(callee_mir.source_scopes.len()); let mut promoted_map = IndexVec::with_capacity(callee_mir.promoted.len()); - for mut scope in callee_mir.visibility_scopes.iter().cloned() { + for mut scope in callee_mir.source_scopes.iter().cloned() { if scope.parent_scope.is_none() { scope.parent_scope = Some(callsite.location.scope); scope.span = callee_mir.span; @@ -391,7 +391,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { scope.span = callsite.location.span; - let idx = caller_mir.visibility_scopes.push(scope); + let idx = caller_mir.source_scopes.push(scope); scope_map.push(idx); } @@ -618,7 +618,7 @@ struct Integrator<'a, 'tcx: 'a> { block_idx: usize, args: &'a [Local], local_map: IndexVec, - scope_map: IndexVec, + scope_map: IndexVec, promoted_map: IndexVec, _callsite: CallSite<'tcx>, destination: Place<'tcx>, @@ -745,7 +745,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { } } - fn visit_visibility_scope(&mut self, scope: &mut VisibilityScope) { + fn visit_source_scope(&mut self, scope: &mut SourceScope) { *scope = self.scope_map[*scope]; } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 5af19ab3646..e9face62ad3 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -167,7 +167,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { terminator: Some(Terminator { source_info: SourceInfo { span, - scope: ARGUMENT_VISIBILITY_SCOPE + scope: OUTERMOST_SOURCE_SCOPE }, kind: TerminatorKind::Return }), @@ -181,7 +181,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { data.statements.push(Statement { source_info: SourceInfo { span, - scope: ARGUMENT_VISIBILITY_SCOPE + scope: OUTERMOST_SOURCE_SCOPE }, kind: StatementKind::Assign(Place::Local(dest), rvalue) }); @@ -424,8 +424,8 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>, IndexVec::new(), // FIXME: maybe try to filter this to avoid blowing up // memory usage? - mir.visibility_scopes.clone(), - mir.visibility_scope_info.clone(), + mir.source_scopes.clone(), + mir.source_scope_info.clone(), IndexVec::new(), None, initial_locals, diff --git a/src/librustc_mir/util/patch.rs b/src/librustc_mir/util/patch.rs index f1bdcfcd22f..21ff7eaa72d 100644 --- a/src/librustc_mir/util/patch.rs +++ b/src/librustc_mir/util/patch.rs @@ -62,7 +62,7 @@ impl<'tcx> MirPatch<'tcx> { terminator: Some(Terminator { source_info: SourceInfo { span: mir.span, - scope: ARGUMENT_VISIBILITY_SCOPE + scope: OUTERMOST_SOURCE_SCOPE }, kind: TerminatorKind::Resume }), diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 9e1ce9b2851..8176c644dd7 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -447,9 +447,9 @@ fn comment(tcx: TyCtxt, SourceInfo { span, scope }: SourceInfo) -> String { fn write_scope_tree( tcx: TyCtxt, mir: &Mir, - scope_tree: &FxHashMap>, + scope_tree: &FxHashMap>, w: &mut dyn Write, - parent: VisibilityScope, + parent: SourceScope, depth: usize, ) -> io::Result<()> { let indent = depth * INDENT.len(); @@ -460,7 +460,7 @@ fn write_scope_tree( }; for &child in children { - let data = &mir.visibility_scopes[child]; + let data = &mir.source_scopes[child]; assert_eq!(data.parent_scope, Some(parent)); writeln!(w, "{0:1$}scope {2} {{", "", indent, child.index())?; @@ -519,16 +519,16 @@ pub fn write_mir_intro<'a, 'gcx, 'tcx>( writeln!(w, "{{")?; // construct a scope tree and write it out - let mut scope_tree: FxHashMap> = FxHashMap(); - for (index, scope_data) in mir.visibility_scopes.iter().enumerate() { + let mut scope_tree: FxHashMap> = FxHashMap(); + for (index, scope_data) in mir.source_scopes.iter().enumerate() { if let Some(parent) = scope_data.parent_scope { scope_tree .entry(parent) .or_insert(vec![]) - .push(VisibilityScope::new(index)); + .push(SourceScope::new(index)); } else { // Only the argument scope has no parent, because it's the root. - assert_eq!(index, ARGUMENT_VISIBILITY_SCOPE.index()); + assert_eq!(index, OUTERMOST_SOURCE_SCOPE.index()); } } @@ -541,7 +541,7 @@ pub fn write_mir_intro<'a, 'gcx, 'tcx>( indented_retptr, ALIGN)?; - write_scope_tree(tcx, mir, &scope_tree, w, ARGUMENT_VISIBILITY_SCOPE, 1)?; + write_scope_tree(tcx, mir, &scope_tree, w, OUTERMOST_SOURCE_SCOPE, 1)?; write_temp_decls(mir, w)?; diff --git a/src/librustc_passes/mir_stats.rs b/src/librustc_passes/mir_stats.rs index f7c8f8f43f1..b795685bb6f 100644 --- a/src/librustc_passes/mir_stats.rs +++ b/src/librustc_passes/mir_stats.rs @@ -17,7 +17,7 @@ use rustc::mir::{Constant, Literal, Location, Local, LocalDecl}; use rustc::mir::{Place, PlaceElem, PlaceProjection}; use rustc::mir::{Mir, Operand, ProjectionElem}; use rustc::mir::{Rvalue, SourceInfo, Statement, StatementKind}; -use rustc::mir::{Terminator, TerminatorKind, VisibilityScope, VisibilityScopeData}; +use rustc::mir::{Terminator, TerminatorKind, SourceScope, SourceScopeData}; use rustc::mir::interpret::EvalErrorKind; use rustc::mir::visit as mir_visit; use rustc::ty::{self, ClosureSubsts, TyCtxt}; @@ -72,10 +72,10 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> { self.super_basic_block_data(block, data); } - fn visit_visibility_scope_data(&mut self, - scope_data: &VisibilityScopeData) { - self.record("VisibilityScopeData", scope_data); - self.super_visibility_scope_data(scope_data); + fn visit_source_scope_data(&mut self, + scope_data: &SourceScopeData) { + self.record("SourceScopeData", scope_data); + self.super_source_scope_data(scope_data); } fn visit_statement(&mut self, @@ -278,9 +278,9 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> { self.super_local_decl(local, local_decl); } - fn visit_visibility_scope(&mut self, - scope: &VisibilityScope) { + fn visit_source_scope(&mut self, + scope: &SourceScope) { self.record("VisiblityScope", scope); - self.super_visibility_scope(scope); + self.super_source_scope(scope); } } From ca1ac6b6fb820765a678fa3decb343fa9f720737 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 28 May 2018 17:37:48 +0300 Subject: [PATCH 2/7] rustc: rename mir::SourceScopeInfo to mir::SourceScopeLocalData. --- src/librustc/ich/impls_mir.rs | 2 +- src/librustc/mir/mod.rs | 32 ++++++++++---------- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/build/mod.rs | 6 ++-- src/librustc_mir/build/scope.rs | 12 ++++---- src/librustc_mir/transform/check_unsafety.rs | 16 +++++----- src/librustc_mir/transform/const_prop.rs | 4 +-- src/librustc_mir/transform/promote_consts.rs | 2 +- 8 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index d4081d29c25..59d5ce278c6 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -364,7 +364,7 @@ for mir::ProjectionElem<'gcx, V, T> } impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope }); -impl_stable_hash_for!(struct mir::SourceScopeInfo { +impl_stable_hash_for!(struct mir::SourceScopeLocalData { lint_root, safety }); diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 3956d150232..b60be21773b 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -84,7 +84,7 @@ pub struct Mir<'tcx> { /// Crate-local information for each source scope, that can't (and /// needn't) be tracked across crates. - pub source_scope_info: ClearCrossCrate>, + pub source_scope_local_data: ClearCrossCrate>, /// Rvalues promoted from this function, such as borrows of constants. /// Each of them is the Mir of a constant with the fn's type parameters @@ -138,8 +138,8 @@ pub const START_BLOCK: BasicBlock = BasicBlock(0); impl<'tcx> Mir<'tcx> { pub fn new(basic_blocks: IndexVec>, source_scopes: IndexVec, - source_scope_info: ClearCrossCrate>, + source_scope_local_data: ClearCrossCrate>, promoted: IndexVec>, yield_ty: Option>, local_decls: IndexVec>, @@ -154,7 +154,7 @@ impl<'tcx> Mir<'tcx> { Mir { basic_blocks, source_scopes, - source_scope_info, + source_scope_local_data, promoted, yield_ty, generator_drop: None, @@ -308,14 +308,6 @@ impl<'tcx> Mir<'tcx> { } } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] -pub struct SourceScopeInfo { - /// A NodeId with lint levels equivalent to this scope's lint levels. - pub lint_root: ast::NodeId, - /// The unsafe block that contains this node. - pub safety: Safety, -} - #[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] pub enum Safety { Safe, @@ -330,7 +322,7 @@ pub enum Safety { impl_stable_hash_for!(struct Mir<'tcx> { basic_blocks, source_scopes, - source_scope_info, + source_scope_local_data, promoted, yield_ty, generator_drop, @@ -1515,6 +1507,14 @@ pub struct SourceScopeData { pub parent_scope: Option, } +#[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, + /// The unsafe block that contains this node. + pub safety: Safety, +} + /////////////////////////////////////////////////////////////////////////// // Operands @@ -2155,16 +2155,16 @@ CloneTypeFoldableAndLiftImpls! { SourceInfo, UpvarDecl, ValidationOp, - SourceScopeData, SourceScope, - SourceScopeInfo, + SourceScopeData, + SourceScopeLocalData, } BraceStructTypeFoldableImpl! { impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> { basic_blocks, source_scopes, - source_scope_info, + source_scope_local_data, promoted, yield_ty, generator_drop, diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index d18c9d72c6d..0257af0c89f 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -292,7 +292,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( debug!("mbcx.used_mut: {:?}", mbcx.used_mut); for local in mbcx.mir.mut_vars_and_args_iter().filter(|local| !mbcx.used_mut.contains(local)) { - if let ClearCrossCrate::Set(ref vsi) = mbcx.mir.source_scope_info { + if let ClearCrossCrate::Set(ref vsi) = mbcx.mir.source_scope_local_data { let local_decl = &mbcx.mir.local_decls[local]; // Skip implicit `self` argument for closures diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 2bc885fb442..23a266d47cf 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -257,7 +257,7 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { /// the vector of all scopes that we have created thus far; /// we track this for debuginfo later source_scopes: IndexVec, - source_scope_info: IndexVec, + source_scope_local_data: IndexVec, source_scope: SourceScope, /// the guard-context: each time we build the guard expression for @@ -595,7 +595,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { scopes: vec![], source_scopes: IndexVec::new(), source_scope: OUTERMOST_SOURCE_SCOPE, - source_scope_info: IndexVec::new(), + source_scope_local_data: IndexVec::new(), guard_context: vec![], push_unsafe_count: 0, unpushed_unsafe: safety, @@ -630,7 +630,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { Mir::new(self.cfg.basic_blocks, self.source_scopes, - ClearCrossCrate::Set(self.source_scope_info), + ClearCrossCrate::Set(self.source_scope_local_data), IndexVec::new(), yield_ty, self.local_decls, diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index a1eb8bcdf7c..ee0a087a1dd 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -323,7 +323,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let sets = tcx.lint_levels(LOCAL_CRATE); let parent_hir_id = tcx.hir.definitions().node_to_hir_id( - self.source_scope_info[source_scope].lint_root + self.source_scope_local_data[source_scope].lint_root ); let current_hir_id = tcx.hir.definitions().node_to_hir_id(node_id); @@ -517,22 +517,22 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let parent = self.source_scope; debug!("new_source_scope({:?}, {:?}, {:?}) - parent({:?})={:?}", span, lint_level, safety, - parent, self.source_scope_info.get(parent)); + parent, self.source_scope_local_data.get(parent)); let scope = self.source_scopes.push(SourceScopeData { span, parent_scope: Some(parent), }); - let scope_info = SourceScopeInfo { + let scope_local_data = SourceScopeLocalData { lint_root: if let LintLevel::Explicit(lint_root) = lint_level { lint_root } else { - self.source_scope_info[parent].lint_root + self.source_scope_local_data[parent].lint_root }, safety: safety.unwrap_or_else(|| { - self.source_scope_info[parent].safety + self.source_scope_local_data[parent].safety }) }; - self.source_scope_info.push(scope_info); + self.source_scope_local_data.push(scope_local_data); scope } diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index e5a71c6ac3a..fedd0774df4 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -27,7 +27,7 @@ use util; pub struct UnsafetyChecker<'a, 'tcx: 'a> { mir: &'a Mir<'tcx>, - source_scope_info: &'a IndexVec, + source_scope_local_data: &'a IndexVec, violations: Vec, source_info: SourceInfo, tcx: TyCtxt<'a, 'tcx, 'tcx>, @@ -38,12 +38,12 @@ pub struct UnsafetyChecker<'a, 'tcx: 'a> { impl<'a, 'gcx, 'tcx> UnsafetyChecker<'a, 'tcx> { fn new(mir: &'a Mir<'tcx>, - source_scope_info: &'a IndexVec, + source_scope_local_data: &'a IndexVec, tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self { Self { mir, - source_scope_info, + source_scope_local_data, violations: vec![], source_info: SourceInfo { span: mir.span, @@ -147,7 +147,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { if util::is_disaligned(self.tcx, self.mir, self.param_env, place) { let source_info = self.source_info; let lint_root = - self.source_scope_info[source_info.scope].lint_root; + self.source_scope_local_data[source_info.scope].lint_root; self.register_violations(&[UnsafetyViolation { source_info, description: Symbol::intern("borrow of packed field").as_interned_str(), @@ -212,7 +212,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { } else if self.tcx.is_foreign_item(def_id) { let source_info = self.source_info; let lint_root = - self.source_scope_info[source_info.scope].lint_root; + self.source_scope_local_data[source_info.scope].lint_root; self.register_violations(&[UnsafetyViolation { source_info, description: Symbol::intern("use of extern static").as_interned_str(), @@ -240,7 +240,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { fn register_violations(&mut self, violations: &[UnsafetyViolation], unsafe_blocks: &[(ast::NodeId, bool)]) { - let within_unsafe = match self.source_scope_info[self.source_info.scope].safety { + let within_unsafe = match self.source_scope_local_data[self.source_info.scope].safety { Safety::Safe => { for violation in violations { if !self.violations.contains(violation) { @@ -327,7 +327,7 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) // `mir_built` force this. let mir = &tcx.mir_built(def_id).borrow(); - let source_scope_info = match mir.source_scope_info { + let source_scope_local_data = match mir.source_scope_local_data { ClearCrossCrate::Set(ref data) => data, ClearCrossCrate::Clear => { debug!("unsafety_violations: {:?} - remote, skipping", def_id); @@ -340,7 +340,7 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) let param_env = tcx.param_env(def_id); let mut checker = UnsafetyChecker::new( - mir, source_scope_info, tcx, param_env); + mir, source_scope_local_data, tcx, param_env); checker.visit_mir(mir); check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks); diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 580b7e208f9..ef61fe099bf 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -338,7 +338,7 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> { .bits(); let right_size = self.tcx.layout_of(self.param_env.and(right.1)).unwrap().size; if r.to_bits(right_size).ok().map_or(false, |b| b >= left_bits as u128) { - let scope_info = match self.mir.source_scope_info { + let source_scope_local_data = match self.mir.source_scope_local_data { ClearCrossCrate::Set(ref data) => data, ClearCrossCrate::Clear => return None, }; @@ -347,7 +347,7 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> { } else { "left" }; - let node_id = scope_info[source_info.scope].lint_root; + let node_id = source_scope_local_data[source_info.scope].lint_root; self.tcx.lint_node( ::rustc::lint::builtin::EXCEEDING_BITSHIFTS, node_id, diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index e9face62ad3..19bc4fd03f4 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -425,7 +425,7 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>, // FIXME: maybe try to filter this to avoid blowing up // memory usage? mir.source_scopes.clone(), - mir.source_scope_info.clone(), + mir.source_scope_local_data.clone(), IndexVec::new(), None, initial_locals, From b10c157bd860c7d6baad56aeee550a84927e1e29 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 29 May 2018 12:24:53 +0300 Subject: [PATCH 3/7] rustc: turn mir::LocalDecl's syntactic_scope into a SourceInfo. --- src/librustc/ich/impls_mir.rs | 2 +- src/librustc/mir/mod.rs | 29 +++++++++++++------- src/librustc/mir/visit.rs | 4 +-- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/build/expr/into.rs | 2 +- src/librustc_mir/build/matches/mod.rs | 18 +++++++----- src/librustc_mir/build/mod.rs | 11 ++++---- src/librustc_mir/shim.rs | 5 ++-- src/librustc_mir/transform/generator.rs | 9 +++--- src/librustc_mir/transform/inline.rs | 3 ++ src/librustc_mir/transform/promote_consts.rs | 1 + 11 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index 59d5ce278c6..a3acb6c1b24 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -26,8 +26,8 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> { ty, name, source_info, + syntactic_source_info, internal, - syntactic_scope, is_user_variable }); impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, by_ref, mutability }); diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index b60be21773b..2faacfb598f 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -506,7 +506,7 @@ pub struct LocalDecl<'tcx> { pub name: Option, /// Source info of the local. The `SourceScope` is the *visibility* one, - /// not the the *syntactic* one (see `syntactic_scope` for more details). + /// not the the *syntactic* one (see `syntactic_source_info` for more details). pub source_info: SourceInfo, /// The *syntactic* (i.e. not visibility) source scope the local is defined @@ -560,9 +560,9 @@ pub struct LocalDecl<'tcx> { /// `drop(x)`, we want it to refer to `x: u32`. /// /// To allow both uses to work, we need to have more than a single scope - /// for a local. We have the `syntactic_scope` represent the + /// for a local. We have the `syntactic_source_info.scope` represent the /// "syntactic" lint scope (with a variable being under its let - /// block) while the source-info scope represents the "local variable" + /// block) while the `source_info.scope` represents the "local variable" /// scope (where the "rest" of a block is under all prior let-statements). /// /// The end result looks like this: @@ -574,10 +574,10 @@ pub struct LocalDecl<'tcx> { /// │ │{ #[allow(unused_mut] } // this is actually split into 2 scopes /// │ │ // in practice because I'm lazy. /// │ │ - /// │ │← x.syntactic_scope + /// │ │← x.syntactic_source_info.scope /// │ │← `x.parse().unwrap()` /// │ │ - /// │ │ │← y.syntactic_scope + /// │ │ │← y.syntactic_source_info.scope /// │ │ /// │ │ │{ let y: u32 } /// │ │ │ @@ -588,7 +588,7 @@ pub struct LocalDecl<'tcx> { /// │ │← x.source_info.scope /// │ │← `drop(x)` // this accesses `x: u32` /// ``` - pub syntactic_scope: SourceScope, + pub syntactic_source_info: SourceInfo, } impl<'tcx> LocalDecl<'tcx> { @@ -603,7 +603,10 @@ impl<'tcx> LocalDecl<'tcx> { span, scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + syntactic_source_info: SourceInfo { + span, + scope: OUTERMOST_SOURCE_SCOPE + }, internal: false, is_user_variable: false } @@ -620,7 +623,10 @@ impl<'tcx> LocalDecl<'tcx> { span, scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + syntactic_source_info: SourceInfo { + span, + scope: OUTERMOST_SOURCE_SCOPE + }, internal: true, is_user_variable: false } @@ -638,7 +644,10 @@ impl<'tcx> LocalDecl<'tcx> { span, scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + syntactic_source_info: SourceInfo { + span, + scope: OUTERMOST_SOURCE_SCOPE + }, internal: false, name: None, // FIXME maybe we do want some name here? is_user_variable: false @@ -2192,7 +2201,7 @@ BraceStructTypeFoldableImpl! { ty, name, source_info, - syntactic_scope, + syntactic_source_info, } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 0b50d55b1af..72d7540b287 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -716,7 +716,7 @@ macro_rules! make_mir_visitor { name: _, ref $($mutability)* source_info, internal: _, - ref $($mutability)* syntactic_scope, + ref $($mutability)* syntactic_source_info, is_user_variable: _, } = *local_decl; @@ -724,8 +724,8 @@ macro_rules! make_mir_visitor { local, source_info: *source_info, }); + self.visit_source_info(syntactic_source_info); self.visit_source_info(source_info); - self.visit_source_scope(syntactic_scope); } fn super_source_scope(&mut self, diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 0257af0c89f..0fab6634e0b 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -311,7 +311,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( tcx.struct_span_lint_node( UNUSED_MUT, - vsi[local_decl.syntactic_scope].lint_root, + vsi[local_decl.syntactic_source_info.scope].lint_root, source_info.span, "variable does not need to be mutable" ) diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index 562f890b4c0..f8b57bed93e 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -247,7 +247,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ty: ptr_ty, name: None, source_info, - syntactic_scope: source_info.scope, + syntactic_source_info: source_info, internal: true, is_user_variable: false }); diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 6d731da0cfb..80739aa9d4f 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -314,7 +314,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { None)); // If we have lints, create a new source scope // that marks the lints for the locals. See the comment - // on the `syntactic_scope` field for why this is needed. + // on the `syntactic_source_info` field for why this is needed. if lint_level.is_explicit() { syntactic_scope = this.new_source_scope(scope_span, lint_level, None); @@ -324,7 +324,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { span, scope: var_scope.unwrap() }; - this.declare_binding(source_info, syntactic_scope, mutability, name, var, + let syntactic_source_info = SourceInfo { + span, + scope: syntactic_scope, + }; + this.declare_binding(source_info, syntactic_source_info, mutability, name, var, ty, has_guard); }); var_scope @@ -1114,7 +1118,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// in the arm body, which will have type `T`. fn declare_binding(&mut self, source_info: SourceInfo, - syntactic_scope: SourceScope, + syntactic_source_info: SourceInfo, mutability: Mutability, name: Name, var_id: NodeId, @@ -1122,8 +1126,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { has_guard: ArmHasGuard) { debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, source_info={:?}, \ - syntactic_scope={:?})", - var_id, name, var_ty, source_info, syntactic_scope); + syntactic_source_info={:?})", + var_id, name, var_ty, source_info, syntactic_source_info); let tcx = self.hir.tcx(); let local = LocalDecl::<'tcx> { @@ -1131,7 +1135,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ty: var_ty.clone(), name: Some(name), source_info, - syntactic_scope, + syntactic_source_info, internal: false, is_user_variable: true, }; @@ -1143,7 +1147,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty), name: Some(name), source_info, - syntactic_scope, + syntactic_source_info, internal: false, is_user_variable: true, }); diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 23a266d47cf..06f43ad4621 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -657,14 +657,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { } } + let source_info = SourceInfo { + scope: OUTERMOST_SOURCE_SCOPE, + span: pattern.map_or(self.fn_span, |pat| pat.span) + }; self.local_decls.push(LocalDecl { mutability: Mutability::Mut, ty, - source_info: SourceInfo { - scope: OUTERMOST_SOURCE_SCOPE, - span: pattern.map_or(self.fn_span, |pat| pat.span) - }, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + source_info, + syntactic_source_info: source_info, name, internal: false, is_user_variable: false, diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 71f76f47afe..6692849bd0f 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -138,10 +138,11 @@ enum CallKind { } fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl { + let source_info = SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span }; LocalDecl { mutability, ty, name: None, - source_info: SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span }, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + source_info, + syntactic_source_info: source_info, internal: false, is_user_variable: false } diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index f7ee6276aaa..1c833453c36 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -295,12 +295,13 @@ fn make_generator_state_argument_indirect<'a, 'tcx>( fn replace_result_variable<'tcx>(ret_ty: Ty<'tcx>, mir: &mut Mir<'tcx>) -> Local { + let source_info = source_info(mir); let new_ret = LocalDecl { mutability: Mutability::Mut, ty: ret_ty, name: None, - source_info: source_info(mir), - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + source_info, + syntactic_source_info: source_info, internal: false, is_user_variable: false, }; @@ -641,7 +642,7 @@ fn create_generator_drop_shim<'a, 'tcx>( ty: tcx.mk_nil(), name: None, source_info, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + syntactic_source_info: source_info, internal: false, is_user_variable: false, }; @@ -657,7 +658,7 @@ fn create_generator_drop_shim<'a, 'tcx>( }), name: None, source_info, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + syntactic_source_info: source_info, internal: false, is_user_variable: false, }; diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 9fa078f8dab..2434f303178 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -400,6 +400,9 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { local.source_info.scope = scope_map[local.source_info.scope]; local.source_info.span = callsite.location.span; + local.syntactic_source_info.scope = + scope_map[local.syntactic_source_info.scope]; + local.syntactic_source_info.span = callsite.location.span; let idx = caller_mir.local_decls.push(local); local_map.push(idx); diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 19bc4fd03f4..61f43f23a23 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -335,6 +335,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { // otherwise we would use the `promoted` directly. let mut promoted_ref = LocalDecl::new_temp(ref_ty, span); promoted_ref.source_info = statement.source_info; + promoted_ref.syntactic_source_info = statement.source_info; let promoted_ref = local_decls.push(promoted_ref); assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref); self.extra_statements.push((loc, Statement { From 0895590c53919bb235771947ae395ab0d1751b4d Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 29 May 2018 17:37:24 +0300 Subject: [PATCH 4/7] rustc: rename mir::LocalDecl's source_info to visibility_source_info. --- src/librustc/ich/impls_mir.rs | 2 +- src/librustc/mir/mod.rs | 28 +++++++-------- src/librustc/mir/visit.rs | 8 ++--- .../debuginfo/create_scope_map.rs | 2 +- src/librustc_codegen_llvm/mir/mod.rs | 4 +-- .../borrow_check/error_reporting.rs | 2 +- src/librustc_mir/borrow_check/mod.rs | 2 +- .../borrow_check/nll/explain_borrow/mod.rs | 2 +- .../borrow_check/nll/type_check/mod.rs | 2 +- src/librustc_mir/build/expr/into.rs | 2 +- src/librustc_mir/build/matches/mod.rs | 34 +++++++++---------- src/librustc_mir/build/mod.rs | 2 +- .../dataflow/move_paths/builder.rs | 2 +- src/librustc_mir/shim.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 2 +- src/librustc_mir/transform/generator.rs | 6 ++-- src/librustc_mir/transform/inline.rs | 5 +-- src/librustc_mir/transform/promote_consts.rs | 4 +-- src/librustc_mir/transform/qualify_consts.rs | 4 +-- src/librustc_mir/util/pretty.rs | 4 +-- 20 files changed, 60 insertions(+), 59 deletions(-) diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index a3acb6c1b24..e5d28fdf785 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -25,8 +25,8 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> { mutability, ty, name, - source_info, syntactic_source_info, + visibility_source_info, internal, is_user_variable }); diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 2faacfb598f..2251d4a4b60 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -505,10 +505,6 @@ pub struct LocalDecl<'tcx> { /// to generate better debuginfo. pub name: Option, - /// Source info of the local. The `SourceScope` is the *visibility* one, - /// not the the *syntactic* one (see `syntactic_source_info` for more details). - pub source_info: SourceInfo, - /// The *syntactic* (i.e. not visibility) source scope the local is defined /// in. If the local was defined in a let-statement, this /// is *within* the let-statement, rather than outside @@ -562,7 +558,7 @@ pub struct LocalDecl<'tcx> { /// To allow both uses to work, we need to have more than a single scope /// for a local. We have the `syntactic_source_info.scope` represent the /// "syntactic" lint scope (with a variable being under its let - /// block) while the `source_info.scope` represents the "local variable" + /// block) while the `visibility_source_info.scope` represents the "local variable" /// scope (where the "rest" of a block is under all prior let-statements). /// /// The end result looks like this: @@ -581,14 +577,18 @@ pub struct LocalDecl<'tcx> { /// │ │ /// │ │ │{ let y: u32 } /// │ │ │ - /// │ │ │← y.source_info.scope + /// │ │ │← y.visibility_source_info.scope /// │ │ │← `y + 2` /// │ /// │ │{ let x: u32 } - /// │ │← x.source_info.scope + /// │ │← x.visibility_source_info.scope /// │ │← `drop(x)` // this accesses `x: u32` /// ``` pub syntactic_source_info: SourceInfo, + + /// Source info of the local. The `SourceScope` is the *visibility* one, + /// not the the *syntactic* one (see `syntactic_source_info` for more details). + pub visibility_source_info: SourceInfo, } impl<'tcx> LocalDecl<'tcx> { @@ -599,11 +599,11 @@ impl<'tcx> LocalDecl<'tcx> { mutability: Mutability::Mut, ty, name: None, - source_info: SourceInfo { + syntactic_source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_source_info: SourceInfo { + visibility_source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }, @@ -619,11 +619,11 @@ impl<'tcx> LocalDecl<'tcx> { mutability: Mutability::Mut, ty, name: None, - source_info: SourceInfo { + syntactic_source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_source_info: SourceInfo { + visibility_source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }, @@ -640,11 +640,11 @@ impl<'tcx> LocalDecl<'tcx> { LocalDecl { mutability: Mutability::Mut, ty: return_ty, - source_info: SourceInfo { + syntactic_source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_source_info: SourceInfo { + visibility_source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }, @@ -2200,8 +2200,8 @@ BraceStructTypeFoldableImpl! { internal, ty, name, - source_info, syntactic_source_info, + visibility_source_info, } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 72d7540b287..3aec9f10e3d 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -714,18 +714,18 @@ macro_rules! make_mir_visitor { mutability: _, ref $($mutability)* ty, name: _, - ref $($mutability)* source_info, - internal: _, ref $($mutability)* syntactic_source_info, + ref $($mutability)* visibility_source_info, + internal: _, is_user_variable: _, } = *local_decl; self.visit_ty(ty, TyContext::LocalDecl { local, - source_info: *source_info, + source_info: *visibility_source_info, }); self.visit_source_info(syntactic_source_info); - self.visit_source_info(source_info); + self.visit_source_info(visibility_source_info); } fn super_source_scope(&mut self, diff --git a/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs b/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs index 24d9ff492d5..81d8e510d11 100644 --- a/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs +++ b/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs @@ -65,7 +65,7 @@ pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebu let mut has_variables = BitVector::new(mir.source_scopes.len()); for var in mir.vars_iter() { let decl = &mir.local_decls[var]; - has_variables.insert(decl.source_info.scope.index()); + has_variables.insert(decl.visibility_source_info.scope.index()); } // Instantiate all scopes. diff --git a/src/librustc_codegen_llvm/mir/mod.rs b/src/librustc_codegen_llvm/mir/mod.rs index 4c0d7fee783..8dd8cc3f4bc 100644 --- a/src/librustc_codegen_llvm/mir/mod.rs +++ b/src/librustc_codegen_llvm/mir/mod.rs @@ -265,7 +265,7 @@ pub fn codegen_mir<'a, 'tcx: 'a>( if let Some(name) = decl.name { // User variable - let debug_scope = fx.scopes[decl.source_info.scope]; + let debug_scope = fx.scopes[decl.visibility_source_info.scope]; let dbg = debug_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo; if !memory_locals.contains(local.index()) && !dbg { @@ -276,7 +276,7 @@ pub fn codegen_mir<'a, 'tcx: 'a>( debug!("alloc: {:?} ({}) -> place", local, name); let place = PlaceRef::alloca(&bx, layout, &name.as_str()); if dbg { - let (scope, span) = fx.debug_loc(decl.source_info); + let (scope, span) = fx.debug_loc(decl.visibility_source_info); declare_local(&bx, &fx.debug_context, name, layout.ty, scope, VariableAccess::DirectVariable { alloca: place.llval }, VariableKind::LocalVariable, span); diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 9061af1b68c..eedf8decd16 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -398,7 +398,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { let borrow_span = self.mir.source_info(borrow.reserve_location).span; let proper_span = match *root_place { - Place::Local(local) => self.mir.local_decls[local].source_info.span, + Place::Local(local) => self.mir.local_decls[local].visibility_source_info.span, _ => drop_span, }; diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 0fab6634e0b..7b6bec06fa6 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -306,7 +306,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( None => continue, } - let source_info = local_decl.source_info; + let source_info = local_decl.visibility_source_info; let mut_span = tcx.sess.codemap().span_until_non_whitespace(source_info.span); tcx.struct_span_lint_node( diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs index 2807a4e8857..88b9afbd138 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs @@ -67,7 +67,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { } None => { err.span_label( - mir.local_decls[local].source_info.span, + mir.local_decls[local].visibility_source_info.span, "borrow may end up in a temporary, created here", ); diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 04f5024b769..f8a0eb3749c 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1201,7 +1201,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { LocalKind::Var | LocalKind::Temp => {} } - let span = local_decl.source_info.span; + let span = local_decl.visibility_source_info.span; let ty = local_decl.ty; // Erase the regions from `ty` to get a global type. The diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index f8b57bed93e..049d4340193 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -246,8 +246,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { mutability: Mutability::Mut, ty: ptr_ty, name: None, - source_info, syntactic_source_info: source_info, + visibility_source_info: source_info, internal: true, is_user_variable: false }); diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 80739aa9d4f..e6ad36f3034 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -294,22 +294,22 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { block.unit() } - /// Declares the bindings of the given pattern and returns the source scope + /// Declares the bindings of the given pattern and returns the visibility scope /// for the bindings in this patterns, if such a scope had to be created. /// NOTE: Declaring the bindings should always be done in their drop scope. pub fn declare_bindings(&mut self, - mut var_scope: Option, + mut visibility_scope: Option, scope_span: Span, lint_level: LintLevel, pattern: &Pattern<'tcx>, has_guard: ArmHasGuard) -> Option { - assert!(!(var_scope.is_some() && lint_level.is_explicit()), - "can't have both a var and a lint scope at the same time"); + assert!(!(visibility_scope.is_some() && lint_level.is_explicit()), + "can't have both a visibility and a lint scope at the same time"); let mut syntactic_scope = self.source_scope; self.visit_bindings(pattern, &mut |this, mutability, name, var, span, ty| { - if var_scope.is_none() { - var_scope = Some(this.new_source_scope(scope_span, + if visibility_scope.is_none() { + visibility_scope = Some(this.new_source_scope(scope_span, LintLevel::Inherited, None)); // If we have lints, create a new source scope @@ -320,18 +320,18 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { this.new_source_scope(scope_span, lint_level, None); } } - let source_info = SourceInfo { - span, - scope: var_scope.unwrap() - }; let syntactic_source_info = SourceInfo { span, scope: syntactic_scope, }; - this.declare_binding(source_info, syntactic_source_info, mutability, name, var, + let visibility_source_info = SourceInfo { + span, + scope: visibility_scope.unwrap() + }; + this.declare_binding(syntactic_source_info, visibility_source_info, mutability, name, var, ty, has_guard); }); - var_scope + visibility_scope } pub fn storage_live_binding(&mut self, @@ -1117,25 +1117,25 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// `&T`. The second local is a binding for occurrences of `var` /// in the arm body, which will have type `T`. fn declare_binding(&mut self, - source_info: SourceInfo, syntactic_source_info: SourceInfo, + visibility_source_info: SourceInfo, mutability: Mutability, name: Name, var_id: NodeId, var_ty: Ty<'tcx>, has_guard: ArmHasGuard) { - debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, source_info={:?}, \ + debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, visibility_source_info={:?}, \ syntactic_source_info={:?})", - var_id, name, var_ty, source_info, syntactic_source_info); + var_id, name, var_ty, visibility_source_info, syntactic_source_info); let tcx = self.hir.tcx(); let local = LocalDecl::<'tcx> { mutability, ty: var_ty.clone(), name: Some(name), - source_info, syntactic_source_info, + visibility_source_info, internal: false, is_user_variable: true, }; @@ -1146,8 +1146,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { mutability, ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty), name: Some(name), - source_info, syntactic_source_info, + visibility_source_info, internal: false, is_user_variable: true, }); diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 06f43ad4621..527e605a16a 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -664,8 +664,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { self.local_decls.push(LocalDecl { mutability: Mutability::Mut, ty, - source_info, syntactic_source_info: source_info, + visibility_source_info: source_info, name, internal: false, is_user_variable: false, diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index 2ff22842141..321f307a43c 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -233,7 +233,7 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> { fn gather_args(&mut self) { for arg in self.mir.args_iter() { let path = self.data.rev_lookup.locals[arg]; - let span = self.mir.local_decls[arg].source_info.span; + let span = self.mir.local_decls[arg].visibility_source_info.span; let init = self.data.inits.push(Init { path, span, kind: InitKind::Deep diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 6692849bd0f..f168292897e 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -141,8 +141,8 @@ fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl { let source_info = SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span }; LocalDecl { mutability, ty, name: None, - source_info, syntactic_source_info: source_info, + visibility_source_info: source_info, internal: false, is_user_variable: false } diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index fedd0774df4..48de30f1ff1 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { // Internal locals are used in the `move_val_init` desugaring. // We want to check unsafety against the source info of the // desugaring, rather than the source info of the RHS. - self.source_info = self.mir.local_decls[local].source_info; + self.source_info = self.mir.local_decls[local].visibility_source_info; } } let base_ty = base.ty(self.mir, self.tcx).to_ty(self.tcx); diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 1c833453c36..940a13a42df 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -300,8 +300,8 @@ fn replace_result_variable<'tcx>(ret_ty: Ty<'tcx>, mutability: Mutability::Mut, ty: ret_ty, name: None, - source_info, syntactic_source_info: source_info, + visibility_source_info: source_info, internal: false, is_user_variable: false, }; @@ -641,8 +641,8 @@ fn create_generator_drop_shim<'a, 'tcx>( mutability: Mutability::Mut, ty: tcx.mk_nil(), name: None, - source_info, syntactic_source_info: source_info, + visibility_source_info: source_info, internal: false, is_user_variable: false, }; @@ -657,8 +657,8 @@ fn create_generator_drop_shim<'a, 'tcx>( mutbl: hir::Mutability::MutMutable, }), name: None, - source_info, syntactic_source_info: source_info, + visibility_source_info: source_info, internal: false, is_user_variable: false, }; diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 2434f303178..868d7cadde4 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -398,11 +398,12 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { for loc in callee_mir.vars_and_temps_iter() { let mut local = callee_mir.local_decls[loc].clone(); - local.source_info.scope = scope_map[local.source_info.scope]; - local.source_info.span = callsite.location.span; local.syntactic_source_info.scope = scope_map[local.syntactic_source_info.scope]; local.syntactic_source_info.span = callsite.location.span; + local.visibility_source_info.scope = + scope_map[local.visibility_source_info.scope]; + local.visibility_source_info.span = callsite.location.span; let idx = caller_mir.local_decls.push(local); local_map.push(idx); diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 61f43f23a23..98cc0ed8234 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -210,7 +210,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let no_stmts = self.source[loc.block].statements.len(); let new_temp = self.promoted.local_decls.push( LocalDecl::new_temp(self.source.local_decls[temp].ty, - self.source.local_decls[temp].source_info.span)); + self.source.local_decls[temp].visibility_source_info.span)); debug!("promote({:?} @ {:?}/{:?}, {:?})", temp, loc, no_stmts, self.keep_original); @@ -334,8 +334,8 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { // This is because `*r` requires `r` to be a local, // otherwise we would use the `promoted` directly. let mut promoted_ref = LocalDecl::new_temp(ref_ty, span); - promoted_ref.source_info = statement.source_info; promoted_ref.syntactic_source_info = statement.source_info; + promoted_ref.visibility_source_info = statement.source_info; let promoted_ref = local_decls.push(promoted_ref); assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref); self.extra_statements.push((loc, Statement { diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 71963012944..05e232753d7 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1046,7 +1046,7 @@ This does not pose a problem by itself because they can't be accessed directly." // conservatively, that drop elaboration will do. let needs_drop = if let Place::Local(local) = *place { if self.local_qualif[local].map_or(true, |q| q.intersects(Qualif::NEEDS_DROP)) { - Some(self.mir.local_decls[local].source_info.span) + Some(self.mir.local_decls[local].visibility_source_info.span) } else { None } @@ -1102,7 +1102,7 @@ This does not pose a problem by itself because they can't be accessed directly." let mut err = feature_err( &self.tcx.sess.parse_sess, "const_let", - decl.source_info.span, + decl.visibility_source_info.span, GateIssue::Language, "arguments of constant functions can only be immutable by-value bindings" ); diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 8176c644dd7..bf01619d5b0 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -467,8 +467,8 @@ fn write_scope_tree( // User variable types (including the user's name in a comment). for local in mir.vars_iter() { let var = &mir.local_decls[local]; - let (name, source_info) = if var.source_info.scope == child { - (var.name.unwrap(), var.source_info) + let (name, source_info) = if var.visibility_source_info.scope == child { + (var.name.unwrap(), var.visibility_source_info) } else { // Not a variable or not declared in this scope. continue; From 3da186b67fcfa01e3c719b3eb4edeb99d1d1aafb Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 29 May 2018 13:54:24 +0300 Subject: [PATCH 5/7] rustc: use syntactic (instead of visibility) source info where appropriate. --- src/librustc/mir/visit.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 2 +- src/librustc_mir/util/pretty.rs | 4 ++-- src/test/mir-opt/box_expr.rs | 3 ++- src/test/mir-opt/end_region_1.rs | 4 ++-- src/test/mir-opt/end_region_2.rs | 4 ++-- src/test/mir-opt/end_region_3.rs | 4 ++-- src/test/mir-opt/end_region_4.rs | 8 ++++---- src/test/mir-opt/end_region_8.rs | 4 ++-- src/test/mir-opt/end_region_9.rs | 4 ++-- src/test/mir-opt/end_region_cyclic.rs | 2 +- src/test/mir-opt/issue-41110.rs | 7 ++++--- src/test/mir-opt/nll/reborrow-basic.rs | 4 ++-- src/test/mir-opt/nll/region-subtyping-basic.rs | 4 ++-- src/test/mir-opt/packed-struct-drop-aligned.rs | 2 +- src/test/mir-opt/validate_3.rs | 4 ++-- 16 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 3aec9f10e3d..3a1a8f02f49 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -722,7 +722,7 @@ macro_rules! make_mir_visitor { self.visit_ty(ty, TyContext::LocalDecl { local, - source_info: *visibility_source_info, + source_info: *syntactic_source_info, }); self.visit_source_info(syntactic_source_info); self.visit_source_info(visibility_source_info); diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 48de30f1ff1..38472418aab 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { // Internal locals are used in the `move_val_init` desugaring. // We want to check unsafety against the source info of the // desugaring, rather than the source info of the RHS. - self.source_info = self.mir.local_decls[local].visibility_source_info; + self.source_info = self.mir.local_decls[local].syntactic_source_info; } } let base_ty = base.ty(self.mir, self.tcx).to_ty(self.tcx); diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index bf01619d5b0..520b7dfac4f 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -467,8 +467,8 @@ fn write_scope_tree( // User variable types (including the user's name in a comment). for local in mir.vars_iter() { let var = &mir.local_decls[local]; - let (name, source_info) = if var.visibility_source_info.scope == child { - (var.name.unwrap(), var.visibility_source_info) + let (name, source_info) = if var.syntactic_source_info.scope == child { + (var.name.unwrap(), var.syntactic_source_info) } else { // Not a variable or not declared in this scope. continue; diff --git a/src/test/mir-opt/box_expr.rs b/src/test/mir-opt/box_expr.rs index ed9c303a16f..8390a0d19ae 100644 --- a/src/test/mir-opt/box_expr.rs +++ b/src/test/mir-opt/box_expr.rs @@ -33,9 +33,10 @@ impl Drop for S { // START rustc.main.ElaborateDrops.before.mir // let mut _0: (); // scope 1 { +// } +// scope 2 { // let _1: std::boxed::Box; // } -// ... // let mut _2: std::boxed::Box; // let mut _3: (); // let mut _4: std::boxed::Box; diff --git a/src/test/mir-opt/end_region_1.rs b/src/test/mir-opt/end_region_1.rs index 640dec0861d..184459aa90e 100644 --- a/src/test/mir-opt/end_region_1.rs +++ b/src/test/mir-opt/end_region_1.rs @@ -22,10 +22,10 @@ fn main() { // START rustc.main.SimplifyCfg-qualify-consts.after.mir // let mut _0: (); // ... -// let _1: i32; -// ... // let _2: &'10_1rs i32; // ... +// let _1: i32; +// ... // bb0: { // StorageLive(_1); // _1 = const 3i32; diff --git a/src/test/mir-opt/end_region_2.rs b/src/test/mir-opt/end_region_2.rs index 3fb5621c8ae..c40ab5253a0 100644 --- a/src/test/mir-opt/end_region_2.rs +++ b/src/test/mir-opt/end_region_2.rs @@ -27,11 +27,11 @@ fn main() { // START rustc.main.SimplifyCfg-qualify-consts.after.mir // let mut _0: (); // ... -// let _2: bool; +// let _7: &'23_3rs bool; // ... // let _3: &'23_1rs bool; // ... -// let _7: &'23_3rs bool; +// let _2: bool; // ... // let mut _4: (); // let mut _5: bool; diff --git a/src/test/mir-opt/end_region_3.rs b/src/test/mir-opt/end_region_3.rs index 070bde8e3c3..086d80d15ea 100644 --- a/src/test/mir-opt/end_region_3.rs +++ b/src/test/mir-opt/end_region_3.rs @@ -28,11 +28,11 @@ fn main() { // START rustc.main.SimplifyCfg-qualify-consts.after.mir // let mut _0: (); // ... -// let mut _1: bool; +// let _7: &'26_3rs bool; // ... // let _3: &'26_1rs bool; // ... -// let _7: &'26_3rs bool; +// let mut _1: bool; // ... // let mut _2: (); // let mut _4: (); diff --git a/src/test/mir-opt/end_region_4.rs b/src/test/mir-opt/end_region_4.rs index ded818688d7..fc58e0824e8 100644 --- a/src/test/mir-opt/end_region_4.rs +++ b/src/test/mir-opt/end_region_4.rs @@ -32,13 +32,13 @@ fn foo(i: i32) { // START rustc.main.SimplifyCfg-qualify-consts.after.mir // let mut _0: (); // ... -// let _1: D; -// ... -// let _2: i32; +// let _6: &'26_4rs i32; // ... // let _3: &'26_2rs i32; // ... -// let _6: &'26_4rs i32; +// let _2: i32; +// ... +// let _1: D; // ... // let mut _4: (); // let mut _5: i32; diff --git a/src/test/mir-opt/end_region_8.rs b/src/test/mir-opt/end_region_8.rs index d621cdb4d58..96a64f2eebf 100644 --- a/src/test/mir-opt/end_region_8.rs +++ b/src/test/mir-opt/end_region_8.rs @@ -31,10 +31,10 @@ fn foo(f: F) where F: FnOnce() -> i32 { // fn main() -> () { // let mut _0: (); // ... -// let _1: D; -// ... // let _2: &'21_1rs D; // ... +// let _1: D; +// ... // let mut _3: (); // let mut _4: [closure@NodeId(22) r:&'19s D]; // let mut _5: &'21_1rs D; diff --git a/src/test/mir-opt/end_region_9.rs b/src/test/mir-opt/end_region_9.rs index 6d9a27eeeb4..15c31e17875 100644 --- a/src/test/mir-opt/end_region_9.rs +++ b/src/test/mir-opt/end_region_9.rs @@ -41,11 +41,11 @@ fn main() { // fn main() -> () { // let mut _0: (); // ... -// let mut _1: bool; +// let mut _4: &'33_0rs i32; // ... // let _2: i32; // ... -// let mut _4: &'33_0rs i32; +// let mut _1: bool; // ... // let mut _3: (); // let mut _5: !; diff --git a/src/test/mir-opt/end_region_cyclic.rs b/src/test/mir-opt/end_region_cyclic.rs index 9c939d0d2fb..2d6962c5a5c 100644 --- a/src/test/mir-opt/end_region_cyclic.rs +++ b/src/test/mir-opt/end_region_cyclic.rs @@ -43,9 +43,9 @@ fn query() -> bool { true } // fn main() -> (){ // let mut _0: (); // scope 1 { -// let _2: S<'36_0rs>; // } // scope 2 { +// let _2: S<'36_0rs>; // } // let mut _1: (); // let mut _3: std::cell::Cell>>; diff --git a/src/test/mir-opt/issue-41110.rs b/src/test/mir-opt/issue-41110.rs index f7f447cc6ba..e43b4052e07 100644 --- a/src/test/mir-opt/issue-41110.rs +++ b/src/test/mir-opt/issue-41110.rs @@ -40,9 +40,10 @@ impl S { // START rustc.main.ElaborateDrops.after.mir // let mut _0: (); // scope 1 { +// } +// scope 2 { // let _1: (); // } -// ... // let mut _2: S; // let mut _3: S; // let mut _4: S; @@ -52,10 +53,10 @@ impl S { // START rustc.test.ElaborateDrops.after.mir // let mut _0: (); // ... -// let _1: S; -// ... // let mut _2: S; // ... +// let _1: S; +// ... // let mut _3: (); // let mut _4: S; // let mut _5: S; diff --git a/src/test/mir-opt/nll/reborrow-basic.rs b/src/test/mir-opt/nll/reborrow-basic.rs index b7c8d81b77f..94a6a9799cf 100644 --- a/src/test/mir-opt/nll/reborrow-basic.rs +++ b/src/test/mir-opt/nll/reborrow-basic.rs @@ -32,7 +32,7 @@ fn main() { // ... // | '_#9r | {bb0[10], bb0[14..=17]} // ... -// let _2: &'_#7r mut i32; -// ... // let _4: &'_#9r mut i32; +// ... +// let _2: &'_#7r mut i32; // END rustc.main.nll.0.mir diff --git a/src/test/mir-opt/nll/region-subtyping-basic.rs b/src/test/mir-opt/nll/region-subtyping-basic.rs index 16952143d0a..57a11d8dd25 100644 --- a/src/test/mir-opt/nll/region-subtyping-basic.rs +++ b/src/test/mir-opt/nll/region-subtyping-basic.rs @@ -37,10 +37,10 @@ fn main() { // | '_#4r | {bb2[5..=6], bb3[0..=1]} // END rustc.main.nll.0.mir // START rustc.main.nll.0.mir -// let _2: &'_#3r usize; -// ... // let _6: &'_#4r usize; // ... +// let _2: &'_#3r usize; +// ... // _2 = &'_#2r _1[_3]; // ... // _7 = _2; diff --git a/src/test/mir-opt/packed-struct-drop-aligned.rs b/src/test/mir-opt/packed-struct-drop-aligned.rs index 1b114419448..9441c6f4085 100644 --- a/src/test/mir-opt/packed-struct-drop-aligned.rs +++ b/src/test/mir-opt/packed-struct-drop-aligned.rs @@ -29,9 +29,9 @@ impl Drop for Droppy { // fn main() -> () { // let mut _0: (); // scope 1 { -// let mut _1: Packed; // } // scope 2 { +// let mut _1: Packed; // } // let mut _2: Aligned; // let mut _3: Droppy; diff --git a/src/test/mir-opt/validate_3.rs b/src/test/mir-opt/validate_3.rs index 79645bd3600..72ec9ce400f 100644 --- a/src/test/mir-opt/validate_3.rs +++ b/src/test/mir-opt/validate_3.rs @@ -32,14 +32,14 @@ fn main() { // fn main() -> (){ // let mut _0: (); // scope 1 { -// let _1: Test; // scope 3 { -// let _2: &ReErased Test; // } // scope 4 { +// let _2: &ReErased Test; // } // } // scope 2 { +// let _1: Test; // } // let mut _3: (); // let mut _4: &ReErased i32; From 6c5397247856d49d89712f9d0c208c1981e9b72d Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 29 May 2018 13:55:21 +0300 Subject: [PATCH 6/7] rustc: turn mir::LocalDecl's visibility_source_info into a SourceScope. --- src/librustc/ich/impls_mir.rs | 2 +- src/librustc/mir/mod.rs | 29 +++++++------------ src/librustc/mir/visit.rs | 4 +-- .../debuginfo/create_scope_map.rs | 2 +- src/librustc_codegen_llvm/mir/mod.rs | 7 +++-- .../borrow_check/error_reporting.rs | 2 +- src/librustc_mir/borrow_check/mod.rs | 6 ++-- .../borrow_check/nll/explain_borrow/mod.rs | 2 +- .../borrow_check/nll/type_check/mod.rs | 2 +- src/librustc_mir/build/expr/into.rs | 2 +- src/librustc_mir/build/matches/mod.rs | 17 +++++------ src/librustc_mir/build/mod.rs | 2 +- .../dataflow/move_paths/builder.rs | 2 +- src/librustc_mir/shim.rs | 2 +- src/librustc_mir/transform/generator.rs | 6 ++-- src/librustc_mir/transform/inline.rs | 4 +-- src/librustc_mir/transform/promote_consts.rs | 4 +-- src/librustc_mir/transform/qualify_consts.rs | 4 +-- 18 files changed, 44 insertions(+), 55 deletions(-) diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index e5d28fdf785..15240570a7a 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -26,7 +26,7 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> { ty, name, syntactic_source_info, - visibility_source_info, + visibility_scope, internal, is_user_variable }); diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 2251d4a4b60..998af9ebcfe 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -558,7 +558,7 @@ pub struct LocalDecl<'tcx> { /// To allow both uses to work, we need to have more than a single scope /// for a local. We have the `syntactic_source_info.scope` represent the /// "syntactic" lint scope (with a variable being under its let - /// block) while the `visibility_source_info.scope` represents the "local variable" + /// block) while the `visibility_scope` represents the "local variable" /// scope (where the "rest" of a block is under all prior let-statements). /// /// The end result looks like this: @@ -577,18 +577,18 @@ pub struct LocalDecl<'tcx> { /// │ │ /// │ │ │{ let y: u32 } /// │ │ │ - /// │ │ │← y.visibility_source_info.scope + /// │ │ │← y.visibility_scope /// │ │ │← `y + 2` /// │ /// │ │{ let x: u32 } - /// │ │← x.visibility_source_info.scope + /// │ │← x.visibility_scope /// │ │← `drop(x)` // this accesses `x: u32` /// ``` pub syntactic_source_info: SourceInfo, - /// Source info of the local. The `SourceScope` is the *visibility* one, - /// not the the *syntactic* one (see `syntactic_source_info` for more details). - pub visibility_source_info: SourceInfo, + /// Source scope within which the local is visible (for debuginfo) + /// (see `syntactic_source_info` for more details). + pub visibility_scope: SourceScope, } impl<'tcx> LocalDecl<'tcx> { @@ -603,10 +603,7 @@ impl<'tcx> LocalDecl<'tcx> { span, scope: OUTERMOST_SOURCE_SCOPE }, - visibility_source_info: SourceInfo { - span, - scope: OUTERMOST_SOURCE_SCOPE - }, + visibility_scope: OUTERMOST_SOURCE_SCOPE, internal: false, is_user_variable: false } @@ -623,10 +620,7 @@ impl<'tcx> LocalDecl<'tcx> { span, scope: OUTERMOST_SOURCE_SCOPE }, - visibility_source_info: SourceInfo { - span, - scope: OUTERMOST_SOURCE_SCOPE - }, + visibility_scope: OUTERMOST_SOURCE_SCOPE, internal: true, is_user_variable: false } @@ -644,10 +638,7 @@ impl<'tcx> LocalDecl<'tcx> { span, scope: OUTERMOST_SOURCE_SCOPE }, - visibility_source_info: SourceInfo { - span, - scope: OUTERMOST_SOURCE_SCOPE - }, + visibility_scope: OUTERMOST_SOURCE_SCOPE, internal: false, name: None, // FIXME maybe we do want some name here? is_user_variable: false @@ -2201,7 +2192,7 @@ BraceStructTypeFoldableImpl! { ty, name, syntactic_source_info, - visibility_source_info, + visibility_scope, } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 3a1a8f02f49..6cd1271cccf 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -715,7 +715,7 @@ macro_rules! make_mir_visitor { ref $($mutability)* ty, name: _, ref $($mutability)* syntactic_source_info, - ref $($mutability)* visibility_source_info, + ref $($mutability)* visibility_scope, internal: _, is_user_variable: _, } = *local_decl; @@ -725,7 +725,7 @@ macro_rules! make_mir_visitor { source_info: *syntactic_source_info, }); self.visit_source_info(syntactic_source_info); - self.visit_source_info(visibility_source_info); + self.visit_source_scope(visibility_scope); } fn super_source_scope(&mut self, diff --git a/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs b/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs index 81d8e510d11..9ced0f5f4ec 100644 --- a/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs +++ b/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs @@ -65,7 +65,7 @@ pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebu let mut has_variables = BitVector::new(mir.source_scopes.len()); for var in mir.vars_iter() { let decl = &mir.local_decls[var]; - has_variables.insert(decl.visibility_source_info.scope.index()); + has_variables.insert(decl.visibility_scope.index()); } // Instantiate all scopes. diff --git a/src/librustc_codegen_llvm/mir/mod.rs b/src/librustc_codegen_llvm/mir/mod.rs index 8dd8cc3f4bc..26680937d41 100644 --- a/src/librustc_codegen_llvm/mir/mod.rs +++ b/src/librustc_codegen_llvm/mir/mod.rs @@ -265,7 +265,7 @@ pub fn codegen_mir<'a, 'tcx: 'a>( if let Some(name) = decl.name { // User variable - let debug_scope = fx.scopes[decl.visibility_source_info.scope]; + let debug_scope = fx.scopes[decl.visibility_scope]; let dbg = debug_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo; if !memory_locals.contains(local.index()) && !dbg { @@ -276,7 +276,10 @@ pub fn codegen_mir<'a, 'tcx: 'a>( debug!("alloc: {:?} ({}) -> place", local, name); let place = PlaceRef::alloca(&bx, layout, &name.as_str()); if dbg { - let (scope, span) = fx.debug_loc(decl.visibility_source_info); + let (scope, span) = fx.debug_loc(mir::SourceInfo { + span: decl.syntactic_source_info.span, + scope: decl.visibility_scope, + }); declare_local(&bx, &fx.debug_context, name, layout.ty, scope, VariableAccess::DirectVariable { alloca: place.llval }, VariableKind::LocalVariable, span); diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index eedf8decd16..9b5e266917b 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -398,7 +398,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { let borrow_span = self.mir.source_info(borrow.reserve_location).span; let proper_span = match *root_place { - Place::Local(local) => self.mir.local_decls[local].visibility_source_info.span, + Place::Local(local) => self.mir.local_decls[local].syntactic_source_info.span, _ => drop_span, }; diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 7b6bec06fa6..2c5d9156f2e 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -306,13 +306,13 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( None => continue, } - let source_info = local_decl.visibility_source_info; - let mut_span = tcx.sess.codemap().span_until_non_whitespace(source_info.span); + let span = local_decl.syntactic_source_info.span; + let mut_span = tcx.sess.codemap().span_until_non_whitespace(span); tcx.struct_span_lint_node( UNUSED_MUT, vsi[local_decl.syntactic_source_info.scope].lint_root, - source_info.span, + span, "variable does not need to be mutable" ) .span_suggestion_short(mut_span, "remove this `mut`", "".to_owned()) diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs index 88b9afbd138..10a0e4e127d 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs @@ -67,7 +67,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { } None => { err.span_label( - mir.local_decls[local].visibility_source_info.span, + mir.local_decls[local].syntactic_source_info.span, "borrow may end up in a temporary, created here", ); diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index f8a0eb3749c..bad5b40d340 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1201,7 +1201,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { LocalKind::Var | LocalKind::Temp => {} } - let span = local_decl.visibility_source_info.span; + let span = local_decl.syntactic_source_info.span; let ty = local_decl.ty; // Erase the regions from `ty` to get a global type. The diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index 049d4340193..398c619c0b1 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -247,7 +247,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ty: ptr_ty, name: None, syntactic_source_info: source_info, - visibility_source_info: source_info, + visibility_scope: source_info.scope, internal: true, is_user_variable: false }); diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index e6ad36f3034..91812da2534 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -324,11 +324,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { span, scope: syntactic_scope, }; - let visibility_source_info = SourceInfo { - span, - scope: visibility_scope.unwrap() - }; - this.declare_binding(syntactic_source_info, visibility_source_info, mutability, name, var, + let visibility_scope = visibility_scope.unwrap(); + this.declare_binding(syntactic_source_info, visibility_scope, mutability, name, var, ty, has_guard); }); visibility_scope @@ -1118,16 +1115,16 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// in the arm body, which will have type `T`. fn declare_binding(&mut self, syntactic_source_info: SourceInfo, - visibility_source_info: SourceInfo, + visibility_scope: SourceScope, mutability: Mutability, name: Name, var_id: NodeId, var_ty: Ty<'tcx>, has_guard: ArmHasGuard) { - debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, visibility_source_info={:?}, \ + debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, visibility_scope={:?}, \ syntactic_source_info={:?})", - var_id, name, var_ty, visibility_source_info, syntactic_source_info); + var_id, name, var_ty, visibility_scope, syntactic_source_info); let tcx = self.hir.tcx(); let local = LocalDecl::<'tcx> { @@ -1135,7 +1132,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ty: var_ty.clone(), name: Some(name), syntactic_source_info, - visibility_source_info, + visibility_scope, internal: false, is_user_variable: true, }; @@ -1147,7 +1144,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty), name: Some(name), syntactic_source_info, - visibility_source_info, + visibility_scope, internal: false, is_user_variable: true, }); diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 527e605a16a..ea3a6ae68e7 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -665,7 +665,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { mutability: Mutability::Mut, ty, syntactic_source_info: source_info, - visibility_source_info: source_info, + visibility_scope: source_info.scope, name, internal: false, is_user_variable: false, diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index 321f307a43c..2c6828d7cf9 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -233,7 +233,7 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> { fn gather_args(&mut self) { for arg in self.mir.args_iter() { let path = self.data.rev_lookup.locals[arg]; - let span = self.mir.local_decls[arg].visibility_source_info.span; + let span = self.mir.local_decls[arg].syntactic_source_info.span; let init = self.data.inits.push(Init { path, span, kind: InitKind::Deep diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index f168292897e..19967cc323f 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -142,7 +142,7 @@ fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl { LocalDecl { mutability, ty, name: None, syntactic_source_info: source_info, - visibility_source_info: source_info, + visibility_scope: source_info.scope, internal: false, is_user_variable: false } diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 940a13a42df..d084d09971d 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -301,7 +301,7 @@ fn replace_result_variable<'tcx>(ret_ty: Ty<'tcx>, ty: ret_ty, name: None, syntactic_source_info: source_info, - visibility_source_info: source_info, + visibility_scope: source_info.scope, internal: false, is_user_variable: false, }; @@ -642,7 +642,7 @@ fn create_generator_drop_shim<'a, 'tcx>( ty: tcx.mk_nil(), name: None, syntactic_source_info: source_info, - visibility_source_info: source_info, + visibility_scope: source_info.scope, internal: false, is_user_variable: false, }; @@ -658,7 +658,7 @@ fn create_generator_drop_shim<'a, 'tcx>( }), name: None, syntactic_source_info: source_info, - visibility_source_info: source_info, + visibility_scope: source_info.scope, internal: false, is_user_variable: false, }; diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 868d7cadde4..cc1da268d68 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -401,9 +401,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { local.syntactic_source_info.scope = scope_map[local.syntactic_source_info.scope]; local.syntactic_source_info.span = callsite.location.span; - local.visibility_source_info.scope = - scope_map[local.visibility_source_info.scope]; - local.visibility_source_info.span = callsite.location.span; + local.visibility_scope = scope_map[local.visibility_scope]; let idx = caller_mir.local_decls.push(local); local_map.push(idx); diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 98cc0ed8234..c61d5e268a9 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -210,7 +210,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let no_stmts = self.source[loc.block].statements.len(); let new_temp = self.promoted.local_decls.push( LocalDecl::new_temp(self.source.local_decls[temp].ty, - self.source.local_decls[temp].visibility_source_info.span)); + self.source.local_decls[temp].syntactic_source_info.span)); debug!("promote({:?} @ {:?}/{:?}, {:?})", temp, loc, no_stmts, self.keep_original); @@ -335,7 +335,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { // otherwise we would use the `promoted` directly. let mut promoted_ref = LocalDecl::new_temp(ref_ty, span); promoted_ref.syntactic_source_info = statement.source_info; - promoted_ref.visibility_source_info = statement.source_info; + promoted_ref.visibility_scope = statement.source_info.scope; let promoted_ref = local_decls.push(promoted_ref); assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref); self.extra_statements.push((loc, Statement { diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 05e232753d7..828d8fa60e8 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1046,7 +1046,7 @@ This does not pose a problem by itself because they can't be accessed directly." // conservatively, that drop elaboration will do. let needs_drop = if let Place::Local(local) = *place { if self.local_qualif[local].map_or(true, |q| q.intersects(Qualif::NEEDS_DROP)) { - Some(self.mir.local_decls[local].visibility_source_info.span) + Some(self.mir.local_decls[local].syntactic_source_info.span) } else { None } @@ -1102,7 +1102,7 @@ This does not pose a problem by itself because they can't be accessed directly." let mut err = feature_err( &self.tcx.sess.parse_sess, "const_let", - decl.visibility_source_info.span, + decl.syntactic_source_info.span, GateIssue::Language, "arguments of constant functions can only be immutable by-value bindings" ); From 06d88cda088783c3751074d2debaf6bb1ca542c3 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 29 May 2018 21:31:33 +0300 Subject: [PATCH 7/7] rustc: rename mir::LocalDecl's syntactic_source_info to source_info. --- src/librustc/ich/impls_mir.rs | 2 +- src/librustc/mir/mod.rs | 18 +++++++-------- src/librustc/mir/visit.rs | 6 ++--- src/librustc_codegen_llvm/mir/mod.rs | 2 +- .../borrow_check/error_reporting.rs | 2 +- src/librustc_mir/borrow_check/mod.rs | 4 ++-- .../borrow_check/nll/explain_borrow/mod.rs | 2 +- .../borrow_check/nll/type_check/mod.rs | 2 +- src/librustc_mir/build/expr/into.rs | 2 +- src/librustc_mir/build/matches/mod.rs | 22 +++++++++---------- src/librustc_mir/build/mod.rs | 2 +- .../dataflow/move_paths/builder.rs | 2 +- src/librustc_mir/shim.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 2 +- src/librustc_mir/transform/generator.rs | 6 ++--- src/librustc_mir/transform/inline.rs | 6 ++--- src/librustc_mir/transform/promote_consts.rs | 4 ++-- src/librustc_mir/transform/qualify_consts.rs | 4 ++-- src/librustc_mir/util/pretty.rs | 4 ++-- 19 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index 15240570a7a..f43ac7ad0dd 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -25,7 +25,7 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> { mutability, ty, name, - syntactic_source_info, + source_info, visibility_scope, internal, is_user_variable diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 998af9ebcfe..b2ff36cb87c 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -556,7 +556,7 @@ pub struct LocalDecl<'tcx> { /// `drop(x)`, we want it to refer to `x: u32`. /// /// To allow both uses to work, we need to have more than a single scope - /// for a local. We have the `syntactic_source_info.scope` represent the + /// for a local. We have the `source_info.scope` represent the /// "syntactic" lint scope (with a variable being under its let /// block) while the `visibility_scope` represents the "local variable" /// scope (where the "rest" of a block is under all prior let-statements). @@ -570,10 +570,10 @@ pub struct LocalDecl<'tcx> { /// │ │{ #[allow(unused_mut] } // this is actually split into 2 scopes /// │ │ // in practice because I'm lazy. /// │ │ - /// │ │← x.syntactic_source_info.scope + /// │ │← x.source_info.scope /// │ │← `x.parse().unwrap()` /// │ │ - /// │ │ │← y.syntactic_source_info.scope + /// │ │ │← y.source_info.scope /// │ │ /// │ │ │{ let y: u32 } /// │ │ │ @@ -584,10 +584,10 @@ pub struct LocalDecl<'tcx> { /// │ │← x.visibility_scope /// │ │← `drop(x)` // this accesses `x: u32` /// ``` - pub syntactic_source_info: SourceInfo, + pub source_info: SourceInfo, /// Source scope within which the local is visible (for debuginfo) - /// (see `syntactic_source_info` for more details). + /// (see `source_info` for more details). pub visibility_scope: SourceScope, } @@ -599,7 +599,7 @@ impl<'tcx> LocalDecl<'tcx> { mutability: Mutability::Mut, ty, name: None, - syntactic_source_info: SourceInfo { + source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }, @@ -616,7 +616,7 @@ impl<'tcx> LocalDecl<'tcx> { mutability: Mutability::Mut, ty, name: None, - syntactic_source_info: SourceInfo { + source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }, @@ -634,7 +634,7 @@ impl<'tcx> LocalDecl<'tcx> { LocalDecl { mutability: Mutability::Mut, ty: return_ty, - syntactic_source_info: SourceInfo { + source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }, @@ -2191,7 +2191,7 @@ BraceStructTypeFoldableImpl! { internal, ty, name, - syntactic_source_info, + source_info, visibility_scope, } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 6cd1271cccf..758d887cd7b 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -714,7 +714,7 @@ macro_rules! make_mir_visitor { mutability: _, ref $($mutability)* ty, name: _, - ref $($mutability)* syntactic_source_info, + ref $($mutability)* source_info, ref $($mutability)* visibility_scope, internal: _, is_user_variable: _, @@ -722,9 +722,9 @@ macro_rules! make_mir_visitor { self.visit_ty(ty, TyContext::LocalDecl { local, - source_info: *syntactic_source_info, + source_info: *source_info, }); - self.visit_source_info(syntactic_source_info); + self.visit_source_info(source_info); self.visit_source_scope(visibility_scope); } diff --git a/src/librustc_codegen_llvm/mir/mod.rs b/src/librustc_codegen_llvm/mir/mod.rs index 26680937d41..f9be91b4f3f 100644 --- a/src/librustc_codegen_llvm/mir/mod.rs +++ b/src/librustc_codegen_llvm/mir/mod.rs @@ -277,7 +277,7 @@ pub fn codegen_mir<'a, 'tcx: 'a>( let place = PlaceRef::alloca(&bx, layout, &name.as_str()); if dbg { let (scope, span) = fx.debug_loc(mir::SourceInfo { - span: decl.syntactic_source_info.span, + span: decl.source_info.span, scope: decl.visibility_scope, }); declare_local(&bx, &fx.debug_context, name, layout.ty, scope, diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 9b5e266917b..9061af1b68c 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -398,7 +398,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { let borrow_span = self.mir.source_info(borrow.reserve_location).span; let proper_span = match *root_place { - Place::Local(local) => self.mir.local_decls[local].syntactic_source_info.span, + Place::Local(local) => self.mir.local_decls[local].source_info.span, _ => drop_span, }; diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 2c5d9156f2e..5efbdeafd1b 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -306,12 +306,12 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( None => continue, } - let span = local_decl.syntactic_source_info.span; + let span = local_decl.source_info.span; let mut_span = tcx.sess.codemap().span_until_non_whitespace(span); tcx.struct_span_lint_node( UNUSED_MUT, - vsi[local_decl.syntactic_source_info.scope].lint_root, + vsi[local_decl.source_info.scope].lint_root, span, "variable does not need to be mutable" ) diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs index 10a0e4e127d..2807a4e8857 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs @@ -67,7 +67,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { } None => { err.span_label( - mir.local_decls[local].syntactic_source_info.span, + mir.local_decls[local].source_info.span, "borrow may end up in a temporary, created here", ); diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index bad5b40d340..04f5024b769 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1201,7 +1201,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { LocalKind::Var | LocalKind::Temp => {} } - let span = local_decl.syntactic_source_info.span; + let span = local_decl.source_info.span; let ty = local_decl.ty; // Erase the regions from `ty` to get a global type. The diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index 398c619c0b1..fbd771fbe50 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -246,7 +246,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { mutability: Mutability::Mut, ty: ptr_ty, name: None, - syntactic_source_info: source_info, + source_info, visibility_scope: source_info.scope, internal: true, is_user_variable: false diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 91812da2534..062a48a8c43 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -306,7 +306,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { -> Option { assert!(!(visibility_scope.is_some() && lint_level.is_explicit()), "can't have both a visibility and a lint scope at the same time"); - let mut syntactic_scope = self.source_scope; + let mut scope = self.source_scope; self.visit_bindings(pattern, &mut |this, mutability, name, var, span, ty| { if visibility_scope.is_none() { visibility_scope = Some(this.new_source_scope(scope_span, @@ -314,18 +314,18 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { None)); // If we have lints, create a new source scope // that marks the lints for the locals. See the comment - // on the `syntactic_source_info` field for why this is needed. + // on the `source_info` field for why this is needed. if lint_level.is_explicit() { - syntactic_scope = + scope = this.new_source_scope(scope_span, lint_level, None); } } - let syntactic_source_info = SourceInfo { + let source_info = SourceInfo { span, - scope: syntactic_scope, + scope, }; let visibility_scope = visibility_scope.unwrap(); - this.declare_binding(syntactic_source_info, visibility_scope, mutability, name, var, + this.declare_binding(source_info, visibility_scope, mutability, name, var, ty, has_guard); }); visibility_scope @@ -1114,7 +1114,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// `&T`. The second local is a binding for occurrences of `var` /// in the arm body, which will have type `T`. fn declare_binding(&mut self, - syntactic_source_info: SourceInfo, + source_info: SourceInfo, visibility_scope: SourceScope, mutability: Mutability, name: Name, @@ -1123,15 +1123,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { has_guard: ArmHasGuard) { debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, visibility_scope={:?}, \ - syntactic_source_info={:?})", - var_id, name, var_ty, visibility_scope, syntactic_source_info); + source_info={:?})", + var_id, name, var_ty, visibility_scope, source_info); let tcx = self.hir.tcx(); let local = LocalDecl::<'tcx> { mutability, ty: var_ty.clone(), name: Some(name), - syntactic_source_info, + source_info, visibility_scope, internal: false, is_user_variable: true, @@ -1143,7 +1143,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { mutability, ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty), name: Some(name), - syntactic_source_info, + source_info, visibility_scope, internal: false, is_user_variable: true, diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index ea3a6ae68e7..ca7a2daf39d 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -664,7 +664,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { self.local_decls.push(LocalDecl { mutability: Mutability::Mut, ty, - syntactic_source_info: source_info, + source_info, visibility_scope: source_info.scope, name, internal: false, diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index 2c6828d7cf9..2ff22842141 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -233,7 +233,7 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> { fn gather_args(&mut self) { for arg in self.mir.args_iter() { let path = self.data.rev_lookup.locals[arg]; - let span = self.mir.local_decls[arg].syntactic_source_info.span; + let span = self.mir.local_decls[arg].source_info.span; let init = self.data.inits.push(Init { path, span, kind: InitKind::Deep diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 19967cc323f..d4a9b2cdd1f 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -141,7 +141,7 @@ fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl { let source_info = SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span }; LocalDecl { mutability, ty, name: None, - syntactic_source_info: source_info, + source_info, visibility_scope: source_info.scope, internal: false, is_user_variable: false diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 38472418aab..fedd0774df4 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { // Internal locals are used in the `move_val_init` desugaring. // We want to check unsafety against the source info of the // desugaring, rather than the source info of the RHS. - self.source_info = self.mir.local_decls[local].syntactic_source_info; + self.source_info = self.mir.local_decls[local].source_info; } } let base_ty = base.ty(self.mir, self.tcx).to_ty(self.tcx); diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index d084d09971d..7ac3b7beb06 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -300,7 +300,7 @@ fn replace_result_variable<'tcx>(ret_ty: Ty<'tcx>, mutability: Mutability::Mut, ty: ret_ty, name: None, - syntactic_source_info: source_info, + source_info, visibility_scope: source_info.scope, internal: false, is_user_variable: false, @@ -641,7 +641,7 @@ fn create_generator_drop_shim<'a, 'tcx>( mutability: Mutability::Mut, ty: tcx.mk_nil(), name: None, - syntactic_source_info: source_info, + source_info, visibility_scope: source_info.scope, internal: false, is_user_variable: false, @@ -657,7 +657,7 @@ fn create_generator_drop_shim<'a, 'tcx>( mutbl: hir::Mutability::MutMutable, }), name: None, - syntactic_source_info: source_info, + source_info, visibility_scope: source_info.scope, internal: false, is_user_variable: false, diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index cc1da268d68..a1845f7ef26 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -398,9 +398,9 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { for loc in callee_mir.vars_and_temps_iter() { let mut local = callee_mir.local_decls[loc].clone(); - local.syntactic_source_info.scope = - scope_map[local.syntactic_source_info.scope]; - local.syntactic_source_info.span = callsite.location.span; + local.source_info.scope = + scope_map[local.source_info.scope]; + local.source_info.span = callsite.location.span; local.visibility_scope = scope_map[local.visibility_scope]; let idx = caller_mir.local_decls.push(local); diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index c61d5e268a9..8dc6539b65d 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -210,7 +210,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let no_stmts = self.source[loc.block].statements.len(); let new_temp = self.promoted.local_decls.push( LocalDecl::new_temp(self.source.local_decls[temp].ty, - self.source.local_decls[temp].syntactic_source_info.span)); + self.source.local_decls[temp].source_info.span)); debug!("promote({:?} @ {:?}/{:?}, {:?})", temp, loc, no_stmts, self.keep_original); @@ -334,7 +334,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { // This is because `*r` requires `r` to be a local, // otherwise we would use the `promoted` directly. let mut promoted_ref = LocalDecl::new_temp(ref_ty, span); - promoted_ref.syntactic_source_info = statement.source_info; + promoted_ref.source_info = statement.source_info; promoted_ref.visibility_scope = statement.source_info.scope; let promoted_ref = local_decls.push(promoted_ref); assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref); diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 828d8fa60e8..71963012944 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1046,7 +1046,7 @@ This does not pose a problem by itself because they can't be accessed directly." // conservatively, that drop elaboration will do. let needs_drop = if let Place::Local(local) = *place { if self.local_qualif[local].map_or(true, |q| q.intersects(Qualif::NEEDS_DROP)) { - Some(self.mir.local_decls[local].syntactic_source_info.span) + Some(self.mir.local_decls[local].source_info.span) } else { None } @@ -1102,7 +1102,7 @@ This does not pose a problem by itself because they can't be accessed directly." let mut err = feature_err( &self.tcx.sess.parse_sess, "const_let", - decl.syntactic_source_info.span, + decl.source_info.span, GateIssue::Language, "arguments of constant functions can only be immutable by-value bindings" ); diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 520b7dfac4f..8176c644dd7 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -467,8 +467,8 @@ fn write_scope_tree( // User variable types (including the user's name in a comment). for local in mir.vars_iter() { let var = &mir.local_decls[local]; - let (name, source_info) = if var.syntactic_source_info.scope == child { - (var.name.unwrap(), var.syntactic_source_info) + let (name, source_info) = if var.source_info.scope == child { + (var.name.unwrap(), var.source_info) } else { // Not a variable or not declared in this scope. continue;