Uh oh!
There was an error while loading. Please reload this page.
Use Option::filter instead of open-coding it - #80637
Conversation
rust-highfive
commented
Jan 3, 2021
r? @estebank (rust-highfive has picked a reviewer for you, use r? to override) |
Uh oh!
There was an error while loading. Please reload this page.
rust-log-analyzer
commented
Jan 3, 2021
The job Click to see the possible cause of the failure (guessed by this bot) |
rust-log-analyzer
commented
Jan 3, 2021
The job Click to see the possible cause of the failure (guessed by this bot) |
LingMan
commented
Jan 3, 2021
Turned the call to |
oli-obk
commented
Jan 4, 2021
Not sure if this is better or worse, but the first two method calls made me reach for the let typeck_results = self.infcx.in_progress_typeck_results?;let ty = typeck_results.borrow().node_type_opt(hir_id)?;let ty = self.infcx.resolve_vars_if_possible(ty);for inner in ty.walk(){if inner == self.target{returnSome(ty);}ifletGenericArgKind::Type(inner_ty) = inner.unpack(){iflet ty::Infer(ty::TyVar(a_vid)) = inner_ty.kind(){ifletGenericArgKind::Type(target_ty) = self.target.unpack(){iflet ty::Infer(ty::TyVar(b_vid)) = target_ty.kind(){ifself.infcx.inner.borrow_mut().type_variables().sub_unified(a_vid, b_vid){returnSome(ty);}}}}}}Nonea bit much nesting, but there are no helper methods returning options that could be used here. Maybe we need to add them? Anyway, the diff lgtm as it is, so let me know if you want to merge it or iterate some more. r? @oli-obk |
jyn514
commented
Jan 4, 2021
This looks like a good candidate for |
LingMan
commented
Jan 4, 2021
Personally I'm a fan of method chaining and would like to keep that intact. Those Some helper to do fnnode_ty_contains_target(&mutself,hir_id:HirId) -> Option<Ty<'tcx>>{self.infcx.in_progress_typeck_results.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id)).map(|ty| self.infcx.resolve_vars_if_possible(ty)).filter(|ty| {
ty.walk().any(|inner| {if inner == self.target{returntrue;}let avid = Some(inner).if_let(GenericArgKind::Type(inner_ty), |inner| inner.unpack()).if_let(ty::Infer(ty::TyVar(a_vid)), |inner_ty| inner_ty.kind());let bvid = Some(self.target).if_let(GenericArgKind::Type(target_ty), |target| target.unpack()).if_let(ty::Infer(ty::TyVar(b_vid)), |target_ty| target_ty.kind());
avid.zip(bvid).map_or(false, |(avid, bvid)| {self.infcx.inner.borrow_mut().type_variables().sub_unified(a_vid, b_vid)})})})}For now I'd like to merge this as is, but it's certainly a spot for a followup if/when a fitting helper becomes available. |
oli-obk
commented
Jan 4, 2021
@bors r+ rollup |
bors
commented
Jan 4, 2021
📌 Commit 203d502 has been approved by |
Rollup of 12 pull requests Successful merges: - rust-lang#80442 (Mention Arc::make_mut and Rc::make_mut in the documentation of Cow) - rust-lang#80533 (bootstrap: clippy fixes) - rust-lang#80538 (Add check for `[T;N]`/`usize` mismatch in astconv) - rust-lang#80612 (Remove reverted change from relnotes) - rust-lang#80627 (Builder: Warn if test file does not exist) - rust-lang#80637 (Use Option::filter instead of open-coding it) - rust-lang#80643 (Move variable into the only branch where it is relevant) - rust-lang#80656 (Fixed documentation error for `std::hint::spin_loop`) - rust-lang#80666 (Fix missing link for "fully qualified syntax") - rust-lang#80672 (./x.py clippy: allow the most noisy lints) - rust-lang#80677 (doc -- list edit for consistency) - rust-lang#80696 (make sure that promoteds which fail to evaluate in dead const code behave correctly) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
@rustbot modify labels +C-cleanup +T-compiler