Skip to content

unsatisfied trait bound uses _ for unevaluated constants #82934

Closed
@shepmaster

Description

@shepmaster

Given the following code:

#![allow(incomplete_features)]
#![feature(const_generics, const_evaluatable_checked)]

use arrayvec::ArrayVec; // 0.5.2

fn append<T, const N: usize>(start: [T; N], v: T) -> [T; N + 1] {
    let xs = ArrayVec::new();
    for _ in 0..N {
        xs.push(v);
    }
    xs.push(v);
    match xs.into_inner() {
        Ok(xs) => xs,
        _ => unreachable!()
    }
}

The current output is:

error[E0283]: type annotations needed for `ArrayVec<[T; _]>`
 --> src/lib.rs:7:14
  |
7 |     let xs = ArrayVec::new();
  |         --   ^^^^^^^^^^^^^ cannot infer type for array `[T; _]`
  |         |
  |         consider giving `xs` the explicit type `ArrayVec<[T; _]>`, where the type parameter `[T; _]` is specified
  |
  = note: cannot satisfy `[T; _]: Array`
  = note: required by `ArrayVec::<A>::new`

Ideally the output should:

  1. Not tell me to add a type when that's not the real problem.
  2. Not tell me to add a type after I add one and it doesn't solve the problem.
  3. Focus on the fact that the trait bound isn't satisfied for arbitrary N.
  • 1.52.0-nightly (2021-03-07 234781a)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsF-generic_const_exprs`#![feature(generic_const_exprs)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.const-generics-bad-diagnosticsAn error is correctly emitted, but is confusing, for `min_const_generics`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions