Skip to content

Commit 5833f74

Browse files
committed
use if let Some(x) = .. instead of ...map(|x|) to conditionally run fns that return () (clippy::option_map_unit_fn)
1 parent b7795e1 commit 5833f74

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

compiler/rustc_mir_build/src/build/scope.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
616616
debug!("stmt_expr Break val block_context.push(SubExpr)");
617617
self.block_context.push(BlockFrame::SubExpr);
618618
unpack!(block = self.into(destination, dest_scope, block, value));
619-
dest_scope
620-
.map(|scope| self.unschedule_drop(scope, destination.as_local().unwrap()));
619+
if let Some(scope) = dest_scope {
620+
self.unschedule_drop(scope, destination.as_local().unwrap())
621+
};
621622
self.block_context.pop();
622623
} else {
623624
self.cfg.push_assign_unit(block, source_info, destination, self.hir.tcx())

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,31 +1448,30 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
14481448
});
14491449
};
14501450

1451-
typeck_results
1451+
if let Some(cause) = typeck_results
14521452
.generator_interior_types
14531453
.iter()
14541454
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| ty_matches(ty))
1455-
.map(|cause| {
1456-
// Check to see if any awaited expressions have the target type.
1457-
let from_awaited_ty = visitor
1458-
.awaits
1459-
.into_iter()
1460-
.map(|id| hir.expect_expr(id))
1461-
.find(|await_expr| {
1462-
let ty = typeck_results.expr_ty_adjusted(&await_expr);
1463-
debug!(
1464-
"maybe_note_obligation_cause_for_async_await: await_expr={:?}",
1465-
await_expr
1466-
);
1467-
ty_matches(ty)
1468-
})
1469-
.map(|expr| expr.span);
1470-
let ty::GeneratorInteriorTypeCause { span, scope_span, yield_span, expr, .. } =
1471-
cause;
1455+
{
1456+
// Check to see if any awaited expressions have the target type.
1457+
let from_awaited_ty = visitor
1458+
.awaits
1459+
.into_iter()
1460+
.map(|id| hir.expect_expr(id))
1461+
.find(|await_expr| {
1462+
let ty = typeck_results.expr_ty_adjusted(&await_expr);
1463+
debug!(
1464+
"maybe_note_obligation_cause_for_async_await: await_expr={:?}",
1465+
await_expr
1466+
);
1467+
ty_matches(ty)
1468+
})
1469+
.map(|expr| expr.span);
1470+
let ty::GeneratorInteriorTypeCause { span, scope_span, yield_span, expr, .. } = cause;
14721471

1473-
interior_or_upvar_span = Some(GeneratorInteriorOrUpvar::Interior(*span));
1474-
interior_extra_info = Some((*scope_span, *yield_span, *expr, from_awaited_ty));
1475-
});
1472+
interior_or_upvar_span = Some(GeneratorInteriorOrUpvar::Interior(*span));
1473+
interior_extra_info = Some((*scope_span, *yield_span, *expr, from_awaited_ty));
1474+
};
14761475

14771476
debug!(
14781477
"maybe_note_obligation_cause_for_async_await: interior_or_upvar={:?} \

0 commit comments

Comments
 (0)