Skip to content

rustc suggests unstable library method on stable #109177

Closed
@rillian

Description

@rillian

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.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.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