Skip to content

Commit d87db8e

Browse files
committed
Simplify last prepare_vtable_segments loop even more
1 parent d567f0f commit d87db8e

File tree

1 file changed

+22
-25
lines changed
  • compiler/rustc_trait_selection/src/traits

1 file changed

+22
-25
lines changed

compiler/rustc_trait_selection/src/traits/vtable.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn prepare_vtable_segments_inner<'tcx, T>(
113113
// Loop run #1: Emitting the slice [D C] (in reverse order). No one has a next-sibling node.
114114
// Loop run #1: Stack after exiting out is []. Now the function exits.
115115

116-
loop {
116+
'outer: loop {
117117
// dive deeper into the stack, recording the path
118118
'diving_in: loop {
119119
let &(inner_most_trait_ref, _, _) = stack.last().unwrap();
@@ -151,32 +151,29 @@ fn prepare_vtable_segments_inner<'tcx, T>(
151151
emit_vptr_on_new_entry = true;
152152

153153
// emit innermost item, move to next sibling and stop there if possible, otherwise jump to outer level.
154-
'exiting_out: loop {
155-
if let Some((inner_most_trait_ref, emit_vptr, siblings)) = stack.last_mut() {
156-
segment_visitor(VtblSegment::TraitOwnEntries {
157-
trait_ref: *inner_most_trait_ref,
158-
emit_vptr: *emit_vptr,
159-
})?;
160-
161-
match siblings.find(|&sibling| visited.insert(sibling.to_predicate(tcx))) {
162-
Some(next_inner_most_trait_ref) => {
163-
// We're throwing away potential constness of super traits here.
164-
// FIXME: handle ~const super traits
165-
let next_inner_most_trait_ref =
166-
next_inner_most_trait_ref.map_bound(|t| t.trait_ref);
167-
*inner_most_trait_ref = next_inner_most_trait_ref;
168-
*emit_vptr = emit_vptr_on_new_entry;
169-
break 'exiting_out;
170-
}
171-
None => {
172-
stack.pop();
173-
continue 'exiting_out;
174-
}
175-
}
154+
while let Some((inner_most_trait_ref, emit_vptr, mut siblings)) = stack.pop() {
155+
segment_visitor(VtblSegment::TraitOwnEntries {
156+
trait_ref: inner_most_trait_ref,
157+
emit_vptr,
158+
})?;
159+
160+
if let Some(next_inner_most_trait_ref) =
161+
siblings.find(|&sibling| visited.insert(sibling.to_predicate(tcx)))
162+
{
163+
// We're throwing away potential constness of super traits here.
164+
// FIXME: handle ~const super traits
165+
let next_inner_most_trait_ref =
166+
next_inner_most_trait_ref.map_bound(|t| t.trait_ref);
167+
168+
stack.push((next_inner_most_trait_ref, emit_vptr_on_new_entry, siblings));
169+
170+
// just pushed a new trait onto the stack, so we need to go through its super traits
171+
continue 'outer;
176172
}
177-
// all done
178-
return ControlFlow::Continue(());
179173
}
174+
175+
// the stack is empty, all done
176+
return ControlFlow::Continue(());
180177
}
181178
}
182179

0 commit comments

Comments
 (0)