- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code:
fn main() {
    let slice = [1,2,3,4];
    let vec = vec![1,2,3,4];
    
    println!("{} {} {}", slice.count(), vec.count(), vec.as_slice().count());
}The current output is:
error[E0599]: the method `count` exists for array `[{integer}; 4]`, but its trait bounds were not satisfied
 --> src/main.rs:5:32
  |
5 |     println!("{} {} {}", slice.count(), vec.count(), vec.as_slice().count());
  |                                ^^^^^ method cannot be called on `[{integer}; 4]` due to unsatisfied trait bounds
  |
  = note: the following trait bounds were not satisfied:
          `[{integer}; 4]: Iterator`
          which is required by `&mut [{integer}; 4]: Iterator`
          `[{integer}]: Iterator`
          which is required by `&mut [{integer}]: Iterator`
(repeated 3 times with slight variations)
Ideally the output should:
- suggest using slice.len()instead ofslice.count()
This is a common error, particularly for new users, and when switching between iterators and vectors/slices/arrays.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.