Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

check_for_deref_method suggestion introduces a parse error #103271

Closed
jruderman opened this issue Oct 19, 2022 · 1 comment · Fixed by #103675
Closed

check_for_deref_method suggestion introduces a parse error #103271

jruderman opened this issue Oct 19, 2022 · 1 comment · Fixed by #103675
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 Oct 19, 2022

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 <>).

@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 Oct 19, 2022
@lyming2007
Copy link

@rustbot claim

lyming2007 pushed a commit to lyming2007/rust that referenced this issue Nov 2, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Nov 3, 2022
…1-dead

remove redundent "<>" for ty::Slice with reference type

this fix rust-lang#103271
lyming2007 pushed a commit to lyming2007/rust that referenced this issue Nov 8, 2022
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Nov 8, 2022
…1-dead

remove redundent "<>" for ty::Slice with reference type

this fix rust-lang#103271
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 10, 2022
…1-dead

remove redundent "<>" for ty::Slice with reference type

this fix rust-lang#103271
compiler-errors added a commit to compiler-errors/rust that referenced this issue Nov 10, 2022
…1-dead

remove redundent "<>" for ty::Slice with reference type

this fix rust-lang#103271
@bors bors closed this as completed in 0b6934d Nov 10, 2022
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
…1-dead

remove redundent "<>" for ty::Slice with reference type

this fix rust-lang#103271
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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