Skip to content

check_for_deref_method suggestion can still introduce a parse error #104379

Closed

Description

@jruderman

This is a variant of #103271 that wasn't fixed by #103675.

Given the following code (playground):

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

The current output is:

warning: unnecessary parentheses around type
 --> epi.rs:2:19
  |
2 |     let length = <(&[u32])>::len;
  |                   ^      ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
2 -     let length = <(&[u32])>::len;
2 +     let length = <&[u32]>::len;
  |

error[E0599]: the function or associated item `len` exists for reference `&[u32]`, but its trait bounds were not satisfied
 --> epi.rs:2:30
  |
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;
  |                    ~~~~~~~

The suggestion isn't quite right, because introducing angle brackets here (already within angle brackets) produces a parse error.

Version

rustc 1.67.0-nightly (6284998a2 2022-11-12)
binary: rustc
commit-hash: 6284998a2677d7e3e8420db783f3aa4fd80d7423
commit-date: 2022-11-12
host: x86_64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4

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 Nov 13, 2022
  2. lyming2007 commented on Nov 14, 2022

    @lyming2007

    @rustbot claim

  3. added a commit that references this issue on Nov 19, 2022
    e86f184
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