Skip to content

Missing "impl Trait introduces an implicit type parameter" when the trait comes from another crate #69944

Closed
@cecton

Description

When a trait has a method that has type parameters (fn foo<T>()) and implicit type parameters (fn foo(x: impl Clone)), if you impl the trait, the compiler gives the error:

error[E0049]: method `foo` has 2 type parameters but its trait declaration has 3 type parameters
  --> crate1/src/main.rs:10:12
   |
4  |     fn foo<A, B>(x: u32, y: impl Debug);
   |            -  -             ----------
   |            |                |
   |            |                `impl Trait` introduces an implicit type parameter
   |            expected 3 type parameters
...
10 |     fn foo<A, B>(x: u32, y: u32) {
   |            ^  ^
   |            |
   |            found 2 type parameters

This is fine but if the trait comes from another crate, the compiler will just say:

error[E0049]: method `foo` has 2 type parameters but its trait declaration has 3 type parameters
 --> crate1/src/main.rs:6:12
  |
6 |     fn foo<A, B>(x: u32, y: u32) {
  |            ^  ^
  |            |
  |            found 2 type parameters, expected 3

Here is a repository with this sample code: https://github.com/cecton/rust-type-param-error

I expected to see this happen: it would be great to see that there are implicit type parameters even if it comes from another crate or at least a warning.

Instead, this happened: I see that there should be 3 type parameters and I provided 2 but if I look at the code I see 2 type parameters, not 3. It was not obvious to me that the impl in parameter was introducing a type parameter.

Meta

rustc --version --verbose:

rustc 1.43.0-nightly (158127853 2020-03-10)
binary: rustc
commit-hash: 15812785344d913d779d9738fe3cca8de56f71d5
commit-date: 2020-03-10
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-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