]> git.lizzy.rs Git - rust.git/commitdiff
Improvement for comparision against fn
authorrchaser53 <tayoshizawa29@gmail.com>
Sun, 7 Apr 2019 13:51:33 +0000 (22:51 +0900)
committerrchaser53 <tayoshizawa29@gmail.com>
Sun, 7 Apr 2019 14:15:35 +0000 (23:15 +0900)
src/librustc_typeck/check/op.rs
src/test/ui/fn/fn-compare-mismatch.stderr
src/test/ui/issues/issue-59488.rs [new file with mode: 0644]
src/test/ui/issues/issue-59488.stderr [new file with mode: 0644]
src/test/ui/parser/require-parens-for-chained-comparison.stderr

index d6932094dddb6000b4761dc8f5258030f3d1ec0a..70c9d9ddee3d413a4705acccf38d6682f16921f4 100644 (file)
@@ -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 @@ fn check_overloaded_binop(&self,
 
                             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 {
index 07b93d9aae7ed6302a16e1a000fc369a03ca8881..6f1155d597e628bf1d0ab28d3f2b4aa6b4850df4 100644 (file)
@@ -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 (file)
index 0000000..937eb72
--- /dev/null
@@ -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 (file)
index 0000000..7bd7700
--- /dev/null
@@ -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`.
index 8899b0d43cd8bb31e3d646622556e783fb15461a..d44e2242cc23f23cf3cb5ce4e98a574f00eec0d2 100644 (file)
@@ -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::<_>}`