Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
haileys opened this issue Nov 11, 2020 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@haileys
Copy link
Contributor

haileys commented Nov 11, 2020

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
@haileys haileys added the C-bug Category: This is a bug. label Nov 11, 2020
@haileys haileys 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 Nov 11, 2020
@jonas-schievink
Copy link
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.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Nov 11, 2020
@estebank estebank added the A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. label Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants