Skip to content

Commit faf8bed

Browse files
authored
Rollup merge of #80637 - LingMan:filter, r=oli-obk
Use Option::filter instead of open-coding it `@rustbot` modify labels +C-cleanup +T-compiler
2 parents 1c6593c + 203d502 commit faf8bed

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,18 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
4343
}
4444

4545
fn node_ty_contains_target(&mut self, hir_id: HirId) -> Option<Ty<'tcx>> {
46-
let ty_opt = self
47-
.infcx
46+
self.infcx
4847
.in_progress_typeck_results
49-
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id));
50-
match ty_opt {
51-
Some(ty) => {
52-
let ty = self.infcx.resolve_vars_if_possible(ty);
53-
if ty.walk().any(|inner| {
48+
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id))
49+
.map(|ty| self.infcx.resolve_vars_if_possible(ty))
50+
.filter(|ty| {
51+
ty.walk().any(|inner| {
5452
inner == self.target
5553
|| match (inner.unpack(), self.target.unpack()) {
5654
(GenericArgKind::Type(inner_ty), GenericArgKind::Type(target_ty)) => {
55+
use ty::{Infer, TyVar};
5756
match (inner_ty.kind(), target_ty.kind()) {
58-
(
59-
&ty::Infer(ty::TyVar(a_vid)),
60-
&ty::Infer(ty::TyVar(b_vid)),
61-
) => self
57+
(&Infer(TyVar(a_vid)), &Infer(TyVar(b_vid))) => self
6258
.infcx
6359
.inner
6460
.borrow_mut()
@@ -69,14 +65,8 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
6965
}
7066
_ => false,
7167
}
72-
}) {
73-
Some(ty)
74-
} else {
75-
None
76-
}
77-
}
78-
None => None,
79-
}
68+
})
69+
})
8070
}
8171
}
8272

0 commit comments

Comments
 (0)