Skip to content

Suggest items be borrowed in for i in items[x..] #87994

Closed

Description

@Nicholas-Baron

Given the following code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5bb0aaa179979e54df877b3aafe9f507

use std::fmt::Display;

fn pretty_list(v: &Vec<impl Display>){
    print!("{}", v[0]);
    for item in v[1..] {
        print!(", {}", item);
    }
}

fn main(){
    let data = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
    pretty_list(&data);
}

The current output is:

error[E0277]: the size for values of type `[impl Display]` cannot be known at compilation time
 --> src/main.rs:5:17
  |
5 |     for item in v[1..] {
  |                 ^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `[impl Display]`
  = note: required because of the requirements on the impl of `IntoIterator` for `[impl Display]`
  = note: required by `into_iter`

error[E0277]: `[impl Display]` is not an iterator
 --> src/main.rs:5:17
  |
5 |     for item in v[1..] {
  |                 ^^^^^^ `[impl Display]` is not an iterator
  |
  = help: the trait `Iterator` is not implemented for `[impl Display]`
  = note: required because of the requirements on the impl of `IntoIterator` for `[impl Display]`
  = note: required by `into_iter`

error: aborting due to 2 previous errors

Ideally, the output should note that &v[1..] is a possible solution to these errors.

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Aug 13, 2021
  2. Nicholas-Baron commented on Aug 13, 2021

    @Nicholas-Baron
    ContributorAuthor

    @rustbot label: +D-newcomer-roadblock.

  3. added
    D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.
    on Aug 13, 2021
  4. added a commit that references this issue on Sep 2, 2021
    733bdd0
  5. added a commit that references this issue on Sep 9, 2021
    2471041
  6. added a commit that references this issue on Sep 10, 2021
    257f5ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-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