Skip to content

Commit 8ec9b2a

Browse files
authored
Rollup merge of #83113 - osa1:refactor_try_index_step, r=jonas-schievink
Minor refactoring in try_index_step Merges `if-let` and `if x.is_some() { ... }` blocks
2 parents 194472c + 14038c7 commit 8ec9b2a

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

compiler/rustc_mir_build/src/build/expr/into.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
427427
block.unit()
428428
}
429429
ExprKind::Index { .. } | ExprKind::Deref { .. } | ExprKind::Field { .. } => {
430-
debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
430+
debug_assert_eq!(Category::of(&expr.kind), Some(Category::Place));
431431

432432
// Create a "fake" temporary variable so that we check that the
433433
// value is Sized. Usually, this is caught in type checking, but
@@ -436,8 +436,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
436436
this.local_decls.push(LocalDecl::new(expr.ty, expr.span));
437437
}
438438

439-
debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
440-
441439
let place = unpack!(block = this.as_place(block, expr));
442440
let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place));
443441
this.cfg.push_assign(block, source_info, destination, rvalue);

compiler/rustc_typeck/src/check/place_op.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
103103
let method =
104104
self.try_overloaded_place_op(expr.span, self_ty, &[input_ty], PlaceOp::Index);
105105

106-
let result = method.map(|ok| {
106+
if let Some(result) = method {
107107
debug!("try_index_step: success, using overloaded indexing");
108-
let method = self.register_infer_ok_obligations(ok);
108+
let method = self.register_infer_ok_obligations(result);
109109

110110
let mut adjustments = self.adjust_steps(autoderef);
111111
if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() {
@@ -128,10 +128,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
128128
self.apply_adjustments(base_expr, adjustments);
129129

130130
self.write_method_call(expr.hir_id, method);
131-
(input_ty, self.make_overloaded_place_return_type(method).ty)
132-
});
133-
if result.is_some() {
134-
return result;
131+
132+
return Some((input_ty, self.make_overloaded_place_return_type(method).ty));
135133
}
136134
}
137135

0 commit comments

Comments
 (0)