about summary refs log tree commit diff
diff options
context:
space:
mode:
authorrchaser53 <tayoshizawa29@gmail.com>2019-04-07 22:51:33 +0900
committerrchaser53 <tayoshizawa29@gmail.com>2019-04-07 23:15:35 +0900
commit89eac91e0576bbf81af4e10a8be47b935592a922 (patch)
tree7b750b6f7d183564c2161fab05186ff2462f4d11
parent4fb888bf04d2f1913e78e9eae51ac5695df1dc01 (diff)
downloadrust-89eac91e0576bbf81af4e10a8be47b935592a922.tar.gz
rust-89eac91e0576bbf81af4e10a8be47b935592a922.zip
Improvement for comparision against fn
-rw-r--r--src/librustc_typeck/check/op.rs10
-rw-r--r--src/test/ui/fn/fn-compare-mismatch.stderr7
-rw-r--r--src/test/ui/issues/issue-59488.rs9
-rw-r--r--src/test/ui/issues/issue-59488.stderr24
-rw-r--r--src/test/ui/parser/require-parens-for-chained-comparison.stderr1
5 files changed, 48 insertions, 3 deletions
diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs
index d6932094ddd..70c9d9ddee3 100644
--- a/src/librustc_typeck/check/op.rs
+++ b/src/librustc_typeck/check/op.rs
@@ -3,7 +3,7 @@
 use super::{FnCtxt, Needs};
 use super::method::MethodCallee;
 use rustc::ty::{self, Ty, TypeFoldable};
-use rustc::ty::TyKind::{Ref, Adt, Str, Uint, Never, Tuple, Char, Array};
+use rustc::ty::TyKind::{Ref, Adt, FnDef, Str, Uint, Never, Tuple, Char, Array};
 use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
 use rustc::infer::type_variable::TypeVariableOrigin;
 use errors::{self,Applicability};
@@ -334,9 +334,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
 
                             if !lhs_expr.span.eq(&rhs_expr.span) {
                                 err.span_label(lhs_expr.span, lhs_ty.to_string());
+                                if let FnDef(..) = lhs_ty.sty {
+                                    err.span_label(lhs_expr.span, "did you forget `()`?");
+                                }
+
                                 err.span_label(rhs_expr.span, rhs_ty.to_string());
+                                if let FnDef(..) = rhs_ty.sty {
+                                    err.span_label(rhs_expr.span, "did you forget `()`?");
+                                }
                             }
 
+
                             let mut suggested_deref = false;
                             if let Ref(_, mut rty, _) = lhs_ty.sty {
                                 if {
diff --git a/src/test/ui/fn/fn-compare-mismatch.stderr b/src/test/ui/fn/fn-compare-mismatch.stderr
index 07b93d9aae7..6f1155d597e 100644
--- a/src/test/ui/fn/fn-compare-mismatch.stderr
+++ b/src/test/ui/fn/fn-compare-mismatch.stderr
@@ -2,9 +2,12 @@ error[E0369]: binary operation `==` cannot be applied to type `fn() {main::f}`
   --> $DIR/fn-compare-mismatch.rs:4:15
    |
 LL |     let x = f == g;
-   |             - ^^ - fn() {main::g}
-   |             |
+   |             - ^^ -
+   |             |    |
+   |             |    fn() {main::g}
+   |             |    did you forget `()`?
    |             fn() {main::f}
+   |             did you forget `()`?
    |
    = note: an implementation of `std::cmp::PartialEq` might be missing for `fn() {main::f}`
 
diff --git a/src/test/ui/issues/issue-59488.rs b/src/test/ui/issues/issue-59488.rs
new file mode 100644
index 00000000000..937eb72fa22
--- /dev/null
+++ b/src/test/ui/issues/issue-59488.rs
@@ -0,0 +1,9 @@
+fn foo() -> i32 {
+    42
+}
+
+fn main() {
+    foo > 12;
+    //~^ ERROR 6:9: 6:10: binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
+    //~| ERROR 6:11: 6:13: mismatched types [E0308]
+}
diff --git a/src/test/ui/issues/issue-59488.stderr b/src/test/ui/issues/issue-59488.stderr
new file mode 100644
index 00000000000..7bd7700026c
--- /dev/null
+++ b/src/test/ui/issues/issue-59488.stderr
@@ -0,0 +1,24 @@
+error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
+  --> $DIR/issue-59488.rs:6:9
+   |
+LL |     foo > 12;
+   |     --- ^ -- {integer}
+   |     |
+   |     fn() -> i32 {foo}
+   |     did you forget `()`?
+   |
+   = note: an implementation of `std::cmp::PartialOrd` might be missing for `fn() -> i32 {foo}`
+
+error[E0308]: mismatched types
+  --> $DIR/issue-59488.rs:6:11
+   |
+LL |     foo > 12;
+   |           ^^ expected fn item, found integer
+   |
+   = note: expected type `fn() -> i32 {foo}`
+              found type `{integer}`
+
+error: aborting due to 2 previous errors
+
+Some errors occurred: E0308, E0369.
+For more information about an error, try `rustc --explain E0308`.
diff --git a/src/test/ui/parser/require-parens-for-chained-comparison.stderr b/src/test/ui/parser/require-parens-for-chained-comparison.stderr
index 8899b0d43cd..d44e2242cc2 100644
--- a/src/test/ui/parser/require-parens-for-chained-comparison.stderr
+++ b/src/test/ui/parser/require-parens-for-chained-comparison.stderr
@@ -44,6 +44,7 @@ LL |     f<X>();
    |     -^- X
    |     |
    |     fn() {f::<_>}
+   |     did you forget `()`?
    |
    = note: an implementation of `std::cmp::PartialOrd` might be missing for `fn() {f::<_>}`