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

+1-1
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

+10-19
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

+2-2
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

+1-1
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

+5-2
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

+1-1
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

+3-3
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

+1-1
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

+1-1
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

+1-1
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
});

src/librustc_mir/build/matches/mod.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
324324
span,
325325
scope: syntactic_scope,
326326
};
327-
let visibility_source_info = SourceInfo {
328-
span,
329-
scope: visibility_scope.unwrap()
330-
};
331-
this.declare_binding(syntactic_source_info, visibility_source_info, mutability, name, var,
327+
let visibility_scope = visibility_scope.unwrap();
328+
this.declare_binding(syntactic_source_info, visibility_scope, mutability, name, var,
332329
ty, has_guard);
333330
});
334331
visibility_scope
@@ -1118,24 +1115,24 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
11181115
/// in the arm body, which will have type `T`.
11191116
fn declare_binding(&mut self,
11201117
syntactic_source_info: SourceInfo,
1121-
visibility_source_info: SourceInfo,
1118+
visibility_scope: SourceScope,
11221119
mutability: Mutability,
11231120
name: Name,
11241121
var_id: NodeId,
11251122
var_ty: Ty<'tcx>,
11261123
has_guard: ArmHasGuard)
11271124
{
1128-
debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, visibility_source_info={:?}, \
1125+
debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, visibility_scope={:?}, \
11291126
syntactic_source_info={:?})",
1130-
var_id, name, var_ty, visibility_source_info, syntactic_source_info);
1127+
var_id, name, var_ty, visibility_scope, syntactic_source_info);
11311128

11321129
let tcx = self.hir.tcx();
11331130
let local = LocalDecl::<'tcx> {
11341131
mutability,
11351132
ty: var_ty.clone(),
11361133
name: Some(name),
11371134
syntactic_source_info,
1138-
visibility_source_info,
1135+
visibility_scope,
11391136
internal: false,
11401137
is_user_variable: true,
11411138
};
@@ -1147,7 +1144,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
11471144
ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty),
11481145
name: Some(name),
11491146
syntactic_source_info,
1150-
visibility_source_info,
1147+
visibility_scope,
11511148
internal: false,
11521149
is_user_variable: true,
11531150
});

src/librustc_mir/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
665665
mutability: Mutability::Mut,
666666
ty,
667667
syntactic_source_info: source_info,
668-
visibility_source_info: source_info,
668+
visibility_scope: source_info.scope,
669669
name,
670670
internal: false,
671671
is_user_variable: false,

src/librustc_mir/dataflow/move_paths/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
233233
fn gather_args(&mut self) {
234234
for arg in self.mir.args_iter() {
235235
let path = self.data.rev_lookup.locals[arg];
236-
let span = self.mir.local_decls[arg].visibility_source_info.span;
236+
let span = self.mir.local_decls[arg].syntactic_source_info.span;
237237

238238
let init = self.data.inits.push(Init {
239239
path, span, kind: InitKind::Deep

src/librustc_mir/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl {
142142
LocalDecl {
143143
mutability, ty, name: None,
144144
syntactic_source_info: source_info,
145-
visibility_source_info: source_info,
145+
visibility_scope: source_info.scope,
146146
internal: false,
147147
is_user_variable: false
148148
}

src/librustc_mir/transform/generator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn replace_result_variable<'tcx>(ret_ty: Ty<'tcx>,
301301
ty: ret_ty,
302302
name: None,
303303
syntactic_source_info: source_info,
304-
visibility_source_info: source_info,
304+
visibility_scope: source_info.scope,
305305
internal: false,
306306
is_user_variable: false,
307307
};
@@ -642,7 +642,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
642642
ty: tcx.mk_nil(),
643643
name: None,
644644
syntactic_source_info: source_info,
645-
visibility_source_info: source_info,
645+
visibility_scope: source_info.scope,
646646
internal: false,
647647
is_user_variable: false,
648648
};
@@ -658,7 +658,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
658658
}),
659659
name: None,
660660
syntactic_source_info: source_info,
661-
visibility_source_info: source_info,
661+
visibility_scope: source_info.scope,
662662
internal: false,
663663
is_user_variable: false,
664664
};

src/librustc_mir/transform/inline.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
401401
local.syntactic_source_info.scope =
402402
scope_map[local.syntactic_source_info.scope];
403403
local.syntactic_source_info.span = callsite.location.span;
404-
local.visibility_source_info.scope =
405-
scope_map[local.visibility_source_info.scope];
406-
local.visibility_source_info.span = callsite.location.span;
404+
local.visibility_scope = scope_map[local.visibility_scope];
407405

408406
let idx = caller_mir.local_decls.push(local);
409407
local_map.push(idx);

src/librustc_mir/transform/promote_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
210210
let no_stmts = self.source[loc.block].statements.len();
211211
let new_temp = self.promoted.local_decls.push(
212212
LocalDecl::new_temp(self.source.local_decls[temp].ty,
213-
self.source.local_decls[temp].visibility_source_info.span));
213+
self.source.local_decls[temp].syntactic_source_info.span));
214214

215215
debug!("promote({:?} @ {:?}/{:?}, {:?})",
216216
temp, loc, no_stmts, self.keep_original);
@@ -335,7 +335,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
335335
// otherwise we would use the `promoted` directly.
336336
let mut promoted_ref = LocalDecl::new_temp(ref_ty, span);
337337
promoted_ref.syntactic_source_info = statement.source_info;
338-
promoted_ref.visibility_source_info = statement.source_info;
338+
promoted_ref.visibility_scope = statement.source_info.scope;
339339
let promoted_ref = local_decls.push(promoted_ref);
340340
assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref);
341341
self.extra_statements.push((loc, Statement {

src/librustc_mir/transform/qualify_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ This does not pose a problem by itself because they can't be accessed directly."
10461046
// conservatively, that drop elaboration will do.
10471047
let needs_drop = if let Place::Local(local) = *place {
10481048
if self.local_qualif[local].map_or(true, |q| q.intersects(Qualif::NEEDS_DROP)) {
1049-
Some(self.mir.local_decls[local].visibility_source_info.span)
1049+
Some(self.mir.local_decls[local].syntactic_source_info.span)
10501050
} else {
10511051
None
10521052
}
@@ -1102,7 +1102,7 @@ This does not pose a problem by itself because they can't be accessed directly."
11021102
let mut err = feature_err(
11031103
&self.tcx.sess.parse_sess,
11041104
"const_let",
1105-
decl.visibility_source_info.span,
1105+
decl.syntactic_source_info.span,
11061106
GateIssue::Language,
11071107
"arguments of constant functions can only be immutable by-value bindings"
11081108
);

0 commit comments

Comments
 (0)