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

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

Closed
mrnossiom opened this issue Jul 27, 2023 · 0 comments · Fixed by #114138
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mrnossiom
Copy link
Contributor

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

@mrnossiom mrnossiom added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 27, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 27, 2023
@compiler-errors compiler-errors self-assigned this Jul 27, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 28, 2023
…ethod-sugg, r=estebank

Adjust spans correctly for fn -> method suggestion

Fixes rust-lang#114131
@bors bors closed this as completed in 3aa8da1 Jul 29, 2023
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 29, 2023
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants