Skip to content

Commit 450abe8

Browse files
committed
Auto merge of rust-lang#73081 - Dylan-DPC:rollup-1aqk215, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#72810 (validate basic sanity for TerminatorKind) - rust-lang#72989 (Revert pr 71840) - rust-lang#72993 (Count the beta prerelease number just from master) - rust-lang#73057 (Clean up E0644 explanation) - rust-lang#73059 (remove outdated comment) Failed merges: r? @ghost
2 parents 9c1857f + b117a39 commit 450abe8

File tree

63 files changed

+1900
-1677
lines changed

Some content is hidden

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

63 files changed

+1900
-1677
lines changed

src/bootstrap/lib.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -963,29 +963,15 @@ impl Build {
963963
return s;
964964
}
965965

966-
let beta = output(
967-
Command::new("git").arg("ls-remote").arg("origin").arg("beta").current_dir(&self.src),
968-
);
969-
let beta = beta.trim().split_whitespace().next().unwrap();
970-
let master = output(
971-
Command::new("git").arg("ls-remote").arg("origin").arg("master").current_dir(&self.src),
972-
);
973-
let master = master.trim().split_whitespace().next().unwrap();
974-
975-
// Figure out where the current beta branch started.
976-
let base = output(
977-
Command::new("git").arg("merge-base").arg(beta).arg(master).current_dir(&self.src),
978-
);
979-
let base = base.trim();
980-
981-
// Next figure out how many merge commits happened since we branched off
982-
// beta. That's our beta number!
966+
// Figure out how many merge commits happened since we branched off master.
967+
// That's our beta number!
968+
// (Note that we use a `..` range, not the `...` symmetric difference.)
983969
let count = output(
984970
Command::new("git")
985971
.arg("rev-list")
986972
.arg("--count")
987973
.arg("--merges")
988-
.arg(format!("{}...HEAD", base))
974+
.arg("refs/remotes/origin/master..HEAD")
989975
.current_dir(&self.src),
990976
);
991977
let n = count.trim().parse().unwrap();

src/librustc_error_codes/error_codes/E0644.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
A closure or generator was constructed that references its own type.
22

3-
Erroneous example:
3+
Erroneous code example:
44

55
```compile_fail,E0644
66
fn fix<F>(f: &F)

src/librustc_middle/ty/sty.rs

-4
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,6 @@ impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> {
724724
///
725725
/// Trait references also appear in object types like `Foo<U>`, but in
726726
/// that case the `Self` parameter is absent from the substitutions.
727-
///
728-
/// Note that a `TraitRef` introduces a level of region binding, to
729-
/// account for higher-ranked trait bounds like `T: for<'a> Foo<&'a U>`
730-
/// or higher-ranked object types.
731727
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
732728
#[derive(HashStable, TypeFoldable)]
733729
pub struct TraitRef<'tcx> {

src/librustc_mir/dataflow/move_paths/builder.rs

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

372+
TerminatorKind::Return => {
373+
self.gather_move(Place::return_place());
374+
}
375+
377376
TerminatorKind::Assert { ref cond, .. } => {
378377
self.gather_operand(cond);
379378
}
@@ -417,7 +416,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
417416
ref operands,
418417
options: _,
419418
line_spans: _,
420-
destination: _
419+
destination: _,
421420
} => {
422421
for op in operands {
423422
match *op {

src/librustc_mir/interpret/terminator.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5050
self.go_to_block(target_block);
5151
}
5252

53-
Call { ref func, ref args, destination, ref cleanup, .. } => {
53+
Call {
54+
ref func,
55+
ref args,
56+
destination,
57+
ref cleanup,
58+
from_hir_call: _from_hir_call,
59+
} => {
5460
let old_stack = self.frame_idx();
5561
let old_loc = self.frame().loc;
5662
let func = self.eval_operand(func, None)?;

src/librustc_mir/transform/validate.rs

+120-15
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
use super::{MirPass, MirSource};
44
use rustc_middle::mir::visit::Visitor;
55
use rustc_middle::{
6-
mir::{Body, Location, Operand, Rvalue, Statement, StatementKind},
7-
ty::{ParamEnv, TyCtxt},
6+
mir::{
7+
BasicBlock, Body, Location, Operand, Rvalue, Statement, StatementKind, Terminator,
8+
TerminatorKind,
9+
},
10+
ty::{self, ParamEnv, TyCtxt},
811
};
9-
use rustc_span::{def_id::DefId, Span, DUMMY_SP};
12+
use rustc_span::def_id::DefId;
1013

1114
pub struct Validator {
1215
/// Describes at which point in the pipeline this validation is happening.
@@ -30,27 +33,38 @@ struct TypeChecker<'a, 'tcx> {
3033
}
3134

3235
impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
33-
fn fail(&self, span: Span, msg: impl AsRef<str>) {
36+
fn fail(&self, location: Location, msg: impl AsRef<str>) {
37+
let span = self.body.source_info(location).span;
3438
// We use `delay_span_bug` as we might see broken MIR when other errors have already
3539
// occurred.
3640
self.tcx.sess.diagnostic().delay_span_bug(
3741
span,
38-
&format!("broken MIR in {:?} ({}): {}", self.def_id, self.when, msg.as_ref()),
42+
&format!(
43+
"broken MIR in {:?} ({}) at {:?}:\n{}",
44+
self.def_id,
45+
self.when,
46+
location,
47+
msg.as_ref()
48+
),
3949
);
4050
}
51+
52+
fn check_bb(&self, location: Location, bb: BasicBlock) {
53+
if self.body.basic_blocks().get(bb).is_none() {
54+
self.fail(location, format!("encountered jump to invalid basic block {:?}", bb))
55+
}
56+
}
4157
}
4258

4359
impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
4460
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
4561
// `Operand::Copy` is only supposed to be used with `Copy` types.
4662
if let Operand::Copy(place) = operand {
4763
let ty = place.ty(&self.body.local_decls, self.tcx).ty;
64+
let span = self.body.source_info(location).span;
4865

49-
if !ty.is_copy_modulo_regions(self.tcx, self.param_env, DUMMY_SP) {
50-
self.fail(
51-
DUMMY_SP,
52-
format!("`Operand::Copy` with non-`Copy` type {} at {:?}", ty, location),
53-
);
66+
if !ty.is_copy_modulo_regions(self.tcx, self.param_env, span) {
67+
self.fail(location, format!("`Operand::Copy` with non-`Copy` type {}", ty));
5468
}
5569
}
5670

@@ -65,16 +79,107 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
6579
Rvalue::Use(Operand::Copy(src) | Operand::Move(src)) => {
6680
if dest == src {
6781
self.fail(
68-
DUMMY_SP,
69-
format!(
70-
"encountered `Assign` statement with overlapping memory at {:?}",
71-
location
72-
),
82+
location,
83+
"encountered `Assign` statement with overlapping memory",
7384
);
7485
}
7586
}
7687
_ => {}
7788
}
7889
}
7990
}
91+
92+
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
93+
match &terminator.kind {
94+
TerminatorKind::Goto { target } => {
95+
self.check_bb(location, *target);
96+
}
97+
TerminatorKind::SwitchInt { targets, values, .. } => {
98+
if targets.len() != values.len() + 1 {
99+
self.fail(
100+
location,
101+
format!(
102+
"encountered `SwitchInt` terminator with {} values, but {} targets (should be values+1)",
103+
values.len(),
104+
targets.len(),
105+
),
106+
);
107+
}
108+
for target in targets {
109+
self.check_bb(location, *target);
110+
}
111+
}
112+
TerminatorKind::Drop { target, unwind, .. } => {
113+
self.check_bb(location, *target);
114+
if let Some(unwind) = unwind {
115+
self.check_bb(location, *unwind);
116+
}
117+
}
118+
TerminatorKind::DropAndReplace { target, unwind, .. } => {
119+
self.check_bb(location, *target);
120+
if let Some(unwind) = unwind {
121+
self.check_bb(location, *unwind);
122+
}
123+
}
124+
TerminatorKind::Call { func, destination, cleanup, .. } => {
125+
let func_ty = func.ty(&self.body.local_decls, self.tcx);
126+
match func_ty.kind {
127+
ty::FnPtr(..) | ty::FnDef(..) => {}
128+
_ => self.fail(
129+
location,
130+
format!("encountered non-callable type {} in `Call` terminator", func_ty),
131+
),
132+
}
133+
if let Some((_, target)) = destination {
134+
self.check_bb(location, *target);
135+
}
136+
if let Some(cleanup) = cleanup {
137+
self.check_bb(location, *cleanup);
138+
}
139+
}
140+
TerminatorKind::Assert { cond, target, cleanup, .. } => {
141+
let cond_ty = cond.ty(&self.body.local_decls, self.tcx);
142+
if cond_ty != self.tcx.types.bool {
143+
self.fail(
144+
location,
145+
format!(
146+
"encountered non-boolean condition of type {} in `Assert` terminator",
147+
cond_ty
148+
),
149+
);
150+
}
151+
self.check_bb(location, *target);
152+
if let Some(cleanup) = cleanup {
153+
self.check_bb(location, *cleanup);
154+
}
155+
}
156+
TerminatorKind::Yield { resume, drop, .. } => {
157+
self.check_bb(location, *resume);
158+
if let Some(drop) = drop {
159+
self.check_bb(location, *drop);
160+
}
161+
}
162+
TerminatorKind::FalseEdges { real_target, imaginary_target } => {
163+
self.check_bb(location, *real_target);
164+
self.check_bb(location, *imaginary_target);
165+
}
166+
TerminatorKind::FalseUnwind { real_target, unwind } => {
167+
self.check_bb(location, *real_target);
168+
if let Some(unwind) = unwind {
169+
self.check_bb(location, *unwind);
170+
}
171+
}
172+
TerminatorKind::InlineAsm { destination, .. } => {
173+
if let Some(destination) = destination {
174+
self.check_bb(location, *destination);
175+
}
176+
}
177+
// Nothing to validate for these.
178+
TerminatorKind::Resume
179+
| TerminatorKind::Abort
180+
| TerminatorKind::Return
181+
| TerminatorKind::Unreachable
182+
| TerminatorKind::GeneratorDrop => {}
183+
}
184+
}
80185
}

src/librustc_mir/util/elaborate_drops.rs

+35-11
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ where
233233
.patch_terminator(bb, TerminatorKind::Goto { target: self.succ });
234234
}
235235
DropStyle::Static => {
236+
let loc = self.terminator_loc(bb);
237+
self.elaborator.clear_drop_flag(loc, self.path, DropFlagMode::Deep);
236238
self.elaborator.patch().patch_terminator(
237239
bb,
238240
TerminatorKind::Drop {
@@ -243,7 +245,9 @@ where
243245
);
244246
}
245247
DropStyle::Conditional => {
246-
let drop_bb = self.complete_drop(self.succ, self.unwind);
248+
let unwind = self.unwind; // FIXME(#43234)
249+
let succ = self.succ;
250+
let drop_bb = self.complete_drop(Some(DropFlagMode::Deep), succ, unwind);
247251
self.elaborator
248252
.patch()
249253
.patch_terminator(bb, TerminatorKind::Goto { target: drop_bb });
@@ -315,7 +319,7 @@ where
315319
// our own drop flag.
316320
path: self.path,
317321
}
318-
.complete_drop(succ, unwind)
322+
.complete_drop(None, succ, unwind)
319323
}
320324
}
321325

@@ -344,7 +348,13 @@ where
344348
// Clear the "master" drop flag at the end. This is needed
345349
// because the "master" drop protects the ADT's discriminant,
346350
// which is invalidated after the ADT is dropped.
347-
(self.drop_flag_reset_block(DropFlagMode::Shallow, self.succ, self.unwind), self.unwind)
351+
let (succ, unwind) = (self.succ, self.unwind); // FIXME(#43234)
352+
(
353+
self.drop_flag_reset_block(DropFlagMode::Shallow, succ, unwind),
354+
unwind.map(|unwind| {
355+
self.drop_flag_reset_block(DropFlagMode::Shallow, unwind, Unwind::InCleanup)
356+
}),
357+
)
348358
}
349359

350360
/// Creates a full drop ladder, consisting of 2 connected half-drop-ladders
@@ -878,7 +888,11 @@ where
878888
self.open_drop_for_adt(def, substs)
879889
}
880890
}
881-
ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind),
891+
ty::Dynamic(..) => {
892+
let unwind = self.unwind; // FIXME(#43234)
893+
let succ = self.succ;
894+
self.complete_drop(Some(DropFlagMode::Deep), succ, unwind)
895+
}
882896
ty::Array(ety, size) => {
883897
let size = size.try_eval_usize(self.tcx(), self.elaborator.param_env());
884898
self.open_drop_for_array(ety, size)
@@ -889,10 +903,20 @@ where
889903
}
890904
}
891905

892-
fn complete_drop(&mut self, succ: BasicBlock, unwind: Unwind) -> BasicBlock {
893-
debug!("complete_drop(succ={:?}, unwind={:?})", succ, unwind);
906+
fn complete_drop(
907+
&mut self,
908+
drop_mode: Option<DropFlagMode>,
909+
succ: BasicBlock,
910+
unwind: Unwind,
911+
) -> BasicBlock {
912+
debug!("complete_drop({:?},{:?})", self, drop_mode);
894913

895914
let drop_block = self.drop_block(succ, unwind);
915+
let drop_block = if let Some(mode) = drop_mode {
916+
self.drop_flag_reset_block(mode, drop_block, unwind)
917+
} else {
918+
drop_block
919+
};
896920

897921
self.drop_flag_test_block(drop_block, succ, unwind)
898922
}
@@ -907,11 +931,6 @@ where
907931
) -> BasicBlock {
908932
debug!("drop_flag_reset_block({:?},{:?})", self, mode);
909933

910-
if unwind.is_cleanup() {
911-
// The drop flag isn't read again on the unwind path, so don't
912-
// bother setting it.
913-
return succ;
914-
}
915934
let block = self.new_block(unwind, TerminatorKind::Goto { target: succ });
916935
let block_start = Location { block, statement_index: 0 };
917936
self.elaborator.clear_drop_flag(block_start, self.path, mode);
@@ -1028,6 +1047,11 @@ where
10281047
self.elaborator.patch().new_temp(ty, self.source_info.span)
10291048
}
10301049

1050+
fn terminator_loc(&mut self, bb: BasicBlock) -> Location {
1051+
let body = self.elaborator.body();
1052+
self.elaborator.patch().terminator_loc(body, bb)
1053+
}
1054+
10311055
fn constant_usize(&self, val: u16) -> Operand<'tcx> {
10321056
Operand::Constant(box Constant {
10331057
span: self.source_info.span,

0 commit comments

Comments
 (0)