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.
This commit is contained in:
parent
18d855b8f6
commit
af7134e7de
1 changed files with 7 additions and 8 deletions
|
@ -1345,15 +1345,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
return &[];
|
return &[];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do a reverse lookup beforehand to avoid touching the crate_num
|
if let Some(def_id) = filter {
|
||||||
// hash map in the loop below.
|
// Do a reverse lookup beforehand to avoid touching the crate_num
|
||||||
let filter = match filter.map(|def_id| self.reverse_translate_def_id(def_id)) {
|
// hash map in the loop below.
|
||||||
Some(Some(def_id)) => Some((def_id.krate.as_u32(), def_id.index)),
|
let filter = match self.reverse_translate_def_id(def_id) {
|
||||||
Some(None) => return &[],
|
Some(def_id) => (def_id.krate.as_u32(), def_id.index),
|
||||||
None => None,
|
None => return &[],
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(filter) = filter {
|
|
||||||
if let Some(impls) = self.trait_impls.get(&filter) {
|
if let Some(impls) = self.trait_impls.get(&filter) {
|
||||||
tcx.arena.alloc_from_iter(
|
tcx.arena.alloc_from_iter(
|
||||||
impls.decode(self).map(|(idx, simplified_self_ty)| {
|
impls.decode(self).map(|(idx, simplified_self_ty)| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue