Skip to content

Commit dca8121

Browse files
committed
Temp: Cleanup 2 (SourceInfo)
1 parent 10817cc commit dca8121

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

src/librustc_mir_build/build/scope.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ struct Scope {
134134
struct DropData {
135135
/// The `Span` where drop obligation was incurred (typically where place was
136136
/// declared)
137-
span: Span,
137+
source_info: SourceInfo,
138138

139139
/// local to drop
140140
local: Local,
@@ -179,8 +179,7 @@ const CONTINUE_NODE: DropIdx = DropIdx::from_u32_const(1);
179179
// TODO say some more.
180180
#[derive(Debug)]
181181
struct DropTree {
182-
/// The next item to drop, if there is one.
183-
// TODO actual comment
182+
/// Drops in the tree.
184183
drops: IndexVec<DropIdx, (DropData, DropIdx)>,
185184
/// Map for finding the inverse of the `next_drop` relation:
186185
///
@@ -193,11 +192,6 @@ struct DropTree {
193192
}
194193

195194
impl Scope {
196-
/// Given a span and this scope's source scope, make a SourceInfo.
197-
fn source_info(&self, span: Span) -> SourceInfo {
198-
SourceInfo { span, scope: self.source_scope }
199-
}
200-
201195
/// Whether there's anything to do for the cleanup path, that is,
202196
/// when unwinding through this scope. This includes destructors,
203197
/// but not StorageDead statements, which don't get emitted at all
@@ -219,7 +213,9 @@ impl Scope {
219213

220214
impl DropTree {
221215
fn new(num_roots: usize) -> Self {
222-
let fake_data = DropData { span: DUMMY_SP, local: Local::MAX, kind: DropKind::Storage };
216+
let fake_source_info = SourceInfo { span: DUMMY_SP, scope: OUTERMOST_SOURCE_SCOPE };
217+
let fake_data =
218+
DropData { source_info: fake_source_info, local: Local::MAX, kind: DropKind::Storage };
223219
let drop_idx = DropIdx::MAX;
224220
let drops = IndexVec::from_elem_n((fake_data, drop_idx), num_roots);
225221
Self {
@@ -286,10 +282,6 @@ impl<'tcx> Scopes<'tcx> {
286282
fn topmost(&self) -> region::Scope {
287283
self.scopes.last().expect("topmost_scope: no scopes present").region_scope
288284
}
289-
290-
// fn source_info(&self, index: usize, span: Span) -> SourceInfo {
291-
// self.scopes[self.len() - index].source_info(span)
292-
// }
293285
}
294286

295287
impl<'a, 'tcx> Builder<'a, 'tcx> {
@@ -497,7 +489,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
497489
self.cfg.start_new_block().unit()
498490
}
499491

500-
// TODO: use in pop_top_scope.
501492
crate fn exit_top_scope(
502493
&mut self,
503494
mut block: BasicBlock,
@@ -685,7 +676,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
685676
// Attribute scope exit drops to scope's closing brace.
686677
let scope_end = self.hir.tcx().sess.source_map().end_point(region_scope_span);
687678

688-
scope.drops.push(DropData { span: scope_end, local, kind: drop_kind });
679+
scope.drops.push(DropData {
680+
source_info: SourceInfo { span: scope_end, scope: scope.source_scope },
681+
local,
682+
kind: drop_kind,
683+
});
689684
}
690685

691686
/// Indicates that the "local operand" stored in `local` is
@@ -790,7 +785,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
790785
bug!("Drop scheduled on top of condition variable")
791786
}
792787
DropKind::Storage => {
793-
let source_info = top_scope.source_info(top_drop_data.span);
788+
let source_info = top_drop_data.source_info;
794789
let local = top_drop_data.local;
795790
assert_eq!(local, cond_temp, "Drop scheduled on top of condition");
796791
self.cfg.push(
@@ -928,7 +923,7 @@ fn build_scope_drops<'tcx>(
928923
// `diverge_cleanup_gen`.
929924

930925
for drop_data in scope.drops.iter().rev() {
931-
let source_info = scope.source_info(drop_data.span);
926+
let source_info = drop_data.source_info;
932927
let local = drop_data.local;
933928

934929
match drop_data.kind {
@@ -1097,10 +1092,6 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
10971092
}
10981093
}
10991094

1100-
fn source_info(span: Span) -> SourceInfo {
1101-
SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }
1102-
}
1103-
11041095
fn build_drop_tree<'tcx, T: DropTreeBuilder<'tcx>>(
11051096
cfg: &mut CFG<'tcx>,
11061097
drops: &mut DropTree,
@@ -1172,21 +1163,21 @@ fn build_drop_tree<'tcx, T: DropTreeBuilder<'tcx>>(
11721163
unwind: None,
11731164
location: drop_data.0.local.into(),
11741165
};
1175-
cfg.terminate(blocks[drop_idx].unwrap(), source_info(drop_data.0.span), terminator);
1166+
cfg.terminate(blocks[drop_idx].unwrap(), drop_data.0.source_info, terminator);
11761167
}
11771168
// Root nodes don't correspond to a drop.
11781169
DropKind::Storage if drop_idx < drops.num_roots => {}
11791170
DropKind::Storage => {
11801171
let block = blocks[drop_idx].unwrap();
11811172
let stmt = Statement {
1182-
source_info: source_info(drop_data.0.span),
1173+
source_info: drop_data.0.source_info,
11831174
kind: StatementKind::StorageDead(drop_data.0.local),
11841175
};
11851176
cfg.push(block, stmt);
11861177
let target = blocks[drop_data.1].unwrap();
11871178
if target != block {
11881179
let terminator = TerminatorKind::Goto { target };
1189-
cfg.terminate(block, source_info(drop_data.0.span), terminator);
1180+
cfg.terminate(block, drop_data.0.source_info, terminator);
11901181
}
11911182
}
11921183
}

0 commit comments

Comments
 (0)