Improvement for comparision against fn
This commit is contained in:
parent
4fb888bf04
commit
89eac91e05
5 changed files with 48 additions and 3 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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}`
|
||||
|
||||
|
|
|
|||
9
src/test/ui/issues/issue-59488.rs
Normal file
9
src/test/ui/issues/issue-59488.rs
Normal file
|
|
@ -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]
|
||||
}
|
||||
24
src/test/ui/issues/issue-59488.stderr
Normal file
24
src/test/ui/issues/issue-59488.stderr
Normal file
|
|
@ -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`.
|
||||
|
|
@ -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::<_>}`
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue