]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #60051 - estebank:fn-sugg, r=davidtwco
authorbors <bors@rust-lang.org>
Thu, 18 Apr 2019 03:06:17 +0000 (03:06 +0000)
committerbors <bors@rust-lang.org>
Thu, 18 Apr 2019 03:06:17 +0000 (03:06 +0000)
Do not mention missing `PartialOrd` impl when involving uncalled fns

src/librustc_typeck/check/op.rs
src/test/ui/fn/fn-compare-mismatch.stderr
src/test/ui/issues/issue-59488.rs
src/test/ui/issues/issue-59488.stderr

index d2fe099e433f2ec4675989a20db8e99c00bbb5ed..b93ed2426b7038de8234774d12203962d54984dd 100644 (file)
@@ -332,8 +332,9 @@ fn check_overloaded_binop(&self,
                                 op.node.as_str(),
                                 lhs_ty);
 
+                            let mut involves_fn = false;
                             if !lhs_expr.span.eq(&rhs_expr.span) {
-                                self.add_type_neq_err_label(
+                                involves_fn |= self.add_type_neq_err_label(
                                     &mut err,
                                     lhs_expr.span,
                                     lhs_ty,
@@ -341,7 +342,7 @@ fn check_overloaded_binop(&self,
                                     op,
                                     is_assign
                                 );
-                                self.add_type_neq_err_label(
+                                involves_fn |= self.add_type_neq_err_label(
                                     &mut err,
                                     rhs_expr.span,
                                     rhs_ty,
@@ -410,7 +411,7 @@ fn check_overloaded_binop(&self,
                                         "`{}` might need a bound for `{}`",
                                         lhs_ty, missing_trait
                                     ));
-                                } else if !suggested_deref {
+                                } else if !suggested_deref && !involves_fn {
                                     err.note(&format!(
                                         "an implementation of `{}` might \
                                          be missing for `{}`",
@@ -429,6 +430,8 @@ fn check_overloaded_binop(&self,
         (lhs_ty, rhs_ty, return_ty)
     }
 
+    /// If one of the types is an uncalled function and calling it would yield the other type,
+    /// suggest calling the function. Returns wether a suggestion was given.
     fn add_type_neq_err_label(
         &self,
         err: &mut errors::DiagnosticBuilder<'_>,
@@ -437,7 +440,7 @@ fn add_type_neq_err_label(
         other_ty: Ty<'tcx>,
         op: hir::BinOp,
         is_assign: IsAssign,
-    ) {
+    ) -> bool /* did we suggest to call a function because of missing parenthesis? */ {
         err.span_label(span, ty.to_string());
         if let FnDef(def_id, _) = ty.sty {
             let source_map = self.tcx.sess.source_map();
@@ -481,8 +484,10 @@ fn add_type_neq_err_label(
                     variable_snippet,
                     applicability,
                 );
+                return true;
             }
         }
+        false
     }
 
     fn check_str_addition(
index 74fb00f8ac383329d54370d189482c387f06f874..c64070a2022d9d0dd13b9c123b9a87fdbbc5a1c0 100644 (file)
@@ -5,8 +5,6 @@ LL |     let x = f == g;
    |             - ^^ - fn() {main::g}
    |             |
    |             fn() {main::f}
-   |
-   = note: an implementation of `std::cmp::PartialEq` might be missing for `fn() {main::f}`
 help: you might have forgotten to call this function
    |
 LL |     let x = f() == g;
index 27cf16a821ffc3197b0cb95a13dad10616789cf8..d5fab0a6f9b267aeeb6e107524c5b7dc7cc556d8 100644 (file)
@@ -10,17 +10,17 @@ fn bar(a: i64) -> i64 {
 
 fn main() {
     foo > 12;
-    //~^ ERROR 12:9: 12:10: binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
-    //~| ERROR 12:11: 12:13: mismatched types [E0308]
+    //~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
+    //~| ERROR mismatched types [E0308]
 
     bar > 13;
-    //~^ ERROR 16:9: 16:10: binary operation `>` cannot be applied to type `fn(i64) -> i64 {bar}` [E0369]
-    //~| ERROR 16:11: 16:13: mismatched types [E0308]
+    //~^ ERROR binary operation `>` cannot be applied to type `fn(i64) -> i64 {bar}` [E0369]
+    //~| ERROR mismatched types [E0308]
 
     foo > foo;
-    //~^ ERROR 20:9: 20:10: binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
+    //~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
 
     foo > bar;
-    //~^ ERROR 23:9: 23:10: binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
-    //~| ERROR 23:11: 23:14: mismatched types [E0308]
+    //~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
+    //~| ERROR mismatched types [E0308]
 }
index b49f5e35f42265153e27c868cef4a6e8e2b41bfb..615adb36d330cebe5fa436802a54a4e2812be26e 100644 (file)
@@ -6,8 +6,6 @@ LL |     foo > 12;
    |     |
    |     fn() -> i32 {foo}
    |     help: you might have forgotten to call this function: `foo()`
-   |
-   = note: an implementation of `std::cmp::PartialOrd` might be missing for `fn() -> i32 {foo}`
 
 error[E0308]: mismatched types
   --> $DIR/issue-59488.rs:12:11
@@ -26,8 +24,6 @@ LL |     bar > 13;
    |     |
    |     fn(i64) -> i64 {bar}
    |     help: you might have forgotten to call this function: `bar( /* arguments */ )`
-   |
-   = note: an implementation of `std::cmp::PartialOrd` might be missing for `fn(i64) -> i64 {bar}`
 
 error[E0308]: mismatched types
   --> $DIR/issue-59488.rs:16:11
@@ -45,8 +41,6 @@ LL |     foo > foo;
    |     --- ^ --- fn() -> i32 {foo}
    |     |
    |     fn() -> i32 {foo}
-   |
-   = note: an implementation of `std::cmp::PartialOrd` might be missing for `fn() -> i32 {foo}`
 help: you might have forgotten to call this function
    |
 LL |     foo() > foo;