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

rustc suggests unstable library method on stable #109177

Closed
rillian opened this issue Mar 15, 2023 · 2 comments · Fixed by #109212
Closed

rustc suggests unstable library method on stable #109177

rillian opened this issue Mar 15, 2023 · 2 comments · Fixed by #109212
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rillian
Copy link
Contributor

rillian commented Mar 15, 2023

Code

fn main() {
    let v = vec![1,2,3,4];
    for pair in v.chunk(2) {
        println!("{}, {}", pair[0], pair[1]);
    }
}

Current output

error[E0599]: no method named `chunk` found for struct `Vec<{integer}>` in the current scope
 --> src/main.rs:3:19
  |
3 |     for pair in v.chunk(2) {
  |                   ^^^^^ help: there is a method with a similar name: `as_chunks`

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

Desired output

error[E0599]: no method named `chunk` found for struct `Vec<{integer}>` in the current scope
 --> src/main.rs:3:19
  |
3 |     for pair in v.chunk(2) {
  |                   ^^^^^ help: there is a method with a similar name: `chunks`

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

Rationale and extra context

It would be more helpful to suggest the chunks method for the typo rather than a nightly-only symbol which isn't actually available.

  1. Following the suggestion doesn't work.
  2. The chunks() method is actually available on a std::slice.
  3. The chunks() method has been stable since 1.0.0.
  4. I had trouble noticing the difference between .chunk() and .chuncks() and could have used the compiler's help.

Other cases

No response

Anything else?

Reproduced with 1.68.0 stable and 1.70 nightly.

@rillian rillian 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 Mar 15, 2023
@rillian
Copy link
Contributor Author

rillian commented Mar 15, 2023

cc @estebank

@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Mar 15, 2023
@Ezrashaw
Copy link
Contributor

@rustbot claim

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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. 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.

3 participants