Skip to content

check_for_deref_method suggestion introduces a parse error #103271

Description

@jruderman

Given the following code (playground):

fn main() {
    let length = <&[u32]>::len;
    assert_eq!(length(&[1,3]), 2);
}

The current output is:

error[E0599]: the function or associated item `len` exists for reference `&[u32]`, but its trait bounds were not satisfied
 --> src/main.rs:2:28
  |
2 |     let length = <&[u32]>::len;
  |                            ^^^ function or associated item cannot be called on `&[u32]` due to unsatisfied trait bounds
  |
  = note: the following trait bounds were not satisfied:
          `&[u32]: ExactSizeIterator`
          which is required by `&mut &[u32]: ExactSizeIterator`
help: the function `len` is implemented on `[u32]`
  |
2 |     let length = <<[u32]>>::len;
  |                   ~~~~~~~

This suggestion is on the right track, but unfortunately it introduces a parse error. It should be:

help: the function `len` is implemented on `[u32]`
  |
2 |     let length = <[u32]>::len;
  |                   ~~~~~

This suggestion is in check_for_deref_method. It suggests adding <> around the type because the type is a slice, but I already have <> in my program (and the span doesn't include the existing <>).

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 19, 2022
  2. lyming2007 commented on Oct 20, 2022

    @lyming2007

    @rustbot claim

  3. added a commit that references this issue on Nov 3, 2022
    af60769
  4. added a commit that references this issue on Nov 8, 2022
    c703763
  5. added a commit that references this issue on Nov 10, 2022
    c729acb
  6. added a commit that references this issue on Nov 10, 2022
    f916022
  7. added a commit that references this issue on Jan 6, 2023
    b3bf6b6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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