diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-03-15 16:22:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-15 16:22:56 +0100 |
| commit | 8ec9b2a0acc5cde19236d777cb197d19f863bd8a (patch) | |
| tree | 28d51f8884a11ca5f1b1401890fdc9cb65008ad6 | |
| parent | 194472c9e366ecf4aff77de50d8fdc26cf94c74c (diff) | |
| parent | 14038c7df25d38b2f5b6790604374e1a33a01fe5 (diff) | |
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
| -rw-r--r-- | compiler/rustc_mir_build/src/build/expr/into.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/check/place_op.rs | 10 |
2 files changed, 5 insertions, 9 deletions
diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index 47f75825fb6..a2adbdddc40 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -427,7 +427,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.unit() } ExprKind::Index { .. } | ExprKind::Deref { .. } | ExprKind::Field { .. } => { - debug_assert!(Category::of(&expr.kind) == Some(Category::Place)); + debug_assert_eq!(Category::of(&expr.kind), Some(Category::Place)); // Create a "fake" temporary variable so that we check that the // value is Sized. Usually, this is caught in type checking, but @@ -436,8 +436,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { this.local_decls.push(LocalDecl::new(expr.ty, expr.span)); } - debug_assert!(Category::of(&expr.kind) == Some(Category::Place)); - let place = unpack!(block = this.as_place(block, expr)); let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place)); this.cfg.push_assign(block, source_info, destination, rvalue); diff --git a/compiler/rustc_typeck/src/check/place_op.rs b/compiler/rustc_typeck/src/check/place_op.rs index 254e41706f9..5bd385107ca 100644 --- a/compiler/rustc_typeck/src/check/place_op.rs +++ b/compiler/rustc_typeck/src/check/place_op.rs @@ -103,9 +103,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let method = self.try_overloaded_place_op(expr.span, self_ty, &[input_ty], PlaceOp::Index); - let result = method.map(|ok| { + if let Some(result) = method { debug!("try_index_step: success, using overloaded indexing"); - let method = self.register_infer_ok_obligations(ok); + let method = self.register_infer_ok_obligations(result); let mut adjustments = self.adjust_steps(autoderef); if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() { @@ -128,10 +128,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.apply_adjustments(base_expr, adjustments); self.write_method_call(expr.hir_id, method); - (input_ty, self.make_overloaded_place_return_type(method).ty) - }); - if result.is_some() { - return result; + + return Some((input_ty, self.make_overloaded_place_return_type(method).ty)); } } |
