Skip to content

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

Closed
@mcolinj

Description

@mcolinj
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`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions