Skip to content

check_for_deref_method suggestion can still introduce a parse error #104379

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
jruderman opened this issue Nov 13, 2022 · 1 comment · Fixed by #104497
Closed

check_for_deref_method suggestion can still introduce a parse error #104379

jruderman opened this issue Nov 13, 2022 · 1 comment · Fixed by #104497
Assignees
Labels
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.

Comments

@jruderman
Copy link
Contributor

jruderman commented Nov 13, 2022

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
@jruderman jruderman 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 Nov 13, 2022
@lyming2007
Copy link

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 19, 2022
…1-dead

detect () to avoid redundant <> suggestion for type

fix rust-lang#104379
@bors bors closed this as completed in 867582e Nov 19, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants