Skip to content

Commit 57c5ac7

Browse files
committed
Tweak the post-order for multi-successor blocks
1 parent fe76e14 commit 57c5ac7

File tree

6 files changed

+18
-20
lines changed

6 files changed

+18
-20
lines changed

compiler/rustc_middle/src/mir/terminator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub struct Terminator<'tcx> {
105105
pub kind: TerminatorKind<'tcx>,
106106
}
107107

108-
pub type Successors<'a> = impl Iterator<Item = BasicBlock> + 'a;
108+
pub type Successors<'a> = impl DoubleEndedIterator<Item = BasicBlock> + 'a;
109109
pub type SuccessorsMut<'a> =
110110
iter::Chain<std::option::IntoIter<&'a mut BasicBlock>, slice::IterMut<'a, BasicBlock>>;
111111

compiler/rustc_middle/src/mir/traversal.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
149149
// B C
150150
// | |
151151
// | |
152-
// D |
152+
// | D
153153
// \ /
154154
// \ /
155155
// E
@@ -159,26 +159,26 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
159159
//
160160
// When the first call to `traverse_successor` happens, the following happens:
161161
//
162-
// [(B, [D]), // `B` taken from the successors of `A`, pushed to the
163-
// // top of the stack along with the successors of `B`
164-
// (A, [C])]
162+
// [(C, [D]), // `C` taken from the successors of `A`, pushed to the
163+
// // top of the stack along with the successors of `C`
164+
// (A, [B])]
165165
//
166-
// [(D, [E]), // `D` taken from successors of `B`, pushed to stack
167-
// (B, []),
168-
// (A, [C])]
166+
// [(D, [E]), // `D` taken from successors of `C`, pushed to stack
167+
// (C, []),
168+
// (A, [B])]
169169
//
170170
// [(E, []), // `E` taken from successors of `D`, pushed to stack
171171
// (D, []),
172-
// (B, []),
173-
// (A, [C])]
172+
// (C, []),
173+
// (A, [B])]
174174
//
175175
// Now that the top of the stack has no successors we can traverse, each item will
176-
// be popped off during iteration until we get back to `A`. This yields [E, D, B].
176+
// be popped off during iteration until we get back to `A`. This yields [E, D, C].
177177
//
178-
// When we yield `B` and call `traverse_successor`, we push `C` to the stack, but
178+
// When we yield `C` and call `traverse_successor`, we push `B` to the stack, but
179179
// since we've already visited `E`, that child isn't added to the stack. The last
180-
// two iterations yield `C` and finally `A` for a final traversal of [E, D, B, C, A]
181-
while let Some(&mut (_, ref mut iter)) = self.visit_stack.last_mut() && let Some(bb) = iter.next() {
180+
// two iterations yield `B` and finally `A` for a final traversal of [E, D, C, B, A]
181+
while let Some(&mut (_, ref mut iter)) = self.visit_stack.last_mut() && let Some(bb) = iter.next_back() {
182182
if self.visited.insert(bb) {
183183
if let Some(term) = &self.basic_blocks[bb].terminator {
184184
self.visit_stack.push((bb, term.successors()));

tests/ui/borrowck/borrowck-thread-local-static-borrow-outlives-fn.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0712]: thread-local variable borrowed past end of function
44
LL | assert_static(&FOO);
55
| ^^^^ thread-local variables cannot be borrowed beyond the end of the function
66
LL | }
7-
| - end of enclosing function is here
7+
| - end of enclosing function is here
88

99
error: aborting due to previous error
1010

tests/ui/issues/issue-17954.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let a = &FOO;
55
| ^^^^ thread-local variables cannot be borrowed beyond the end of the function
66
...
77
LL | }
8-
| - end of enclosing function is here
8+
| - end of enclosing function is here
99

1010
error: aborting due to previous error
1111

tests/ui/issues/issue-52049.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ error[E0716]: temporary value dropped while borrowed
22
--> $DIR/issue-52049.rs:6:10
33
|
44
LL | foo(&unpromotable(5u32));
5-
| -----^^^^^^^^^^^^^^^^^^-
5+
| -----^^^^^^^^^^^^^^^^^^-- temporary value is freed at the end of this statement
66
| | |
77
| | creates a temporary value which is freed while still in use
88
| argument requires that borrow lasts for `'static`
9-
LL | }
10-
| - temporary value is freed at the end of this statement
119

1210
error: aborting due to previous error
1311

tests/ui/lifetimes/issue-90600-expected-return-static-indirect.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | let read = &refcell as &RefCell<dyn Read>;
1010
| -------- cast requires that `foo` is borrowed for `'static`
1111
...
1212
LL | }
13-
| - `foo` dropped here while still borrowed
13+
| - `foo` dropped here while still borrowed
1414

1515
error: lifetime may not live long enough
1616
--> $DIR/issue-90600-expected-return-static-indirect.rs:9:16

0 commit comments

Comments
 (0)