-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvement for comparision against fn #59798
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
89eac91
Improvement for comparision against fn
rchaser53 aeb1e39
Merge remote-tracking branch 'origin/master'
rchaser53 cbcbd2c
create add_type_neq_err_label
rchaser53 199b0ba
improve error messages
rchaser53 d01ac0d
add the logic for when other_ty is FnDef
rchaser53 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could have another code branch for the case where both
ty
andother_ty
arefn
s, so that you can suggest calling both of them, if their return types are the same.