Skip to content

suggest_call_as_method in HIR type check hints incorrect code when dealing with macros #114131

Closed
@mrnossiom

Description

@mrnossiom

Code

fn main() {
    let hello = len(vec![]);
}

Current output

error[E0425]: cannot find function `len` in this scope
 --> src/main.rs:2:17
  |
2 |     let hello = len(vec![]);
  |                 ^^^ not found in this scope
  |
help: use the `.` operator to call the method `len` on `&Vec<_>`
 --> /home/milomoisson/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/macros.rs:44:36

44-         $crate::__rust_force_expr!($crate::vec::Vec::new())
44+         $crate::__rust_force_expr!(.len())
  |

For more information about this error, try `rustc --explain E0425`.
error: could not compile `rustc-wrong-hint-repro` (bin "rustc-wrong-hint-repro") due to previous error

Desired output

error[E0425]: cannot find function `len` in this scope
 --> src/main.rs:2:17
  |
2 |     let hello = len(vec![]);
  |                 ^^^ not found in this scope
  |
help: use the `.` operator to call the method `len` on `&Vec<_>`
 --> /home/milomoisson/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/macros.rs:44:36

44-         len(vec![])
44+         vec![].len()
  |

For more information about this error, try `rustc --explain E0425`.
error: could not compile `rustc-wrong-hint-repro` (bin "rustc-wrong-hint-repro") due to previous error

Rationale and extra context

No response

Other cases

No response

Anything else?

rustc help hint with color:
image

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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