Skip to content

check_for_deref_method suggestion can still introduce a parse error #104379

Closed
@jruderman

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

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