Skip to content

impl Trait and explicit const arguments #61410

Closed
@varkor

Description

@varkor
// run-pass

#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash

trait Usizer {
    fn m(self) -> usize;
}

fn f<const N: usize>(u: impl Usizer) -> usize {
    N + u.m()
}

struct Usizable;

impl Usizer for Usizable {
    fn m(self) -> usize {
        16
    }
}

fn main() {
    assert_eq!(f::<4usize>(Usizable), 20usize);
}

results in:

error[E0282]: type annotations needed
  --> bug.rs:23:16
   |
23 |     assert_eq!(f::<4usize>(Usizable), 20usize);
   |                ^^^^^^^^^^^ cannot infer type for `fn(Usizable) -> usize {f::<Usizable, _: usize>}`

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`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`.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions