@@ -38,7 +38,8 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
38
38
impl_m_span : Span ,
39
39
impl_m_body_id : ast:: NodeId ,
40
40
trait_m : & ty:: Method < ' tcx > ,
41
- impl_trait_ref : & ty:: TraitRef < ' tcx > ) {
41
+ impl_trait_ref : & ty:: TraitRef < ' tcx > ,
42
+ trait_item_span : Option < Span > ) {
42
43
debug ! ( "compare_impl_method(impl_trait_ref={:?})" ,
43
44
impl_trait_ref) ;
44
45
@@ -97,14 +98,42 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
97
98
let num_impl_m_type_params = impl_m. generics . types . len ( ) ;
98
99
let num_trait_m_type_params = trait_m. generics . types . len ( ) ;
99
100
if num_impl_m_type_params != num_trait_m_type_params {
100
- span_err ! ( tcx. sess, impl_m_span, E0049 ,
101
+ let impl_m_node_id = tcx. map . as_local_node_id ( impl_m. def_id ) . unwrap ( ) ;
102
+ let span = match tcx. map . expect_impl_item ( impl_m_node_id) . node {
103
+ ImplItemKind :: Method ( ref impl_m_sig, _) => {
104
+ if impl_m_sig. generics . is_parameterized ( ) {
105
+ impl_m_sig. generics . span
106
+ } else {
107
+ impl_m_span
108
+ }
109
+ }
110
+ _ => bug ! ( "{:?} is not a method" , impl_m)
111
+ } ;
112
+
113
+ struct_span_err ! ( tcx. sess, span, E0049 ,
101
114
"method `{}` has {} type parameter{} \
102
115
but its trait declaration has {} type parameter{}",
103
116
trait_m. name,
104
117
num_impl_m_type_params,
105
118
if num_impl_m_type_params == 1 { "" } else { "s" } ,
106
119
num_trait_m_type_params,
107
- if num_trait_m_type_params == 1 { "" } else { "s" } ) ;
120
+ if num_trait_m_type_params == 1 { "" } else { "s" } )
121
+ . span_label ( trait_item_span. unwrap ( ) ,
122
+ & format ! ( "expected {}" ,
123
+ & if num_trait_m_type_params != 1 {
124
+ format!( "{} type parameters" ,
125
+ num_trait_m_type_params)
126
+ } else {
127
+ format!( "{} type parameter" ,
128
+ num_trait_m_type_params)
129
+ } ) )
130
+ . span_label ( span, & format ! ( "found {}" ,
131
+ & if num_impl_m_type_params != 1 {
132
+ format!( "{} type parameters" , num_impl_m_type_params)
133
+ } else {
134
+ format!( "1 type parameter" )
135
+ } ) )
136
+ . emit ( ) ;
108
137
return ;
109
138
}
110
139
0 commit comments