Skip to content

Commit cbcbd2c

Browse files
committed
create add_type_neq_err_label
1 parent aeb1e39 commit cbcbd2c

File tree

1 file changed

+14
-10
lines changed
  • src/librustc_typeck/check

1 file changed

+14
-10
lines changed

src/librustc_typeck/check/op.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,18 +333,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
333333
lhs_ty);
334334

335335
if !lhs_expr.span.eq(&rhs_expr.span) {
336-
err.span_label(lhs_expr.span, lhs_ty.to_string());
337-
if let FnDef(..) = lhs_ty.sty {
338-
err.span_label(lhs_expr.span, "did you forget `()`?");
339-
}
340-
341-
err.span_label(rhs_expr.span, rhs_ty.to_string());
342-
if let FnDef(..) = rhs_ty.sty {
343-
err.span_label(rhs_expr.span, "did you forget `()`?");
344-
}
336+
self.add_type_neq_err_label(&mut err, lhs_expr.span, lhs_ty);
337+
self.add_type_neq_err_label(&mut err, rhs_expr.span, rhs_ty);
345338
}
346339

347-
348340
let mut suggested_deref = false;
349341
if let Ref(_, mut rty, _) = lhs_ty.sty {
350342
if {
@@ -423,6 +415,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
423415
(lhs_ty, rhs_ty, return_ty)
424416
}
425417

418+
fn add_type_neq_err_label(
419+
&self,
420+
err: &mut errors::DiagnosticBuilder<'_>,
421+
span: Span,
422+
ty: Ty<'tcx>,
423+
) {
424+
err.span_label(span, ty.to_string());
425+
if let FnDef(..) = ty.sty {
426+
err.span_label(span, "did you forget `()`?");
427+
}
428+
}
429+
426430
fn check_str_addition(
427431
&self,
428432
expr: &'gcx hir::Expr,

0 commit comments

Comments
 (0)