]> git.lizzy.rs Git - rust.git/commitdiff
rustc: turn mir::LocalDecl's visibility_source_info into a SourceScope.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Tue, 29 May 2018 10:55:21 +0000 (13:55 +0300)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Wed, 30 May 2018 17:30:10 +0000 (20:30 +0300)
18 files changed:
src/librustc/ich/impls_mir.rs
src/librustc/mir/mod.rs
src/librustc/mir/visit.rs
src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
src/librustc_codegen_llvm/mir/mod.rs
src/librustc_mir/borrow_check/error_reporting.rs
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs
src/librustc_mir/build/expr/into.rs
src/librustc_mir/build/matches/mod.rs
src/librustc_mir/build/mod.rs
src/librustc_mir/dataflow/move_paths/builder.rs
src/librustc_mir/shim.rs
src/librustc_mir/transform/generator.rs
src/librustc_mir/transform/inline.rs
src/librustc_mir/transform/promote_consts.rs
src/librustc_mir/transform/qualify_consts.rs

index e5d28fdf785fcea08460ccfc85d3638206bbcb11..15240570a7ae224ade77cff6ba2558b615e2122f 100644 (file)
@@ -26,7 +26,7 @@
     ty,
     name,
     syntactic_source_info,
-    visibility_source_info,
+    visibility_scope,
     internal,
     is_user_variable
 });
index 2251d4a4b60998d4a84f50587b4ec2e9ad4a9384..998af9ebcfe7dfd95a597045216e1addd120bf39 100644 (file)
@@ -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 @@ pub fn new_temp(ty: Ty<'tcx>, span: Span) -> Self {
                 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 @@ pub fn new_internal(ty: Ty<'tcx>, span: Span) -> Self {
                 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 @@ pub fn new_return_place(return_ty: Ty, span: Span) -> LocalDecl {
                 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 @@ impl<'tcx> TypeFoldable<'tcx> for LocalDecl<'tcx> {
         ty,
         name,
         syntactic_source_info,
-        visibility_source_info,
+        visibility_scope,
     }
 }
 
index 3a1a8f02f4979c4d1652056df0c798605372f6ad..6cd1271cccff099d857303c08a88d14824d56e7e 100644 (file)
@@ -715,7 +715,7 @@ fn super_local_decl(&mut self,
                     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 @@ fn super_local_decl(&mut self,
                     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,
index 81d8e510d11ea293c5ab3449239e2c6944386368..9ced0f5f4eca13425a89369f90efa2dd6c68dd51 100644 (file)
@@ -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.
index 8dd8cc3f4bc610b67d4bb8a72b53526a999dac45..26680937d41d59d9466d6d01a84c89387fdd6184 100644 (file)
@@ -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);
index eedf8decd168dbc4cf5d2b25490a10aa078b86b2..9b5e266917b57bdc9a8486eb30eda48ca82df370 100644 (file)
@@ -398,7 +398,7 @@ pub(super) fn report_borrowed_value_does_not_live_long_enough(
 
         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,
         };
 
index 7b6bec06fa65ccb43fc8e448d556c45f288b3fc2..2c5d9156f2e04e5525d5eb7d2269733c33d846da 100644 (file)
@@ -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())
index 88b9afbd138627e6eb238c1f973fc92faad40a5d..10a0e4e127d2128a837d8f962082254bd9d4d341 100644 (file)
@@ -67,7 +67,7 @@ pub(in borrow_check) fn explain_why_borrow_contains_point(
                             }
                             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",
                                 );
 
index f8a0eb3749c0b64cf4009d0b4bb7e2f19d3a02fc..bad5b40d340d6261ee285e69828ad236494f5192 100644 (file)
@@ -1201,7 +1201,7 @@ fn check_local(&mut self, mir: &Mir<'tcx>, local: Local, local_decl: &LocalDecl<
             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
index 049d4340193af68d3b3bf7fa82a077bada0eb9f0..398c619c0b1a4419a86710691c48f2635ae83c65 100644 (file)
@@ -247,7 +247,7 @@ pub fn into_expr(&mut self,
                         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
                     });
index e6ad36f3034bb5ae156d86815e4f4c23a5b7fc66..91812da2534ef9ebaa9a1297d7eabbd96e101a44 100644 (file)
@@ -324,11 +324,8 @@ pub fn declare_bindings(&mut self,
                 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 @@ fn bind_matched_candidate_for_arm_body(&mut self,
     /// 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 @@ fn declare_binding(&mut self,
             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 @@ fn declare_binding(&mut self,
                 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,
             });
index 527e605a16ac1f16ab5160e1d0d2c669acea139c..ea3a6ae68e79aace48051b367130be4e8cf452a8 100644 (file)
@@ -665,7 +665,7 @@ fn args_and_body(&mut self,
                 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,
index 321f307a43c74069385c23285e94d8ee3ab8f36f..2c6828d7cf90817f54e2443f89be6e72b22235ef 100644 (file)
@@ -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
index f168292897ea90aa40c9ed2195fabc0935e51745..19967cc323f9a7070c2d66cf3af847633f6e201d 100644 (file)
@@ -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
     }
index 940a13a42df9f1a131c38c93ef4d3558f2eb82ec..d084d09971d46de126d461cbd443f4c897857888 100644 (file)
@@ -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,
     };
index 868d7cadde4ac90a6810d3b762d19fdf0ccd057e..cc1da268d68c176ef34c61d96361635db2648f0f 100644 (file)
@@ -401,9 +401,7 @@ fn inline_call(&self,
                     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);
index 98cc0ed8234a054d33583501499e979f0ebf0dba..c61d5e268a990e11eb7a5ae2b186b1a7fb99ffef 100644 (file)
@@ -210,7 +210,7 @@ fn promote_temp(&mut self, temp: Local) -> Local {
         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 @@ fn interior_base<'a, 'tcx>(place: &'a mut Place<'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 {
index 05e232753d716d2291652dd9317426ab56a509fa..828d8fa60e8ba5174ac953cc725da25b0545c71c 100644 (file)
@@ -1046,7 +1046,7 @@ fn visit_terminator_kind(&mut self,
                 // 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 @@ fn visit_assign(&mut self,
                     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"
                     );