Skip to content

Commit 91bbb69

Browse files
committed
re-style check_expr_unop
1 parent 79f12eb commit 91bbb69

1 file changed

Lines changed: 22 additions & 32 deletions

File tree

  • compiler/rustc_hir_typeck/src

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -437,39 +437,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
437437
let oprnd_t = self.check_expr_with_expectation(oprnd, expected_inner);
438438

439439
if let Err(guar) = oprnd_t.error_reported() {
440-
Ty::new_error(tcx, guar)
441-
} else {
442-
let oprnd_t = self.structurally_resolve_type(expr.span, oprnd_t);
443-
match unop {
444-
hir::UnOp::Deref => {
445-
if let Some(ty) = self.lookup_derefing(expr, oprnd, oprnd_t) {
446-
ty
447-
} else {
448-
let mut err =
449-
self.dcx().create_err(CantDereference { span: expr.span, ty: oprnd_t });
450-
let sp = tcx.sess.source_map().start_point(expr.span).with_parent(None);
451-
if let Some(sp) =
452-
tcx.sess.psess.ambiguous_block_expr_parse.borrow().get(&sp)
453-
{
454-
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
455-
}
456-
Ty::new_error(tcx, err.emit())
457-
}
458-
}
459-
hir::UnOp::Not => {
460-
let result = self.check_user_unop(expr, oprnd_t, unop, expected_inner);
461-
// If it's builtin, we can reuse the type, this helps inference.
462-
if oprnd_t.is_integral() || *oprnd_t.kind() == ty::Bool {
463-
oprnd_t
464-
} else {
465-
result
466-
}
467-
}
468-
hir::UnOp::Neg => {
469-
let result = self.check_user_unop(expr, oprnd_t, unop, expected_inner);
470-
// If it's builtin, we can reuse the type, this helps inference.
471-
if oprnd_t.is_numeric() { oprnd_t } else { result }
440+
return Ty::new_error(tcx, guar);
441+
}
442+
443+
let oprnd_t = self.structurally_resolve_type(expr.span, oprnd_t);
444+
match unop {
445+
hir::UnOp::Deref => self.lookup_derefing(expr, oprnd, oprnd_t).unwrap_or_else(|| {
446+
let mut err =
447+
self.dcx().create_err(CantDereference { span: expr.span, ty: oprnd_t });
448+
let sp = tcx.sess.source_map().start_point(expr.span).with_parent(None);
449+
if let Some(sp) = tcx.sess.psess.ambiguous_block_expr_parse.borrow().get(&sp) {
450+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
472451
}
452+
Ty::new_error(tcx, err.emit())
453+
}),
454+
hir::UnOp::Not => {
455+
let result = self.check_user_unop(expr, oprnd_t, unop, expected_inner);
456+
// If it's builtin, we can reuse the type, this helps inference.
457+
if oprnd_t.is_integral() || *oprnd_t.kind() == ty::Bool { oprnd_t } else { result }
458+
}
459+
hir::UnOp::Neg => {
460+
let result = self.check_user_unop(expr, oprnd_t, unop, expected_inner);
461+
// If it's builtin, we can reuse the type, this helps inference.
462+
if oprnd_t.is_numeric() { oprnd_t } else { result }
473463
}
474464
}
475465
}

0 commit comments

Comments
 (0)