Skip to content

Commit 62ae1fa

Browse files
authored
Rollup merge of #100945 - TaKO8Ki:add-missing-test-case-for-impl-generic-mismatch, r=Dylan-DPC
Add a missing test case for impl generic mismatch This suggestion use different span depending on whether the method has generics or not, so I added a test case about the method with some generics.
2 parents 0293780 + 56f9e29 commit 62ae1fa

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/test/ui/impl-trait/impl-generic-mismatch.rs

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ impl Bar for () {
1818
//~^ Error method `bar` has incompatible signature for trait
1919
}
2020

21+
trait Baz {
22+
fn baz<U: Debug, T: Debug>(&self, _: &U, _: &T);
23+
}
24+
25+
impl Baz for () {
26+
fn baz<T: Debug>(&self, _: &impl Debug, _: &T) { }
27+
//~^ Error method `baz` has incompatible signature for trait
28+
}
29+
2130
// With non-local trait (#49841):
2231

2332
use std::hash::{Hash, Hasher};

src/test/ui/impl-trait/impl-generic-mismatch.stderr

+16-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,22 @@ help: try changing the `impl Trait` argument to a generic parameter
2727
LL | fn bar<U: Debug>(&self, _: &U) { }
2828
| ++++++++++ ~
2929

30+
error[E0643]: method `baz` has incompatible signature for trait
31+
--> $DIR/impl-generic-mismatch.rs:26:33
32+
|
33+
LL | fn baz<U: Debug, T: Debug>(&self, _: &U, _: &T);
34+
| - declaration in trait here
35+
...
36+
LL | fn baz<T: Debug>(&self, _: &impl Debug, _: &T) { }
37+
| ^^^^^^^^^^ expected generic parameter, found `impl Trait`
38+
|
39+
help: try changing the `impl Trait` argument to a generic parameter
40+
|
41+
LL | fn baz<U: Debug, T: Debug>(&self, _: &T, _: &T) { }
42+
| ~~~~~~~~~~~~~~~~~~~~ ~
43+
3044
error[E0643]: method `hash` has incompatible signature for trait
31-
--> $DIR/impl-generic-mismatch.rs:28:33
45+
--> $DIR/impl-generic-mismatch.rs:37:33
3246
|
3347
LL | fn hash(&self, hasher: &mut impl Hasher) {}
3448
| ^^^^^^^^^^^ expected generic parameter, found `impl Trait`
@@ -38,6 +52,6 @@ LL | fn hash(&self, hasher: &mut impl Hasher) {}
3852
LL | fn hash<H: Hasher>(&self, state: &mut H);
3953
| - declaration in trait here
4054

41-
error: aborting due to 3 previous errors
55+
error: aborting due to 4 previous errors
4256

4357
For more information about this error, try `rustc --explain E0643`.

0 commit comments

Comments
 (0)