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

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

Closed
cecton opened this issue Mar 12, 2020 · 1 comment · Fixed by #116995
Labels
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.

Comments

@cecton
Copy link

cecton commented Mar 12, 2020

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
@cecton cecton added the C-bug Category: This is a bug. label Mar 12, 2020
@Centril Centril added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed C-bug Category: This is a bug. labels Mar 12, 2020
@estebank
Copy link
Contributor

Triage: no change.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 20, 2023
…rrors

Point at assoc fn definition on type param divergence

When the number of type parameters in the associated function of an impl and its trait differ, we now *always* point at the trait one, even if it comes from a foreign crate. When it is local, we point at the specific params, when it is foreign, we point at the whole associated item.

Fix rust-lang#69944.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 21, 2023
…rrors

Point at assoc fn definition on type param divergence

When the number of type parameters in the associated function of an impl and its trait differ, we now *always* point at the trait one, even if it comes from a foreign crate. When it is local, we point at the specific params, when it is foreign, we point at the whole associated item.

Fix rust-lang#69944.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 21, 2023
Rollup merge of rust-lang#116995 - estebank:issue-69944, r=compiler-errors

Point at assoc fn definition on type param divergence

When the number of type parameters in the associated function of an impl and its trait differ, we now *always* point at the trait one, even if it comes from a foreign crate. When it is local, we point at the specific params, when it is foreign, we point at the whole associated item.

Fix rust-lang#69944.
@bors bors closed this as completed in 939a224 Oct 21, 2023
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 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

Successfully merging a pull request may close this issue.

3 participants