Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ba989b2

Browse files
committedFeb 29, 2020
Add some more comments
1 parent 9a926f9 commit ba989b2

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed
 

‎src/librustc_mir_build/build/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir as hir;
88
use rustc_span::Span;
99

1010
impl<'a, 'tcx> Builder<'a, 'tcx> {
11-
pub fn ast_block(
11+
crate fn ast_block(
1212
&mut self,
1313
destination: &Place<'tcx>,
1414
scope: Option<region::Scope>,

‎src/librustc_mir_build/build/into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(in crate::build) trait EvalInto<'tcx> {
2020
}
2121

2222
impl<'a, 'tcx> Builder<'a, 'tcx> {
23-
pub fn into<E>(
23+
crate fn into<E>(
2424
&mut self,
2525
destination: &Place<'tcx>,
2626
scope: Option<region::Scope>,

‎src/librustc_mir_build/build/matches/test.rs

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

‎src/librustc_mir_build/build/scope.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ trait DropTreeBuilder<'tcx> {
235235

236236
impl DropTree {
237237
fn new() -> Self {
238+
// The root node of the tree doesn't represent a drop, but instead
239+
// represents the block in the tree that should be jumped to once all
240+
// of the required drops have been performed.
238241
let fake_source_info = SourceInfo { span: DUMMY_SP, scope: OUTERMOST_SOURCE_SCOPE };
239242
let fake_data =
240243
DropData { source_info: fake_source_info, local: Local::MAX, kind: DropKind::Storage };
@@ -256,12 +259,17 @@ impl DropTree {
256259
self.entry_points.push((to, from));
257260
}
258261

262+
/// Builds the MIR for a given drop tree.
263+
///
264+
/// `blocks` should have the same length as `self.drops`, and may have its
265+
/// first value set to some already existing block.
259266
fn build_mir<'tcx, T: DropTreeBuilder<'tcx>>(
260267
&mut self,
261268
cfg: &mut CFG<'tcx>,
262269
blocks: &mut IndexVec<DropIdx, Option<BasicBlock>>,
263270
) {
264271
debug!("DropTree::lower_to_mir(drops = {:#?})", self);
272+
debug_assert_eq!(blocks.len(), self.drops.len());
265273

266274
self.assign_blocks::<T>(cfg, blocks);
267275
self.link_blocks(cfg, blocks)
@@ -1105,7 +1113,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11051113
return self.cfg.start_new_block().unit();
11061114
}
11071115
let mut first_arm = true;
1108-
let cached_unwind_block = self.diverge_cleanup();
11091116
let arm_end_blocks: Vec<_> = arm_candidates
11101117
.into_iter()
11111118
.map(|(arm, candidate)| {
@@ -1115,8 +1122,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11151122
destination_scope.map(|scope| {
11161123
self.unschedule_drop(scope, destination.as_local().unwrap());
11171124
});
1118-
let top_scope = &mut self.scopes.scopes.last_mut().unwrap();
1119-
top_scope.cached_unwind_block = Some(cached_unwind_block);
11201125
}
11211126

11221127
let arm_source_info = self.source_info(arm.span);
@@ -1394,10 +1399,16 @@ impl<'tcx> DropTreeBuilder<'tcx> for GeneratorDrop {
13941399
cfg.start_new_block()
13951400
}
13961401
fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) {
1397-
let kind = &mut cfg.block_data_mut(from).terminator_mut().kind;
1398-
if let TerminatorKind::Yield { drop, .. } = kind {
1402+
let term = cfg.block_data_mut(from).terminator_mut();
1403+
if let TerminatorKind::Yield { ref mut drop, .. } = term.kind {
13991404
*drop = Some(to);
1400-
};
1405+
} else {
1406+
span_bug!(
1407+
term.source_info.span,
1408+
"cannot enter generator drop tree from {:?}",
1409+
term.kind
1410+
)
1411+
}
14011412
}
14021413
}
14031414

@@ -1408,8 +1419,8 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
14081419
cfg.start_new_cleanup_block()
14091420
}
14101421
fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) {
1411-
let term = &mut cfg.block_data_mut(from).terminator_mut().kind;
1412-
match term {
1422+
let term = &mut cfg.block_data_mut(from).terminator_mut();
1423+
match &mut term.kind {
14131424
TerminatorKind::Drop { unwind, .. }
14141425
| TerminatorKind::DropAndReplace { unwind, .. }
14151426
| TerminatorKind::FalseUnwind { unwind, .. }
@@ -1425,7 +1436,9 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
14251436
| TerminatorKind::Unreachable
14261437
| TerminatorKind::Yield { .. }
14271438
| TerminatorKind::GeneratorDrop
1428-
| TerminatorKind::FalseEdges { .. } => bug!("cannot unwind from {:?}", term),
1439+
| TerminatorKind::FalseEdges { .. } => {
1440+
span_bug!(term.source_info.span, "cannot unwind from {:?}", term.kind)
1441+
}
14291442
}
14301443
}
14311444
}

0 commit comments

Comments
 (0)
Please sign in to comment.