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

"the method rev() exists on usize" is misleading #90315

Closed
rcoh opened this issue Oct 26, 2021 · 0 comments · Fixed by #94893
Closed

"the method rev() exists on usize" is misleading #90315

rcoh opened this issue Oct 26, 2021 · 0 comments · Fixed by #94893
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rcoh
Copy link
Contributor

rcoh commented Oct 26, 2021

Given the following code:

  let arr = &[0,1,2,3];
  for i in 0..arr.len().rev() {
     // ...   
  }

The current output is:

error[E0599]: the method `rev` exists for type `usize`, but its trait bounds were not satisfied
 --> src/main.rs:5:25
  |
5 |   for i in 0..arr.len().rev() {
  |                         ^^^ method cannot be called on `usize` due to unsatisfied trait bounds
  |
  = note: the following trait bounds were not satisfied:
          `usize: Iterator`
          which is required by `&mut usize: Iterator

Ideally the output should look like:

// Minimal fix: remove misleading message:
Omit "the method rev exists for type usize." 

// Amazing fix:
  |
5 |   for i in 0..arr.len().rev() {
  |                         ^^^ method cannot be called on `usize` due to unsatisfied trait bounds
  |
  = note: the following trait bounds were not satisfied:
          `usize: Iterator`
          which is required by `&mut usize: Iterator
  = hint: (0..arr.len()) implements `Iterator`, perhaps you are missing parentheses? 

@rcoh rcoh 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 26, 2021
@estebank estebank added A-trait-system Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. labels Feb 13, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 24, 2022
…-issue-90315, r=Mark-Simulacrum

diagnostics: regression test for `<usize as Iterator>::rev`

Closes rust-lang#90315
@bors bors closed this as completed in 40c9bc0 Apr 24, 2022
@fmease fmease removed the A-trait-system Area: Trait system label Dec 21, 2024
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 D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. 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.

3 participants