Skip to content

Commit 6c53972

Browse files
committed
rustc: turn mir::LocalDecl's visibility_source_info into a SourceScope.
1 parent 3da186b commit 6c53972

File tree

18 files changed

+44
-55
lines changed

18 files changed

+44
-55
lines changed

src/librustc/ich/impls_mir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> {
2626
ty,
2727
name,
2828
syntactic_source_info,
29-
visibility_source_info,
29+
visibility_scope,
3030
internal,
3131
is_user_variable
3232
});

src/librustc/mir/mod.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ pub struct LocalDecl<'tcx> {
558558
/// To allow both uses to work, we need to have more than a single scope
559559
/// for a local. We have the `syntactic_source_info.scope` represent the
560560
/// "syntactic" lint scope (with a variable being under its let
561-
/// block) while the `visibility_source_info.scope` represents the "local variable"
561+
/// block) while the `visibility_scope` represents the "local variable"
562562
/// scope (where the "rest" of a block is under all prior let-statements).
563563
///
564564
/// The end result looks like this:
@@ -577,18 +577,18 @@ pub struct LocalDecl<'tcx> {
577577
/// │ │
578578
/// │ │ │{ let y: u32 }
579579
/// │ │ │
580-
/// │ │ │← y.visibility_source_info.scope
580+
/// │ │ │← y.visibility_scope
581581
/// │ │ │← `y + 2`
582582
/// │
583583
/// │ │{ let x: u32 }
584-
/// │ │← x.visibility_source_info.scope
584+
/// │ │← x.visibility_scope
585585
/// │ │← `drop(x)` // this accesses `x: u32`
586586
/// ```
587587
pub syntactic_source_info: SourceInfo,
588588

589-
/// Source info of the local. The `SourceScope` is the *visibility* one,
590-
/// not the the *syntactic* one (see `syntactic_source_info` for more details).
591-
pub visibility_source_info: SourceInfo,
589+
/// Source scope within which the local is visible (for debuginfo)
590+
/// (see `syntactic_source_info` for more details).
591+
pub visibility_scope: SourceScope,
592592
}
593593

594594
impl<'tcx> LocalDecl<'tcx> {
@@ -603,10 +603,7 @@ impl<'tcx> LocalDecl<'tcx> {
603603
span,
604604
scope: OUTERMOST_SOURCE_SCOPE
605605
},
606-
visibility_source_info: SourceInfo {
607-
span,
608-
scope: OUTERMOST_SOURCE_SCOPE
609-
},
606+
visibility_scope: OUTERMOST_SOURCE_SCOPE,
610607
internal: false,
611608
is_user_variable: false
612609
}
@@ -623,10 +620,7 @@ impl<'tcx> LocalDecl<'tcx> {
623620
span,
624621
scope: OUTERMOST_SOURCE_SCOPE
625622
},
626-
visibility_source_info: SourceInfo {
627-
span,
628-
scope: OUTERMOST_SOURCE_SCOPE
629-
},
623+
visibility_scope: OUTERMOST_SOURCE_SCOPE,
630624
internal: true,
631625
is_user_variable: false
632626
}
@@ -644,10 +638,7 @@ impl<'tcx> LocalDecl<'tcx> {
644638
span,
645639
scope: OUTERMOST_SOURCE_SCOPE
646640
},
647-
visibility_source_info: SourceInfo {
648-
span,
649-
scope: OUTERMOST_SOURCE_SCOPE
650-
},
641+
visibility_scope: OUTERMOST_SOURCE_SCOPE,
651642
internal: false,
652643
name: None, // FIXME maybe we do want some name here?
653644
is_user_variable: false
@@ -2201,7 +2192,7 @@ BraceStructTypeFoldableImpl! {
22012192
ty,
22022193
name,
22032194
syntactic_source_info,
2204-
visibility_source_info,
2195+
visibility_scope,
22052196
}
22062197
}
22072198

src/librustc/mir/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ macro_rules! make_mir_visitor {
715715
ref $($mutability)* ty,
716716
name: _,
717717
ref $($mutability)* syntactic_source_info,
718-
ref $($mutability)* visibility_source_info,
718+
ref $($mutability)* visibility_scope,
719719
internal: _,
720720
is_user_variable: _,
721721
} = *local_decl;
@@ -725,7 +725,7 @@ macro_rules! make_mir_visitor {
725725
source_info: *syntactic_source_info,
726726
});
727727
self.visit_source_info(syntactic_source_info);
728-
self.visit_source_info(visibility_source_info);
728+
self.visit_source_scope(visibility_scope);
729729
}
730730

731731
fn super_source_scope(&mut self,

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebu
6565
let mut has_variables = BitVector::new(mir.source_scopes.len());
6666
for var in mir.vars_iter() {
6767
let decl = &mir.local_decls[var];
68-
has_variables.insert(decl.visibility_source_info.scope.index());
68+
has_variables.insert(decl.visibility_scope.index());
6969
}
7070

7171
// Instantiate all scopes.

src/librustc_codegen_llvm/mir/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pub fn codegen_mir<'a, 'tcx: 'a>(
265265

266266
if let Some(name) = decl.name {
267267
// User variable
268-
let debug_scope = fx.scopes[decl.visibility_source_info.scope];
268+
let debug_scope = fx.scopes[decl.visibility_scope];
269269
let dbg = debug_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo;
270270

271271
if !memory_locals.contains(local.index()) && !dbg {
@@ -276,7 +276,10 @@ pub fn codegen_mir<'a, 'tcx: 'a>(
276276
debug!("alloc: {:?} ({}) -> place", local, name);
277277
let place = PlaceRef::alloca(&bx, layout, &name.as_str());
278278
if dbg {
279-
let (scope, span) = fx.debug_loc(decl.visibility_source_info);
279+
let (scope, span) = fx.debug_loc(mir::SourceInfo {
280+
span: decl.syntactic_source_info.span,
281+
scope: decl.visibility_scope,
282+
});
280283
declare_local(&bx, &fx.debug_context, name, layout.ty, scope,
281284
VariableAccess::DirectVariable { alloca: place.llval },
282285
VariableKind::LocalVariable, span);

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
398398

399399
let borrow_span = self.mir.source_info(borrow.reserve_location).span;
400400
let proper_span = match *root_place {
401-
Place::Local(local) => self.mir.local_decls[local].visibility_source_info.span,
401+
Place::Local(local) => self.mir.local_decls[local].syntactic_source_info.span,
402402
_ => drop_span,
403403
};
404404

src/librustc_mir/borrow_check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,13 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
306306
None => continue,
307307
}
308308

309-
let source_info = local_decl.visibility_source_info;
310-
let mut_span = tcx.sess.codemap().span_until_non_whitespace(source_info.span);
309+
let span = local_decl.syntactic_source_info.span;
310+
let mut_span = tcx.sess.codemap().span_until_non_whitespace(span);
311311

312312
tcx.struct_span_lint_node(
313313
UNUSED_MUT,
314314
vsi[local_decl.syntactic_source_info.scope].lint_root,
315-
source_info.span,
315+
span,
316316
"variable does not need to be mutable"
317317
)
318318
.span_suggestion_short(mut_span, "remove this `mut`", "".to_owned())

src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
6767
}
6868
None => {
6969
err.span_label(
70-
mir.local_decls[local].visibility_source_info.span,
70+
mir.local_decls[local].syntactic_source_info.span,
7171
"borrow may end up in a temporary, created here",
7272
);
7373

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12011201
LocalKind::Var | LocalKind::Temp => {}
12021202
}
12031203

1204-
let span = local_decl.visibility_source_info.span;
1204+
let span = local_decl.syntactic_source_info.span;
12051205
let ty = local_decl.ty;
12061206

12071207
// Erase the regions from `ty` to get a global type. The

src/librustc_mir/build/expr/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
247247
ty: ptr_ty,
248248
name: None,
249249
syntactic_source_info: source_info,
250-
visibility_source_info: source_info,
250+
visibility_scope: source_info.scope,
251251
internal: true,
252252
is_user_variable: false
253253
});

0 commit comments

Comments
 (0)