Skip to content

Commit b10c157

Browse files
committed
rustc: turn mir::LocalDecl's syntactic_scope into a SourceInfo.
1 parent ca1ac6b commit b10c157

File tree

11 files changed

+53
-33
lines changed

11 files changed

+53
-33
lines changed

src/librustc/ich/impls_mir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> {
2626
ty,
2727
name,
2828
source_info,
29+
syntactic_source_info,
2930
internal,
30-
syntactic_scope,
3131
is_user_variable
3232
});
3333
impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, by_ref, mutability });

src/librustc/mir/mod.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ pub struct LocalDecl<'tcx> {
506506
pub name: Option<Name>,
507507

508508
/// Source info of the local. The `SourceScope` is the *visibility* one,
509-
/// not the the *syntactic* one (see `syntactic_scope` for more details).
509+
/// not the the *syntactic* one (see `syntactic_source_info` for more details).
510510
pub source_info: SourceInfo,
511511

512512
/// The *syntactic* (i.e. not visibility) source scope the local is defined
@@ -560,9 +560,9 @@ pub struct LocalDecl<'tcx> {
560560
/// `drop(x)`, we want it to refer to `x: u32`.
561561
///
562562
/// To allow both uses to work, we need to have more than a single scope
563-
/// for a local. We have the `syntactic_scope` represent the
563+
/// for a local. We have the `syntactic_source_info.scope` represent the
564564
/// "syntactic" lint scope (with a variable being under its let
565-
/// block) while the source-info scope represents the "local variable"
565+
/// block) while the `source_info.scope` represents the "local variable"
566566
/// scope (where the "rest" of a block is under all prior let-statements).
567567
///
568568
/// The end result looks like this:
@@ -574,10 +574,10 @@ pub struct LocalDecl<'tcx> {
574574
/// │ │{ #[allow(unused_mut] } // this is actually split into 2 scopes
575575
/// │ │ // in practice because I'm lazy.
576576
/// │ │
577-
/// │ │← x.syntactic_scope
577+
/// │ │← x.syntactic_source_info.scope
578578
/// │ │← `x.parse().unwrap()`
579579
/// │ │
580-
/// │ │ │← y.syntactic_scope
580+
/// │ │ │← y.syntactic_source_info.scope
581581
/// │ │
582582
/// │ │ │{ let y: u32 }
583583
/// │ │ │
@@ -588,7 +588,7 @@ pub struct LocalDecl<'tcx> {
588588
/// │ │← x.source_info.scope
589589
/// │ │← `drop(x)` // this accesses `x: u32`
590590
/// ```
591-
pub syntactic_scope: SourceScope,
591+
pub syntactic_source_info: SourceInfo,
592592
}
593593

594594
impl<'tcx> LocalDecl<'tcx> {
@@ -603,7 +603,10 @@ impl<'tcx> LocalDecl<'tcx> {
603603
span,
604604
scope: OUTERMOST_SOURCE_SCOPE
605605
},
606-
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
606+
syntactic_source_info: SourceInfo {
607+
span,
608+
scope: OUTERMOST_SOURCE_SCOPE
609+
},
607610
internal: false,
608611
is_user_variable: false
609612
}
@@ -620,7 +623,10 @@ impl<'tcx> LocalDecl<'tcx> {
620623
span,
621624
scope: OUTERMOST_SOURCE_SCOPE
622625
},
623-
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
626+
syntactic_source_info: SourceInfo {
627+
span,
628+
scope: OUTERMOST_SOURCE_SCOPE
629+
},
624630
internal: true,
625631
is_user_variable: false
626632
}
@@ -638,7 +644,10 @@ impl<'tcx> LocalDecl<'tcx> {
638644
span,
639645
scope: OUTERMOST_SOURCE_SCOPE
640646
},
641-
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
647+
syntactic_source_info: SourceInfo {
648+
span,
649+
scope: OUTERMOST_SOURCE_SCOPE
650+
},
642651
internal: false,
643652
name: None, // FIXME maybe we do want some name here?
644653
is_user_variable: false
@@ -2192,7 +2201,7 @@ BraceStructTypeFoldableImpl! {
21922201
ty,
21932202
name,
21942203
source_info,
2195-
syntactic_scope,
2204+
syntactic_source_info,
21962205
}
21972206
}
21982207

src/librustc/mir/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,16 +716,16 @@ macro_rules! make_mir_visitor {
716716
name: _,
717717
ref $($mutability)* source_info,
718718
internal: _,
719-
ref $($mutability)* syntactic_scope,
719+
ref $($mutability)* syntactic_source_info,
720720
is_user_variable: _,
721721
} = *local_decl;
722722

723723
self.visit_ty(ty, TyContext::LocalDecl {
724724
local,
725725
source_info: *source_info,
726726
});
727+
self.visit_source_info(syntactic_source_info);
727728
self.visit_source_info(source_info);
728-
self.visit_source_scope(syntactic_scope);
729729
}
730730

731731
fn super_source_scope(&mut self,

src/librustc_mir/borrow_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
311311

312312
tcx.struct_span_lint_node(
313313
UNUSED_MUT,
314-
vsi[local_decl.syntactic_scope].lint_root,
314+
vsi[local_decl.syntactic_source_info.scope].lint_root,
315315
source_info.span,
316316
"variable does not need to be mutable"
317317
)

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
source_info,
250-
syntactic_scope: source_info.scope,
250+
syntactic_source_info: source_info,
251251
internal: true,
252252
is_user_variable: false
253253
});

src/librustc_mir/build/matches/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
314314
None));
315315
// If we have lints, create a new source scope
316316
// that marks the lints for the locals. See the comment
317-
// on the `syntactic_scope` field for why this is needed.
317+
// on the `syntactic_source_info` field for why this is needed.
318318
if lint_level.is_explicit() {
319319
syntactic_scope =
320320
this.new_source_scope(scope_span, lint_level, None);
@@ -324,7 +324,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
324324
span,
325325
scope: var_scope.unwrap()
326326
};
327-
this.declare_binding(source_info, syntactic_scope, mutability, name, var,
327+
let syntactic_source_info = SourceInfo {
328+
span,
329+
scope: syntactic_scope,
330+
};
331+
this.declare_binding(source_info, syntactic_source_info, mutability, name, var,
328332
ty, has_guard);
329333
});
330334
var_scope
@@ -1114,24 +1118,24 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
11141118
/// in the arm body, which will have type `T`.
11151119
fn declare_binding(&mut self,
11161120
source_info: SourceInfo,
1117-
syntactic_scope: SourceScope,
1121+
syntactic_source_info: SourceInfo,
11181122
mutability: Mutability,
11191123
name: Name,
11201124
var_id: NodeId,
11211125
var_ty: Ty<'tcx>,
11221126
has_guard: ArmHasGuard)
11231127
{
11241128
debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, source_info={:?}, \
1125-
syntactic_scope={:?})",
1126-
var_id, name, var_ty, source_info, syntactic_scope);
1129+
syntactic_source_info={:?})",
1130+
var_id, name, var_ty, source_info, syntactic_source_info);
11271131

11281132
let tcx = self.hir.tcx();
11291133
let local = LocalDecl::<'tcx> {
11301134
mutability,
11311135
ty: var_ty.clone(),
11321136
name: Some(name),
11331137
source_info,
1134-
syntactic_scope,
1138+
syntactic_source_info,
11351139
internal: false,
11361140
is_user_variable: true,
11371141
};
@@ -1143,7 +1147,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
11431147
ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty),
11441148
name: Some(name),
11451149
source_info,
1146-
syntactic_scope,
1150+
syntactic_source_info,
11471151
internal: false,
11481152
is_user_variable: true,
11491153
});

src/librustc_mir/build/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,14 +657,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
657657
}
658658
}
659659

660+
let source_info = SourceInfo {
661+
scope: OUTERMOST_SOURCE_SCOPE,
662+
span: pattern.map_or(self.fn_span, |pat| pat.span)
663+
};
660664
self.local_decls.push(LocalDecl {
661665
mutability: Mutability::Mut,
662666
ty,
663-
source_info: SourceInfo {
664-
scope: OUTERMOST_SOURCE_SCOPE,
665-
span: pattern.map_or(self.fn_span, |pat| pat.span)
666-
},
667-
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
667+
source_info,
668+
syntactic_source_info: source_info,
668669
name,
669670
internal: false,
670671
is_user_variable: false,

src/librustc_mir/shim.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ enum CallKind {
138138
}
139139

140140
fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl {
141+
let source_info = SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span };
141142
LocalDecl {
142143
mutability, ty, name: None,
143-
source_info: SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span },
144-
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
144+
source_info,
145+
syntactic_source_info: source_info,
145146
internal: false,
146147
is_user_variable: false
147148
}

src/librustc_mir/transform/generator.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,13 @@ fn make_generator_state_argument_indirect<'a, 'tcx>(
295295

296296
fn replace_result_variable<'tcx>(ret_ty: Ty<'tcx>,
297297
mir: &mut Mir<'tcx>) -> Local {
298+
let source_info = source_info(mir);
298299
let new_ret = LocalDecl {
299300
mutability: Mutability::Mut,
300301
ty: ret_ty,
301302
name: None,
302-
source_info: source_info(mir),
303-
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
303+
source_info,
304+
syntactic_source_info: source_info,
304305
internal: false,
305306
is_user_variable: false,
306307
};
@@ -641,7 +642,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
641642
ty: tcx.mk_nil(),
642643
name: None,
643644
source_info,
644-
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
645+
syntactic_source_info: source_info,
645646
internal: false,
646647
is_user_variable: false,
647648
};
@@ -657,7 +658,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
657658
}),
658659
name: None,
659660
source_info,
660-
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
661+
syntactic_source_info: source_info,
661662
internal: false,
662663
is_user_variable: false,
663664
};

src/librustc_mir/transform/inline.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
400400

401401
local.source_info.scope = scope_map[local.source_info.scope];
402402
local.source_info.span = callsite.location.span;
403+
local.syntactic_source_info.scope =
404+
scope_map[local.syntactic_source_info.scope];
405+
local.syntactic_source_info.span = callsite.location.span;
403406

404407
let idx = caller_mir.local_decls.push(local);
405408
local_map.push(idx);

src/librustc_mir/transform/promote_consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +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.source_info = statement.source_info;
338+
promoted_ref.syntactic_source_info = statement.source_info;
338339
let promoted_ref = local_decls.push(promoted_ref);
339340
assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref);
340341
self.extra_statements.push((loc, Statement {

0 commit comments

Comments
 (0)