Skip to content

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

Closed

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

Activity

  1. changed the title [-]Compile error when providing explicit generic arguments where impl Trait appears in bound of generic argument[/-] [+]Compile error when providing explicit generic arguments where impl Trait appears in bound of generic type[/+] on Nov 11, 2020
  2. jonas-schievink commented on Nov 11, 2020

    @jonas-schievink
    Contributor

    The error is intentional, as it would not be clear if/where its value can be specified by the caller (same reasoning as for impl Trait in argument position). The message could be improved though.

  3. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    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.
    and removed
    C-bugCategory: This is a bug.
    on Nov 11, 2020
  4. added
    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
    on Nov 14, 2020
  5. Dylan-DPC commented on Jan 1, 2025

    @Dylan-DPC
    Member

    Closing this as this code now compiles on stable & nightly

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 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