Skip to content

Commit f8f5d7a

Browse files
committed
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)
1 parent 348f26e commit f8f5d7a

File tree

1 file changed

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

1 file changed

+24
-25
lines changed

compiler/rustc_trait_selection/src/traits/vtable.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -116,34 +116,33 @@ fn prepare_vtable_segments_inner<'tcx, T>(
116116
loop {
117117
// dive deeper into the stack, recording the path
118118
'diving_in: loop {
119-
if let Some((inner_most_trait_ref, _, _)) = stack.last() {
120-
let inner_most_trait_ref = *inner_most_trait_ref;
121-
let mut direct_super_traits_iter = tcx
122-
.super_predicates_of(inner_most_trait_ref.def_id())
123-
.predicates
124-
.into_iter()
125-
.filter_map(move |(pred, _)| {
126-
pred.subst_supertrait(tcx, &inner_most_trait_ref).as_trait_clause()
127-
});
119+
let &(inner_most_trait_ref, _, _) = stack.last().unwrap();
120+
121+
let mut direct_super_traits_iter = tcx
122+
.super_predicates_of(inner_most_trait_ref.def_id())
123+
.predicates
124+
.into_iter()
125+
.filter_map(move |(pred, _)| {
126+
pred.subst_supertrait(tcx, &inner_most_trait_ref).as_trait_clause()
127+
});
128128

129-
'diving_in_skip_visited_traits: loop {
130-
if let Some(next_super_trait) = direct_super_traits_iter.next() {
131-
if visited.insert(next_super_trait.to_predicate(tcx)) {
132-
// We're throwing away potential constness of super traits here.
133-
// FIXME: handle ~const super traits
134-
let next_super_trait = next_super_trait.map_bound(|t| t.trait_ref);
135-
stack.push((
136-
next_super_trait,
137-
emit_vptr_on_new_entry,
138-
Some(direct_super_traits_iter),
139-
));
140-
break 'diving_in_skip_visited_traits;
141-
} else {
142-
continue 'diving_in_skip_visited_traits;
143-
}
129+
'diving_in_skip_visited_traits: loop {
130+
if let Some(next_super_trait) = direct_super_traits_iter.next() {
131+
if visited.insert(next_super_trait.to_predicate(tcx)) {
132+
// We're throwing away potential constness of super traits here.
133+
// FIXME: handle ~const super traits
134+
let next_super_trait = next_super_trait.map_bound(|t| t.trait_ref);
135+
stack.push((
136+
next_super_trait,
137+
emit_vptr_on_new_entry,
138+
Some(direct_super_traits_iter),
139+
));
140+
break 'diving_in_skip_visited_traits;
144141
} else {
145-
break 'diving_in;
142+
continue 'diving_in_skip_visited_traits;
146143
}
144+
} else {
145+
break 'diving_in;
147146
}
148147
}
149148
}

0 commit comments

Comments
 (0)