Skip to content

Compile error when providing explicit generic arguments where impl Trait appears in bound of generic type #78936

Closed
@haileys

Description

@haileys

I tried this code:

fn example<T: FromStr<Err = impl Debug>>() {
    todo!();
}

fn main() {
    example::<usize>();
}

I expected this to compile, however I received this error instead:

error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position
 --> x.rs:9:15
  |
9 |     example::<usize>();
  |               ^^^^^ explicit generic argument not allowed

This error is unexpected, because impl Debug is not used in the argument position and is instead part of a trait bound on a named type parameter.

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (cf9cf7c92 2020-11-10)
binary: rustc
commit-hash: cf9cf7c923eb01146971429044f216a3ca905e06
commit-date: 2020-11-10
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-enhancementCategory: An issue proposing an enhancement or a PR with one.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