Skip to content

Generic type parameter deduction fails when used with associated constant defaults #44539

Closed
@mehcode

Description

@mehcode
Compiling playground v0.0.1 (file:///playground)
error[E0283]: type annotations required: cannot resolve `_: Foo`
  --> src/main.rs:12:14
   |
12 |   take_debug(Foo::BAR);
   |              ^^^^^^^^
   |
   = note: required by `Foo::BAR`

error: aborting due to previous error
use std::fmt;

trait Foo {
  const BAR: u8 = 32;
}

fn take_debug<F: fmt::Debug>(f: F) {
    println!("{:?}", f);
}

fn main() {
  // error
  take_debug(Foo::BAR);
}

https://play.rust-lang.org/?gist=b8610b4b6fa35a3c913434e43f18de1c&version=nightly
https://play.rust-lang.org/?gist=fb75d70964d26c4ce1f75ae98895edec&version=nightly


$ rustc --version
rustc 1.22.0-nightly (eba374fb2 2017-09-11)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.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