about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits/vtable.rs
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2023-07-19 09:49:13 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2023-07-19 09:51:35 +0000
commitf8f5d7aab28b9c310b4312b5d38c80fe4dc6df02 (patch)
treeae3adba66054e995b16877672058d762a6c8b063 /compiler/rustc_trait_selection/src/traits/vtable.rs
parent348f26e40957c2a2469f0ea2b41c403803de8075 (diff)
downloadrust-f8f5d7aab28b9c310b4312b5d38c80fe4dc6df02.tar.gz
rust-f8f5d7aab28b9c310b4312b5d38c80fe4dc6df02.zip
Replace `if let` with `unwrap` in `prepare_vtable_segments`
Reasoning: if the stack is empty, the loop will be infinite,
so the assumption is that the stack can't be non empty. Unwrap
makes the assumption more clear (and removes an indentation level)
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits/vtable.rs')
-rw-r--r--compiler/rustc_trait_selection/src/traits/vtable.rs49
1 files changed, 24 insertions, 25 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs
index 0a3f423d3c1..ac9fb51e391 100644
--- a/compiler/rustc_trait_selection/src/traits/vtable.rs
+++ b/compiler/rustc_trait_selection/src/traits/vtable.rs
@@ -116,34 +116,33 @@ fn prepare_vtable_segments_inner<'tcx, T>(
     loop {
         // dive deeper into the stack, recording the path
         'diving_in: loop {
-            if let Some((inner_most_trait_ref, _, _)) = stack.last() {
-                let inner_most_trait_ref = *inner_most_trait_ref;
-                let mut direct_super_traits_iter = tcx
-                    .super_predicates_of(inner_most_trait_ref.def_id())
-                    .predicates
-                    .into_iter()
-                    .filter_map(move |(pred, _)| {
-                        pred.subst_supertrait(tcx, &inner_most_trait_ref).as_trait_clause()
-                    });
+            let &(inner_most_trait_ref, _, _) = stack.last().unwrap();
+
+            let mut direct_super_traits_iter = tcx
+                .super_predicates_of(inner_most_trait_ref.def_id())
+                .predicates
+                .into_iter()
+                .filter_map(move |(pred, _)| {
+                    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;
-                        }
+            '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 {
-                        break 'diving_in;
+                        continue 'diving_in_skip_visited_traits;
                     }
+                } else {
+                    break 'diving_in;
                 }
             }
         }