Rollup merge of #80637 - LingMan:filter, r=oli-obk

Use Option::filter instead of open-coding it

`@rustbot` modify labels +C-cleanup +T-compiler
This commit is contained in:
Yuki Okushi 2021-01-05 09:52:42 +09:00 committed by GitHub
commit faf8beddef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,22 +43,18 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
} }
fn node_ty_contains_target(&mut self, hir_id: HirId) -> Option<Ty<'tcx>> { fn node_ty_contains_target(&mut self, hir_id: HirId) -> Option<Ty<'tcx>> {
let ty_opt = self self.infcx
.infcx
.in_progress_typeck_results .in_progress_typeck_results
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id)); .and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id))
match ty_opt { .map(|ty| self.infcx.resolve_vars_if_possible(ty))
Some(ty) => { .filter(|ty| {
let ty = self.infcx.resolve_vars_if_possible(ty); ty.walk().any(|inner| {
if ty.walk().any(|inner| {
inner == self.target inner == self.target
|| match (inner.unpack(), self.target.unpack()) { || match (inner.unpack(), self.target.unpack()) {
(GenericArgKind::Type(inner_ty), GenericArgKind::Type(target_ty)) => { (GenericArgKind::Type(inner_ty), GenericArgKind::Type(target_ty)) => {
use ty::{Infer, TyVar};
match (inner_ty.kind(), target_ty.kind()) { match (inner_ty.kind(), target_ty.kind()) {
( (&Infer(TyVar(a_vid)), &Infer(TyVar(b_vid))) => self
&ty::Infer(ty::TyVar(a_vid)),
&ty::Infer(ty::TyVar(b_vid)),
) => self
.infcx .infcx
.inner .inner
.borrow_mut() .borrow_mut()
@ -69,14 +65,8 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
} }
_ => false, _ => false,
} }
}) { })
Some(ty) })
} else {
None
}
}
None => None,
}
} }
} }