Skip to content

Commit af7134e

Browse files
committedJan 3, 2021
Move variable into the only branch where it is relevant
At the `if` branch `filter` (the `let` binding) is `None` iff `filter` (the parameter) was `None`. We can branch on the parameter, move the binding into the `if`, and the complexity of handling `Option<Option<_>` largely dissolves.
1 parent 18d855b commit af7134e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed
 

‎compiler/rustc_metadata/src/rmeta/decoder.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1345,15 +1345,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13451345
return &[];
13461346
}
13471347

1348-
// Do a reverse lookup beforehand to avoid touching the crate_num
1349-
// hash map in the loop below.
1350-
let filter = match filter.map(|def_id| self.reverse_translate_def_id(def_id)) {
1351-
Some(Some(def_id)) => Some((def_id.krate.as_u32(), def_id.index)),
1352-
Some(None) => return &[],
1353-
None => None,
1354-
};
1348+
if let Some(def_id) = filter {
1349+
// Do a reverse lookup beforehand to avoid touching the crate_num
1350+
// hash map in the loop below.
1351+
let filter = match self.reverse_translate_def_id(def_id) {
1352+
Some(def_id) => (def_id.krate.as_u32(), def_id.index),
1353+
None => return &[],
1354+
};
13551355

1356-
if let Some(filter) = filter {
13571356
if let Some(impls) = self.trait_impls.get(&filter) {
13581357
tcx.arena.alloc_from_iter(
13591358
impls.decode(self).map(|(idx, simplified_self_ty)| {

0 commit comments

Comments
 (0)