Skip to content
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

Profoundly unhelpful compiler error message when "mod" accidentally used as "%" #45560

Closed
mcolinj opened this issue Oct 26, 2017 · 4 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@mcolinj
Copy link

mcolinj commented Oct 26, 2017

error: Could not compile `leap`.
warning: build failed, waiting for other jobs to finish...
error[E0308]: mismatched types
 --> src/lib.rs:1:40
  |
1 |   pub fn is_leap_year(year: i32) -> bool {
  |  ________________________________________^
2 | |     if year mod 4 == 0 {
3 | |         true
4 | |     } else {
5 | |         false
6 | |     }
7 | | }
  | |_^ expected bool, found ()
  |
  = note: expected type `bool`
             found type `()`

error: aborting due to 2 previous errors

error: Could not compile `leap`.

@mcolinj mcolinj changed the title Profoundly unhelpful compiler error message when "mod" accidentally use as "%" Profoundly unhelpful compiler error message when "mod" accidentally used as "%" Oct 26, 2017
@scottmcm
Copy link
Member

Note that it also gives this as the first error:

error: expected `{`, found `mod`
 --> src/main.rs:2:13
  |
2 |     if year mod 4 == 0 {
  |             ^^^

@mcolinj
Copy link
Author

mcolinj commented Oct 26, 2017

Yes, thanks. I see that now that I've reproduced it. That first error scrolled off the screen so I did not see it! I'm a newbie at Rust Belt Rust today and my workshop instructor suggest I file this PR after seeing it. Not sure if it is reasonable to response to the "mod" command so out of place.

@kennytm kennytm added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 26, 2017
@scottmcm
Copy link
Member

scottmcm commented Oct 26, 2017

Thanks for filing! There's definitely opportunity for improvement here -- perhaps type errors should never be shown for methods whose bodies failed to parse, or something.

@TimNN TimNN added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Oct 31, 2017
@estebank
Copy link
Contributor

estebank commented Jan 15, 2018

@fixed in #46732. The compiler now only complains about mod and won't try to type check blocks that have had parse errors:

error: expected `{`, found `mod`
 --> src/main.rs:2:13
  |
2 |     if year mod 4 == 0 {
  |             ^^^

error: aborting due to previous error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

5 participants