Skip to content

Commit 46fcf1c

Browse files
committedNov 6, 2018
Use trait impl method span when type param mismatch is due to impl Trait
1 parent ca4fa6f commit 46fcf1c

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
 

‎src/librustc_typeck/check/compare_method.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,9 @@ fn compare_number_of_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
595595
if num_impl_m_type_params != num_trait_m_type_params {
596596
let impl_m_node_id = tcx.hir.as_local_node_id(impl_m.def_id).unwrap();
597597
let impl_m_item = tcx.hir.expect_impl_item(impl_m_node_id);
598-
let span = if impl_m_item.generics.params.is_empty() {
598+
let span = if impl_m_item.generics.params.is_empty()
599+
|| impl_m_item.generics.span.is_dummy() // impl Trait in argument position (#55374)
600+
{
599601
impl_m_span
600602
} else {
601603
impl_m_item.generics.span
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait Foo {
2+
type T;
3+
fn foo(&self, t: Self::T);
4+
//~^ NOTE expected 0 type parameters
5+
}
6+
7+
impl Foo for u32 {
8+
type T = ();
9+
10+
fn foo(&self, t: impl Clone) {}
11+
//~^ ERROR method `foo` has 1 type parameter but its trait declaration has 0 type parameters
12+
//~| NOTE found 1 type parameter
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0049]: method `foo` has 1 type parameter but its trait declaration has 0 type parameters
2+
--> $DIR/type-arg-mismatch-due-to-impl-trait.rs:10:5
3+
|
4+
LL | fn foo(&self, t: Self::T);
5+
| -------------------------- expected 0 type parameters
6+
...
7+
LL | fn foo(&self, t: impl Clone) {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found 1 type parameter
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0049`.

0 commit comments

Comments
 (0)