Skip to content

Commit

Permalink
Rollup merge of rust-lang#83113 - osa1:refactor_try_index_step, r=jon…
Browse files Browse the repository at this point in the history
…as-schievink

Minor refactoring in try_index_step

Merges `if-let` and `if x.is_some() { ... }` blocks
  • Loading branch information
Dylan-DPC authored Mar 15, 2021
2 parents 7fcef79 + 14038c7 commit 9360930
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 1 addition & 3 deletions compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_typeck/src/check/place_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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));
}
}

Expand Down

0 comments on commit 9360930

Please sign in to comment.