- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code:
struct MyS;
impl MyS {
    const FOO: i32 = 1;
    fn foo() -> MyS {MyS}
}
fn main() {
    let x: i32 = MyS::foo;
    
    let y: i32 = i32::max - 42;
    let z: i32 = i32::max;
}The current output is:
error[E0308]: mismatched types
 --> src/main.rs:9:18
  |
9 |     let x: i32 = MyS::foo;
  |            ---   ^^^^^^^^ expected `i32`, found fn item
  |            |
  |            expected due to this
  |
  = note: expected type `i32`
          found fn item `fn() -> MyS {MyS::foo}`
error[E0369]: cannot subtract `{integer}` from `fn(i32, i32) -> i32 {<i32 as Ord>::max}`
  --> src/main.rs:11:27
   |
11 |     let y: i32 = i32::max - 42;
   |                  -------- ^ -- {integer}
   |                  |
   |                  fn(i32, i32) -> i32 {<i32 as Ord>::max}
error[E0308]: mismatched types
  --> src/main.rs:12:18
   |
12 |     let z: i32 = i32::max;
   |            ---   ^^^^^^^^ expected `i32`, found fn item
   |            |
   |            expected due to this
   |
   = note: expected type `i32`
           found fn item `fn(i32, i32) -> i32 {<i32 as Ord>::max}`
help: use parentheses to call this function
   |
12 |     let z: i32 = i32::max(...);
   |                          +++++
Ideally the output of both errors should mention that the MyS::MAX or i32::MAX constants exists if the type of the constant would solve the type issues.
help: use `MyS::FOO` to refer to the constant of type MyS
or
help: use `i32::MAX` to refer to the constant of type i32
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.