Skip to content

Commit 1e71862

Browse files
matthewjasperAaron1011
authored andcommitted
Add some more comments
1 parent f810e60 commit 1e71862

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

compiler/rustc_mir_build/src/build/matches/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
434434
literal: method,
435435
}),
436436
args: vec![val, expect],
437-
destination: Some((eq_result.clone(), eq_block)),
437+
destination: Some((eq_result, eq_block)),
438438
cleanup: None,
439439
from_hir_call: false,
440440
fn_span: source_info.span,

compiler/rustc_mir_build/src/build/scope.rs

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

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

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

@@ -1359,8 +1372,8 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
13591372
cfg.start_new_cleanup_block()
13601373
}
13611374
fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) {
1362-
let term = &mut cfg.block_data_mut(from).terminator_mut().kind;
1363-
match term {
1375+
let term = &mut cfg.block_data_mut(from).terminator_mut();
1376+
match &mut term.kind {
13641377
TerminatorKind::Drop { unwind, .. }
13651378
| TerminatorKind::DropAndReplace { unwind, .. }
13661379
| TerminatorKind::FalseUnwind { unwind, .. }
@@ -1376,7 +1389,9 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
13761389
| TerminatorKind::Unreachable
13771390
| TerminatorKind::Yield { .. }
13781391
| TerminatorKind::GeneratorDrop
1379-
| TerminatorKind::FalseEdges { .. } => bug!("cannot unwind from {:?}", term),
1392+
| TerminatorKind::FalseEdges { .. } => {
1393+
span_bug!(term.source_info.span, "cannot unwind from {:?}", term.kind)
1394+
}
13801395
}
13811396
}
13821397
}

0 commit comments

Comments
 (0)