Skip to content

Commit 3655175

Browse files
committed
Auto merge of rust-lang#97111 - JohnTitor:rollup-x3vjf6u, r=JohnTitor
Rollup of 7 pull requests Successful merges: - rust-lang#96329 (Add a couple tests for rust-lang#90887 fixes) - rust-lang#97009 (Allow `unused_macro_rules` in path tests) - rust-lang#97075 (Add regression test for rust-lang#81804) - rust-lang#97079 (Change `Successors` to `impl Iterator<Item = BasicBlock>`) - rust-lang#97080 (remove the `RelateResultCompare` trait) - rust-lang#97093 (Migrate `maybe_recover_from_bad_type_plus` diagnostic) - rust-lang#97102 (Update function pointer call error message) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 735efc0 + 5fdc849 commit 3655175

File tree

31 files changed

+250
-97
lines changed

31 files changed

+250
-97
lines changed

compiler/rustc_borrowck/src/dataflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'tcx> OutOfScopePrecomputer<'_, 'tcx> {
199199
// Add successor BBs to the work list, if necessary.
200200
let bb_data = &self.body[bb];
201201
debug_assert!(hi == bb_data.statements.len());
202-
for &succ_bb in bb_data.terminator().successors() {
202+
for succ_bb in bb_data.terminator().successors() {
203203
if !self.visited.insert(succ_bb) {
204204
if succ_bb == location.block && first_lo > 0 {
205205
// `succ_bb` has been seen before. If it wasn't

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
467467
block
468468
.terminator()
469469
.successors()
470-
.map(|bb| Location { statement_index: 0, block: *bb })
470+
.map(|bb| Location { statement_index: 0, block: bb })
471471
.filter(|s| visited_locations.insert(*s))
472472
.map(|s| {
473473
if self.is_back_edge(location, s) {
@@ -526,7 +526,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
526526
}
527527
} else {
528528
for bb in block.terminator().successors() {
529-
let successor = Location { statement_index: 0, block: *bb };
529+
let successor = Location { statement_index: 0, block: bb };
530530

531531
if !visited_locations.contains(&successor)
532532
&& self.find_loop_head_dfs(successor, loop_head, visited_locations)

compiler/rustc_borrowck/src/diagnostics/find_use.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ impl<'cx, 'tcx> UseFinder<'cx, 'tcx> {
6767
block_data
6868
.terminator()
6969
.successors()
70-
.filter(|&bb| Some(&Some(*bb)) != block_data.terminator().unwind())
71-
.map(|&bb| Location { statement_index: 0, block: bb }),
70+
.filter(|&bb| Some(&Some(bb)) != block_data.terminator().unwind())
71+
.map(|bb| Location { statement_index: 0, block: bb }),
7272
);
7373
}
7474
}

compiler/rustc_borrowck/src/nll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn populate_polonius_move_facts(
108108
// We are at the terminator of an init that has a panic path,
109109
// and where the init should not happen on panic
110110

111-
for &successor in block_data.terminator().successors() {
111+
for successor in block_data.terminator().successors() {
112112
if body[successor].is_cleanup {
113113
continue;
114114
}

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKi
328328
bb, data, result[bb], funclet
329329
);
330330

331-
for &succ in data.terminator().successors() {
331+
for succ in data.terminator().successors() {
332332
let kind = result[succ];
333333
debug!("cleanup_kinds: propagating {:?} to {:?}/{:?}", funclet, succ, kind);
334334
match kind {

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
8989
ccx: &ConstCx<'_, 'tcx>,
9090
span: Span,
9191
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
92-
ccx.tcx.sess.struct_span_err(span, "function pointers are not allowed in const fn")
92+
ccx.tcx.sess.struct_span_err(
93+
span,
94+
&format!("function pointer calls are not allowed in {}s", ccx.const_kind()),
95+
)
9396
}
9497
}
9598

compiler/rustc_error_messages/locales/en-US/parser.ftl

+9
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ parser-struct-literal-body-without-path =
55
parser-maybe-report-ambiguous-plus =
66
ambiguous `+` in a type
77
.suggestion = use parentheses to disambiguate
8+
9+
parser-maybe-recover-from-bad-type-plus =
10+
expected a path on the left-hand side of `+`, not `{$ty}`
11+
12+
parser-add-paren = try adding parentheses
13+
14+
parser-forgot-paren = perhaps you forgot parentheses?
15+
16+
parser-expect-path = expected a path

compiler/rustc_infer/src/infer/combine.rs

-15
Original file line numberDiff line numberDiff line change
@@ -776,21 +776,6 @@ pub trait ConstEquateRelation<'tcx>: TypeRelation<'tcx> {
776776
fn const_equate_obligation(&mut self, a: ty::Const<'tcx>, b: ty::Const<'tcx>);
777777
}
778778

779-
pub trait RelateResultCompare<'tcx, T> {
780-
fn compare<F>(&self, t: T, f: F) -> RelateResult<'tcx, T>
781-
where
782-
F: FnOnce() -> TypeError<'tcx>;
783-
}
784-
785-
impl<'tcx, T: Clone + PartialEq> RelateResultCompare<'tcx, T> for RelateResult<'tcx, T> {
786-
fn compare<F>(&self, t: T, f: F) -> RelateResult<'tcx, T>
787-
where
788-
F: FnOnce() -> TypeError<'tcx>,
789-
{
790-
self.clone().and_then(|s| if s == t { self.clone() } else { Err(f()) })
791-
}
792-
}
793-
794779
pub fn const_unification_error<'tcx>(
795780
a_is_expected: bool,
796781
(a, b): (ty::Const<'tcx>, ty::Const<'tcx>),

compiler/rustc_infer/src/infer/nll_relate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ where
859859

860860
delegate: &'me mut D,
861861

862-
/// After we generalize this type, we are going to relative it to
862+
/// After we generalize this type, we are going to relate it to
863863
/// some other type. What will be the variance at this point?
864864
ambient_variance: ty::Variance,
865865

compiler/rustc_middle/src/mir/generic_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn mir_fn_to_generic_graph<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Grap
2424
let terminator = body[source].terminator();
2525
let labels = terminator.kind.fmt_successor_labels();
2626

27-
for (&target, label) in terminator.successors().zip(labels) {
27+
for (target, label) in terminator.successors().zip(labels) {
2828
let src = node(def_id, source);
2929
let trg = node(def_id, target);
3030
edges.push(Edge::new(src, trg, label.to_string()));

compiler/rustc_middle/src/mir/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1355,10 +1355,7 @@ pub enum InlineAsmOperand<'tcx> {
13551355
/// Type for MIR `Assert` terminator error messages.
13561356
pub type AssertMessage<'tcx> = AssertKind<Operand<'tcx>>;
13571357

1358-
// FIXME: Change `Successors` to `impl Iterator<Item = BasicBlock>`.
1359-
#[allow(rustc::pass_by_value)]
1360-
pub type Successors<'a> =
1361-
iter::Chain<option::IntoIter<&'a BasicBlock>, slice::Iter<'a, BasicBlock>>;
1358+
pub type Successors<'a> = impl Iterator<Item = BasicBlock> + 'a;
13621359
pub type SuccessorsMut<'a> =
13631360
iter::Chain<option::IntoIter<&'a mut BasicBlock>, slice::IterMut<'a, BasicBlock>>;
13641361

@@ -3434,13 +3431,13 @@ impl<'tcx> graph::WithStartNode for Body<'tcx> {
34343431
impl<'tcx> graph::WithSuccessors for Body<'tcx> {
34353432
#[inline]
34363433
fn successors(&self, node: Self::Node) -> <Self as GraphSuccessors<'_>>::Iter {
3437-
self.basic_blocks[node].terminator().successors().cloned()
3434+
self.basic_blocks[node].terminator().successors()
34383435
}
34393436
}
34403437

34413438
impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> {
34423439
type Item = BasicBlock;
3443-
type Iter = iter::Cloned<Successors<'b>>;
3440+
type Iter = Successors<'b>;
34443441
}
34453442

34463443
impl<'tcx, 'graph> graph::GraphPredecessors<'graph> for Body<'tcx> {

compiler/rustc_middle/src/mir/patch.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ impl<'tcx> MirPatch<'tcx> {
166166
// get terminator's targets and apply the statement to all of them.
167167
if loc.statement_index > body[loc.block].statements.len() {
168168
let term = body[loc.block].terminator();
169-
let successors = term.successors().clone();
170-
171-
for i in successors {
169+
for i in term.successors() {
172170
stmts_and_targets
173171
.push((Statement { source_info, kind: stmt.clone() }, i.clone()));
174172
}

compiler/rustc_middle/src/mir/predecessors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl PredecessorCache {
4343
let mut preds = IndexVec::from_elem(SmallVec::new(), basic_blocks);
4444
for (bb, data) in basic_blocks.iter_enumerated() {
4545
if let Some(term) = &data.terminator {
46-
for &succ in term.successors() {
46+
for succ in term.successors() {
4747
preds[succ].push(bb);
4848
}
4949
}

compiler/rustc_middle/src/mir/terminator.rs

+27-23
Original file line numberDiff line numberDiff line change
@@ -416,32 +416,36 @@ impl<'tcx> TerminatorKind<'tcx> {
416416
| Return
417417
| Unreachable
418418
| Call { destination: None, cleanup: None, .. }
419-
| InlineAsm { destination: None, cleanup: None, .. } => None.into_iter().chain(&[]),
420-
Goto { target: ref t }
421-
| Call { destination: None, cleanup: Some(ref t), .. }
422-
| Call { destination: Some((_, ref t)), cleanup: None, .. }
423-
| Yield { resume: ref t, drop: None, .. }
424-
| DropAndReplace { target: ref t, unwind: None, .. }
425-
| Drop { target: ref t, unwind: None, .. }
426-
| Assert { target: ref t, cleanup: None, .. }
427-
| FalseUnwind { real_target: ref t, unwind: None }
428-
| InlineAsm { destination: Some(ref t), cleanup: None, .. }
429-
| InlineAsm { destination: None, cleanup: Some(ref t), .. } => {
430-
Some(t).into_iter().chain(&[])
419+
| InlineAsm { destination: None, cleanup: None, .. } => {
420+
None.into_iter().chain((&[]).into_iter().copied())
431421
}
432-
Call { destination: Some((_, ref t)), cleanup: Some(ref u), .. }
433-
| Yield { resume: ref t, drop: Some(ref u), .. }
434-
| DropAndReplace { target: ref t, unwind: Some(ref u), .. }
435-
| Drop { target: ref t, unwind: Some(ref u), .. }
436-
| Assert { target: ref t, cleanup: Some(ref u), .. }
437-
| FalseUnwind { real_target: ref t, unwind: Some(ref u) }
438-
| InlineAsm { destination: Some(ref t), cleanup: Some(ref u), .. } => {
439-
Some(t).into_iter().chain(slice::from_ref(u))
422+
Goto { target: t }
423+
| Call { destination: None, cleanup: Some(t), .. }
424+
| Call { destination: Some((_, t)), cleanup: None, .. }
425+
| Yield { resume: t, drop: None, .. }
426+
| DropAndReplace { target: t, unwind: None, .. }
427+
| Drop { target: t, unwind: None, .. }
428+
| Assert { target: t, cleanup: None, .. }
429+
| FalseUnwind { real_target: t, unwind: None }
430+
| InlineAsm { destination: Some(t), cleanup: None, .. }
431+
| InlineAsm { destination: None, cleanup: Some(t), .. } => {
432+
Some(t).into_iter().chain((&[]).into_iter().copied())
440433
}
441-
SwitchInt { ref targets, .. } => None.into_iter().chain(&targets.targets),
442-
FalseEdge { ref real_target, ref imaginary_target } => {
443-
Some(real_target).into_iter().chain(slice::from_ref(imaginary_target))
434+
Call { destination: Some((_, t)), cleanup: Some(ref u), .. }
435+
| Yield { resume: t, drop: Some(ref u), .. }
436+
| DropAndReplace { target: t, unwind: Some(ref u), .. }
437+
| Drop { target: t, unwind: Some(ref u), .. }
438+
| Assert { target: t, cleanup: Some(ref u), .. }
439+
| FalseUnwind { real_target: t, unwind: Some(ref u) }
440+
| InlineAsm { destination: Some(t), cleanup: Some(ref u), .. } => {
441+
Some(t).into_iter().chain(slice::from_ref(u).into_iter().copied())
444442
}
443+
SwitchInt { ref targets, .. } => {
444+
None.into_iter().chain(targets.targets.iter().copied())
445+
}
446+
FalseEdge { real_target, ref imaginary_target } => Some(real_target)
447+
.into_iter()
448+
.chain(slice::from_ref(imaginary_target).into_iter().copied()),
445449
}
446450
}
447451

compiler/rustc_middle/src/mir/traversal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
180180
// two iterations yield `C` and finally `A` for a final traversal of [E, D, B, C, A]
181181
loop {
182182
let bb = if let Some(&mut (_, ref mut iter)) = self.visit_stack.last_mut() {
183-
if let Some(&bb) = iter.next() {
183+
if let Some(bb) = iter.next() {
184184
bb
185185
} else {
186186
break;

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ where
125125
}
126126

127127
fn target(&self, edge: &Self::Edge) -> Self::Node {
128-
self.body[edge.source].terminator().successors().nth(edge.index).copied().unwrap()
128+
self.body[edge.source].terminator().successors().nth(edge.index).unwrap()
129129
}
130130
}
131131

compiler/rustc_mir_transform/src/coverage/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ pub(super) fn dump_coverage_graphviz<'tcx>(
701701
edge_labels.retain(|label| label != "unreachable");
702702
let edge_counters = from_terminator
703703
.successors()
704-
.map(|&successor_bb| graphviz_data.get_edge_counter(from_bcb, successor_bb));
704+
.map(|successor_bb| graphviz_data.get_edge_counter(from_bcb, successor_bb));
705705
iter::zip(&edge_labels, edge_counters)
706706
.map(|(label, some_counter)| {
707707
if let Some(counter) = some_counter {

compiler/rustc_mir_transform/src/coverage/graph.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -484,17 +484,17 @@ fn bcb_filtered_successors<'a, 'tcx>(
484484
body: &'tcx &'a mir::Body<'tcx>,
485485
term_kind: &'tcx TerminatorKind<'tcx>,
486486
) -> Box<dyn Iterator<Item = BasicBlock> + 'a> {
487-
let mut successors = term_kind.successors();
488487
Box::new(
489488
match &term_kind {
490489
// SwitchInt successors are never unwind, and all of them should be traversed.
491-
TerminatorKind::SwitchInt { .. } => successors,
490+
TerminatorKind::SwitchInt { ref targets, .. } => {
491+
None.into_iter().chain(targets.all_targets().into_iter().copied())
492+
}
492493
// For all other kinds, return only the first successor, if any, and ignore unwinds.
493494
// NOTE: `chain(&[])` is required to coerce the `option::iter` (from
494495
// `next().into_iter()`) into the `mir::Successors` aliased type.
495-
_ => successors.next().into_iter().chain(&[]),
496+
_ => term_kind.successors().next().into_iter().chain((&[]).into_iter().copied()),
496497
}
497-
.copied()
498498
.filter(move |&successor| body[successor].terminator().kind != TerminatorKind::Unreachable),
499499
)
500500
}

compiler/rustc_mir_transform/src/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl<'tcx> Inliner<'tcx> {
449449
}
450450

451451
if !is_drop {
452-
for &succ in term.successors() {
452+
for succ in term.successors() {
453453
work_list.push(succ);
454454
}
455455
}

compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl RemoveNoopLandingPads {
6565
| TerminatorKind::SwitchInt { .. }
6666
| TerminatorKind::FalseEdge { .. }
6767
| TerminatorKind::FalseUnwind { .. } => {
68-
terminator.successors().all(|&succ| nop_landing_pads.contains(succ))
68+
terminator.successors().all(|succ| nop_landing_pads.contains(succ))
6969
}
7070
TerminatorKind::GeneratorDrop
7171
| TerminatorKind::Yield { .. }

compiler/rustc_mir_transform/src/simplify.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
8181

8282
for (_, data) in traversal::preorder(body) {
8383
if let Some(ref term) = data.terminator {
84-
for &tgt in term.successors() {
84+
for tgt in term.successors() {
8585
pred_count[tgt] += 1;
8686
}
8787
}
@@ -235,8 +235,8 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
235235
};
236236

237237
let first_succ = {
238-
if let Some(&first_succ) = terminator.successors().next() {
239-
if terminator.successors().all(|s| *s == first_succ) {
238+
if let Some(first_succ) = terminator.successors().next() {
239+
if terminator.successors().all(|s| s == first_succ) {
240240
let count = terminator.successors().count();
241241
self.pred_count[first_succ] -= (count - 1) as u32;
242242
first_succ

0 commit comments

Comments
 (0)