Skip to content

Commit 9912925

Browse files
committed
Auto merge of #72074 - RalfJung:rollup-1ns58no, r=RalfJung
Rollup of 4 pull requests Successful merges: - #71840 (Rework MIR drop tree lowering) - #71882 (Update the `cc` crate) - #71945 (Sort "implementations on foreign types" section in the sidebar) - #72043 (Add missing backtick in E0569 explanation) Failed merges: r? @ghost
2 parents 8d16eeb + f2b655f commit 9912925

File tree

59 files changed

+1628
-1760
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1628
-1760
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@ version = "0.1.0"
412412

413413
[[package]]
414414
name = "cc"
415-
version = "1.0.50"
415+
version = "1.0.52"
416416
source = "registry+https://github.com/rust-lang/crates.io-index"
417-
checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
417+
checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d"
418418
dependencies = [
419419
"jobserver",
420420
]

src/librustc_error_codes/error_codes/E0569.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
If an impl has a generic parameter with the `#[may_dangle]` attribute, then
2-
that impl must be declared as an `unsafe impl.
2+
that impl must be declared as an `unsafe impl`.
33

44
Erroneous code example:
55

src/librustc_mir/dataflow/move_paths/builder.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,18 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
361361
fn gather_terminator(&mut self, term: &Terminator<'tcx>) {
362362
match term.kind {
363363
TerminatorKind::Goto { target: _ }
364+
| TerminatorKind::FalseEdges { .. }
365+
| TerminatorKind::FalseUnwind { .. }
366+
// In some sense returning moves the return place into the current
367+
// call's destination, however, since there are no statements after
368+
// this that could possibly access the return place, this doesn't
369+
// need recording.
370+
| TerminatorKind::Return
364371
| TerminatorKind::Resume
365372
| TerminatorKind::Abort
366373
| TerminatorKind::GeneratorDrop
367-
| TerminatorKind::FalseEdges { .. }
368-
| TerminatorKind::FalseUnwind { .. }
369374
| TerminatorKind::Unreachable => {}
370375

371-
TerminatorKind::Return => {
372-
self.gather_move(Place::return_place());
373-
}
374-
375376
TerminatorKind::Assert { ref cond, .. } => {
376377
self.gather_operand(cond);
377378
}

src/librustc_mir/util/elaborate_drops.rs

+11-35
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ where
163163
.patch_terminator(bb, TerminatorKind::Goto { target: self.succ });
164164
}
165165
DropStyle::Static => {
166-
let loc = self.terminator_loc(bb);
167-
self.elaborator.clear_drop_flag(loc, self.path, DropFlagMode::Deep);
168166
self.elaborator.patch().patch_terminator(
169167
bb,
170168
TerminatorKind::Drop {
@@ -175,9 +173,7 @@ where
175173
);
176174
}
177175
DropStyle::Conditional => {
178-
let unwind = self.unwind; // FIXME(#43234)
179-
let succ = self.succ;
180-
let drop_bb = self.complete_drop(Some(DropFlagMode::Deep), succ, unwind);
176+
let drop_bb = self.complete_drop(self.succ, self.unwind);
181177
self.elaborator
182178
.patch()
183179
.patch_terminator(bb, TerminatorKind::Goto { target: drop_bb });
@@ -249,7 +245,7 @@ where
249245
// our own drop flag.
250246
path: self.path,
251247
}
252-
.complete_drop(None, succ, unwind)
248+
.complete_drop(succ, unwind)
253249
}
254250
}
255251

@@ -278,13 +274,7 @@ where
278274
// Clear the "master" drop flag at the end. This is needed
279275
// because the "master" drop protects the ADT's discriminant,
280276
// which is invalidated after the ADT is dropped.
281-
let (succ, unwind) = (self.succ, self.unwind); // FIXME(#43234)
282-
(
283-
self.drop_flag_reset_block(DropFlagMode::Shallow, succ, unwind),
284-
unwind.map(|unwind| {
285-
self.drop_flag_reset_block(DropFlagMode::Shallow, unwind, Unwind::InCleanup)
286-
}),
287-
)
277+
(self.drop_flag_reset_block(DropFlagMode::Shallow, self.succ, self.unwind), self.unwind)
288278
}
289279

290280
/// Creates a full drop ladder, consisting of 2 connected half-drop-ladders
@@ -820,11 +810,7 @@ where
820810
self.open_drop_for_adt(def, substs)
821811
}
822812
}
823-
ty::Dynamic(..) => {
824-
let unwind = self.unwind; // FIXME(#43234)
825-
let succ = self.succ;
826-
self.complete_drop(Some(DropFlagMode::Deep), succ, unwind)
827-
}
813+
ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind),
828814
ty::Array(ety, size) => {
829815
let size = size.try_eval_usize(self.tcx(), self.elaborator.param_env());
830816
self.open_drop_for_array(ety, size)
@@ -835,20 +821,10 @@ where
835821
}
836822
}
837823

838-
fn complete_drop(
839-
&mut self,
840-
drop_mode: Option<DropFlagMode>,
841-
succ: BasicBlock,
842-
unwind: Unwind,
843-
) -> BasicBlock {
844-
debug!("complete_drop({:?},{:?})", self, drop_mode);
824+
fn complete_drop(&mut self, succ: BasicBlock, unwind: Unwind) -> BasicBlock {
825+
debug!("complete_drop(succ={:?}, unwind={:?})", succ, unwind);
845826

846827
let drop_block = self.drop_block(succ, unwind);
847-
let drop_block = if let Some(mode) = drop_mode {
848-
self.drop_flag_reset_block(mode, drop_block, unwind)
849-
} else {
850-
drop_block
851-
};
852828

853829
self.drop_flag_test_block(drop_block, succ, unwind)
854830
}
@@ -861,6 +837,11 @@ where
861837
) -> BasicBlock {
862838
debug!("drop_flag_reset_block({:?},{:?})", self, mode);
863839

840+
if unwind.is_cleanup() {
841+
// The drop flag isn't read again on the unwind path, so don't
842+
// bother setting it.
843+
return succ;
844+
}
864845
let block = self.new_block(unwind, TerminatorKind::Goto { target: succ });
865846
let block_start = Location { block, statement_index: 0 };
866847
self.elaborator.clear_drop_flag(block_start, self.path, mode);
@@ -969,11 +950,6 @@ where
969950
self.elaborator.patch().new_temp(ty, self.source_info.span)
970951
}
971952

972-
fn terminator_loc(&mut self, bb: BasicBlock) -> Location {
973-
let body = self.elaborator.body();
974-
self.elaborator.patch().terminator_loc(body, bb)
975-
}
976-
977953
fn constant_usize(&self, val: u16) -> Operand<'tcx> {
978954
Operand::Constant(box Constant {
979955
span: self.source_info.span,

src/librustc_mir/util/graphviz.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,17 @@ where
9797
write!(w, r#"<table border="0" cellborder="1" cellspacing="0">"#)?;
9898

9999
// Basic block number at the top.
100+
let (blk, color) = if data.is_cleanup {
101+
(format!("{} (cleanup)", block.index()), "lightblue")
102+
} else {
103+
(format!("{}", block.index()), "gray")
104+
};
100105
write!(
101106
w,
102-
r#"<tr><td {attrs} colspan="{colspan}">{blk}</td></tr>"#,
103-
attrs = r#"bgcolor="gray" align="center""#,
107+
r#"<tr><td bgcolor="{color}" align="center" colspan="{colspan}">{blk}</td></tr>"#,
104108
colspan = num_cols,
105-
blk = block.index()
109+
blk = blk,
110+
color = color
106111
)?;
107112

108113
init(w)?;

src/librustc_mir_build/build/block.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2626
self.in_opt_scope(opt_destruction_scope.map(|de| (de, source_info)), move |this| {
2727
this.in_scope((region_scope, source_info), LintLevel::Inherited, move |this| {
2828
if targeted_by_break {
29-
// This is a `break`-able block
30-
let exit_block = this.cfg.start_new_block();
31-
let block_exit =
32-
this.in_breakable_scope(None, exit_block, destination, |this| {
33-
this.ast_block_stmts(destination, block, span, stmts, expr, safety_mode)
34-
});
35-
this.cfg.goto(unpack!(block_exit), source_info, exit_block);
36-
exit_block.unit()
29+
this.in_breakable_scope(None, destination, span, |this| {
30+
Some(this.ast_block_stmts(
31+
destination,
32+
block,
33+
span,
34+
stmts,
35+
expr,
36+
safety_mode,
37+
))
38+
})
3739
} else {
3840
this.ast_block_stmts(destination, block, span, stmts, expr, safety_mode)
3941
}

src/librustc_mir_build/build/expr/into.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -134,32 +134,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
134134
// body, even when the exact code in the body cannot unwind
135135

136136
let loop_block = this.cfg.start_new_block();
137-
let exit_block = this.cfg.start_new_block();
138137

139138
// Start the loop.
140139
this.cfg.goto(block, source_info, loop_block);
141140

142-
this.in_breakable_scope(Some(loop_block), exit_block, destination, move |this| {
141+
this.in_breakable_scope(Some(loop_block), destination, expr_span, move |this| {
143142
// conduct the test, if necessary
144143
let body_block = this.cfg.start_new_block();
145-
let diverge_cleanup = this.diverge_cleanup();
146144
this.cfg.terminate(
147145
loop_block,
148146
source_info,
149-
TerminatorKind::FalseUnwind {
150-
real_target: body_block,
151-
unwind: Some(diverge_cleanup),
152-
},
147+
TerminatorKind::FalseUnwind { real_target: body_block, unwind: None },
153148
);
149+
this.diverge_from(loop_block);
154150

155151
// The “return” value of the loop body must always be an unit. We therefore
156152
// introduce a unit temporary as the destination for the loop body.
157153
let tmp = this.get_unit_temp();
158154
// Execute the body, branching back to the test.
159155
let body_block_end = unpack!(this.into(tmp, body_block, body));
160156
this.cfg.goto(body_block_end, source_info, loop_block);
161-
});
162-
exit_block.unit()
157+
158+
// Loops are only exited by `break` expressions.
159+
None
160+
})
163161
}
164162
ExprKind::Call { ty, fun, args, from_hir_call } => {
165163
let intrinsic = match ty.kind {
@@ -201,7 +199,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
201199
.collect();
202200

203201
let success = this.cfg.start_new_block();
204-
let cleanup = this.diverge_cleanup();
205202

206203
this.record_operands_moved(&args);
207204

@@ -211,7 +208,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
211208
TerminatorKind::Call {
212209
func: fun,
213210
args,
214-
cleanup: Some(cleanup),
211+
cleanup: None,
215212
// FIXME(varkor): replace this with an uninhabitedness-based check.
216213
// This requires getting access to the current module to call
217214
// `tcx.is_ty_uninhabited_from`, which is currently tricky to do.
@@ -223,6 +220,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
223220
from_hir_call,
224221
},
225222
);
223+
this.diverge_from(block);
226224
success.unit()
227225
}
228226
}
@@ -358,12 +356,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
358356
let scope = this.local_scope();
359357
let value = unpack!(block = this.as_operand(block, scope, value));
360358
let resume = this.cfg.start_new_block();
361-
let cleanup = this.generator_drop_cleanup();
362359
this.cfg.terminate(
363360
block,
364361
source_info,
365-
TerminatorKind::Yield { value, resume, resume_arg: destination, drop: cleanup },
362+
TerminatorKind::Yield { value, resume, resume_arg: destination, drop: None },
366363
);
364+
this.generator_drop_cleanup(block);
367365
resume.unit()
368366
}
369367

src/librustc_mir_build/build/matches/mod.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
225225
outer_source_info: SourceInfo,
226226
fake_borrow_temps: Vec<(Place<'tcx>, Local)>,
227227
) -> BlockAnd<()> {
228-
let match_scope = self.scopes.topmost();
229-
230228
let arm_end_blocks: Vec<_> = arm_candidates
231229
.into_iter()
232230
.map(|(arm, candidate)| {
@@ -247,7 +245,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
247245
let arm_block = this.bind_pattern(
248246
outer_source_info,
249247
candidate,
250-
arm.guard.as_ref().map(|g| (g, match_scope)),
248+
arm.guard.as_ref(),
251249
&fake_borrow_temps,
252250
scrutinee_span,
253251
Some(arm.scope),
@@ -284,7 +282,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
284282
&mut self,
285283
outer_source_info: SourceInfo,
286284
candidate: Candidate<'_, 'tcx>,
287-
guard: Option<(&Guard<'tcx>, region::Scope)>,
285+
guard: Option<&Guard<'tcx>>,
288286
fake_borrow_temps: &Vec<(Place<'tcx>, Local)>,
289287
scrutinee_span: Span,
290288
arm_scope: Option<region::Scope>,
@@ -1590,7 +1588,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15901588
&mut self,
15911589
candidate: Candidate<'pat, 'tcx>,
15921590
parent_bindings: &[(Vec<Binding<'tcx>>, Vec<Ascription<'tcx>>)],
1593-
guard: Option<(&Guard<'tcx>, region::Scope)>,
1591+
guard: Option<&Guard<'tcx>>,
15941592
fake_borrows: &Vec<(Place<'tcx>, Local)>,
15951593
scrutinee_span: Span,
15961594
schedule_drops: bool,
@@ -1702,7 +1700,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17021700
// the reference that we create for the arm.
17031701
// * So we eagerly create the reference for the arm and then take a
17041702
// reference to that.
1705-
if let Some((guard, region_scope)) = guard {
1703+
if let Some(guard) = guard {
17061704
let tcx = self.hir.tcx();
17071705
let bindings = parent_bindings
17081706
.iter()
@@ -1746,12 +1744,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17461744
unreachable
17471745
});
17481746
let outside_scope = self.cfg.start_new_block();
1749-
self.exit_scope(
1750-
source_info.span,
1751-
region_scope,
1752-
otherwise_post_guard_block,
1753-
outside_scope,
1754-
);
1747+
self.exit_top_scope(otherwise_post_guard_block, outside_scope, source_info);
17551748
self.false_edges(
17561749
outside_scope,
17571750
otherwise_block,

src/librustc_mir_build/build/matches/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
423423
let bool_ty = self.hir.bool_ty();
424424
let eq_result = self.temp(bool_ty, source_info.span);
425425
let eq_block = self.cfg.start_new_block();
426-
let cleanup = self.diverge_cleanup();
427426
self.cfg.terminate(
428427
block,
429428
source_info,
@@ -441,10 +440,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
441440
}),
442441
args: vec![val, expect],
443442
destination: Some((eq_result, eq_block)),
444-
cleanup: Some(cleanup),
443+
cleanup: None,
445444
from_hir_call: false,
446445
},
447446
);
447+
self.diverge_from(block);
448448

449449
if let [success_block, fail_block] = *make_target_blocks(self) {
450450
// check the result

0 commit comments

Comments
 (0)