about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2023-07-19 10:01:48 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2023-07-19 10:01:48 +0000
commit364fc444a5f4e8f348d5abeb9978894ed250823a (patch)
tree7e968e43b2288ca17bbee39cd1b31ac738f4ec53 /compiler/rustc_trait_selection/src/traits
parentf8f5d7aab28b9c310b4312b5d38c80fe4dc6df02 (diff)
downloadrust-364fc444a5f4e8f348d5abeb9978894ed250823a.tar.gz
rust-364fc444a5f4e8f348d5abeb9978894ed250823a.zip
Refactor 'diving_in loop internals in `prepare_vtable_segments`
Less explicit loops -- easier to read.
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits')
-rw-r--r--compiler/rustc_trait_selection/src/traits/vtable.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs
index ac9fb51e391..89b5272083e 100644
--- a/compiler/rustc_trait_selection/src/traits/vtable.rs
+++ b/compiler/rustc_trait_selection/src/traits/vtable.rs
@@ -126,24 +126,24 @@ fn prepare_vtable_segments_inner<'tcx, T>(
                     pred.subst_supertrait(tcx, &inner_most_trait_ref).as_trait_clause()
                 });
 
-            'diving_in_skip_visited_traits: loop {
-                if let Some(next_super_trait) = direct_super_traits_iter.next() {
-                    if visited.insert(next_super_trait.to_predicate(tcx)) {
-                        // We're throwing away potential constness of super traits here.
-                        // FIXME: handle ~const super traits
-                        let next_super_trait = next_super_trait.map_bound(|t| t.trait_ref);
-                        stack.push((
-                            next_super_trait,
-                            emit_vptr_on_new_entry,
-                            Some(direct_super_traits_iter),
-                        ));
-                        break 'diving_in_skip_visited_traits;
-                    } else {
-                        continue 'diving_in_skip_visited_traits;
-                    }
-                } else {
-                    break 'diving_in;
+            // Find an unvisited supertrait
+            match direct_super_traits_iter
+                .find(|&super_trait| visited.insert(super_trait.to_predicate(tcx)))
+            {
+                // Push it to the stack for the next iteration of 'diving_in to pick up
+                Some(unvisited_super_trait) => {
+                    // We're throwing away potential constness of super traits here.
+                    // FIXME: handle ~const super traits
+                    let next_super_trait = unvisited_super_trait.map_bound(|t| t.trait_ref);
+                    stack.push((
+                        next_super_trait,
+                        emit_vptr_on_new_entry,
+                        Some(direct_super_traits_iter),
+                    ))
                 }
+
+                // There are no more unvisited direct super traits, dive-in finished
+                None => break 'diving_in,
             }
         }