Auto merge of #59798 - rchaser53:issue-59488, r=estebank
Improvement for comparision against fn I try to add error message. related: https://github.com/rust-lang/rust/issues/59488
This commit is contained in:
commit
464473ab3b
4 changed files with 188 additions and 3 deletions
|
|
@ -7,6 +7,14 @@ LL | let x = f == 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;
|
||||
| ^^^
|
||||
help: you might have forgotten to call this function
|
||||
|
|
||||
LL | let x = f == g();
|
||||
| ^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/fn-compare-mismatch.rs:4:18
|
||||
|
|
|
|||
26
src/test/ui/issues/issue-59488.rs
Normal file
26
src/test/ui/issues/issue-59488.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// ignore-tidy-linelength
|
||||
|
||||
fn foo() -> i32 {
|
||||
42
|
||||
}
|
||||
|
||||
fn bar(a: i64) -> i64 {
|
||||
43
|
||||
}
|
||||
|
||||
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]
|
||||
|
||||
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]
|
||||
|
||||
foo > foo;
|
||||
//~^ ERROR 20:9: 20:10: 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]
|
||||
}
|
||||
81
src/test/ui/issues/issue-59488.stderr
Normal file
81
src/test/ui/issues/issue-59488.stderr
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
|
||||
--> $DIR/issue-59488.rs:12:9
|
||||
|
|
||||
LL | foo > 12;
|
||||
| --- ^ -- {integer}
|
||||
| |
|
||||
| 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
|
||||
|
|
||||
LL | foo > 12;
|
||||
| ^^ expected fn item, found integer
|
||||
|
|
||||
= note: expected type `fn() -> i32 {foo}`
|
||||
found type `i32`
|
||||
|
||||
error[E0369]: binary operation `>` cannot be applied to type `fn(i64) -> i64 {bar}`
|
||||
--> $DIR/issue-59488.rs:16:9
|
||||
|
|
||||
LL | bar > 13;
|
||||
| --- ^ -- {integer}
|
||||
| |
|
||||
| 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
|
||||
|
|
||||
LL | bar > 13;
|
||||
| ^^ expected fn item, found integer
|
||||
|
|
||||
= note: expected type `fn(i64) -> i64 {bar}`
|
||||
found type `i64`
|
||||
|
||||
error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
|
||||
--> $DIR/issue-59488.rs:20:9
|
||||
|
|
||||
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;
|
||||
| ^^^^^
|
||||
help: you might have forgotten to call this function
|
||||
|
|
||||
LL | foo > foo();
|
||||
| ^^^^^
|
||||
|
||||
error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
|
||||
--> $DIR/issue-59488.rs:23:9
|
||||
|
|
||||
LL | foo > bar;
|
||||
| --- ^ --- fn(i64) -> i64 {bar}
|
||||
| |
|
||||
| fn() -> i32 {foo}
|
||||
|
|
||||
= note: an implementation of `std::cmp::PartialOrd` might be missing for `fn() -> i32 {foo}`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-59488.rs:23:11
|
||||
|
|
||||
LL | foo > bar;
|
||||
| ^^^ expected fn item, found a different fn item
|
||||
|
|
||||
= note: expected type `fn() -> i32 {foo}`
|
||||
found type `fn(i64) -> i64 {bar}`
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
Some errors occurred: E0308, E0369.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue