Skip to content

Don't suggest associated function call for associated const #104801

Closed
@compiler-errors

Description

@compiler-errors

Follow-up from this comment: #104422 (comment)

Given the following code:

fn main() {
    1i32.MAX()
}

The current output is:

error[E0599]: no method named `MAX` found for type `i32` in the current scope
 --> src/main.rs:2:10
  |
2 |     1i32.MAX()
  |     -----^^^--
  |     |    |
  |     |    this is an associated function, not a method
  |     help: use associated function syntax instead: `i32::MAX()`
  |
  = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
  = note: the candidate is defined in an impl for the type `i32`

For more information about this error, try `rustc --explain E0599`.

Ideally the output should not mention i32::MAX(), since that is an associated constant and not an associated function. However, it seems like some parts of method probing don't consider the associate item's kind when collecting candidates for diagnostics.

This should be investigated and fixed. While investigating, similar code should also be inspected and fixed if this can be triggered in other ways, for example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions