Skip to content

Commit 1a19c1d

Browse files
committed
Add some more comments
1 parent 54aa418 commit 1a19c1d

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/librustc_mir_build/build/matches/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
439439
literal: method,
440440
}),
441441
args: vec![val, expect],
442-
destination: Some((eq_result.clone(), eq_block)),
442+
destination: Some((eq_result, eq_block)),
443443
cleanup: None,
444444
from_hir_call: false,
445445
},

src/librustc_mir_build/build/scope.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ trait DropTreeBuilder<'tcx> {
237237

238238
impl DropTree {
239239
fn new() -> Self {
240+
// The root node of the tree doesn't represent a drop, but instead
241+
// represents the block in the tree that should be jumped to once all
242+
// of the required drops have been performed.
240243
let fake_source_info = SourceInfo::outermost(DUMMY_SP);
241244
let fake_data =
242245
DropData { source_info: fake_source_info, local: Local::MAX, kind: DropKind::Storage };
@@ -258,6 +261,10 @@ impl DropTree {
258261
self.entry_points.push((to, from));
259262
}
260263

264+
/// Builds the MIR for a given drop tree.
265+
///
266+
/// `blocks` should have the same length as `self.drops`, and may have its
267+
/// first value set to some already existing block.
261268
fn build_mir<'tcx, T: DropTreeBuilder<'tcx>>(
262269
&mut self,
263270
cfg: &mut CFG<'tcx>,
@@ -1344,10 +1351,16 @@ impl<'tcx> DropTreeBuilder<'tcx> for GeneratorDrop {
13441351
cfg.start_new_block()
13451352
}
13461353
fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) {
1347-
let kind = &mut cfg.block_data_mut(from).terminator_mut().kind;
1348-
if let TerminatorKind::Yield { drop, .. } = kind {
1354+
let term = cfg.block_data_mut(from).terminator_mut();
1355+
if let TerminatorKind::Yield { ref mut drop, .. } = term.kind {
13491356
*drop = Some(to);
1350-
};
1357+
} else {
1358+
span_bug!(
1359+
term.source_info.span,
1360+
"cannot enter generator drop tree from {:?}",
1361+
term.kind
1362+
)
1363+
}
13511364
}
13521365
}
13531366

@@ -1358,8 +1371,8 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
13581371
cfg.start_new_cleanup_block()
13591372
}
13601373
fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) {
1361-
let term = &mut cfg.block_data_mut(from).terminator_mut().kind;
1362-
match term {
1374+
let term = &mut cfg.block_data_mut(from).terminator_mut();
1375+
match &mut term.kind {
13631376
TerminatorKind::Drop { unwind, .. }
13641377
| TerminatorKind::DropAndReplace { unwind, .. }
13651378
| TerminatorKind::FalseUnwind { unwind, .. }
@@ -1375,7 +1388,9 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
13751388
| TerminatorKind::Unreachable
13761389
| TerminatorKind::Yield { .. }
13771390
| TerminatorKind::GeneratorDrop
1378-
| TerminatorKind::FalseEdges { .. } => bug!("cannot unwind from {:?}", term),
1391+
| TerminatorKind::FalseEdges { .. } => {
1392+
span_bug!(term.source_info.span, "cannot unwind from {:?}", term.kind)
1393+
}
13791394
}
13801395
}
13811396
}

0 commit comments

Comments
 (0)