@@ -24,6 +24,8 @@ use astconv::{ast_conv, ty_of_fn_decl, ty_of_arg, ast_ty_to_ty};
24
24
use ast_util:: trait_method_to_ty_method;
25
25
use rscope:: * ;
26
26
use ty:: { FnTyBase , FnMeta , FnSig } ;
27
+ use util:: common:: pluralize;
28
+ use util:: ppaux:: bound_to_str;
27
29
28
30
fn collect_item_types ( ccx : @crate_ctxt , crate : @ast:: crate ) {
29
31
@@ -263,9 +265,13 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span,
263
265
self type", tcx. sess. str_of( impl_m. ident) ) ) ;
264
266
}
265
267
266
- if impl_m. tps != trait_m. tps {
267
- tcx. sess . span_err ( sp, ~"method `" + tcx. sess . str_of ( trait_m. ident ) +
268
- ~"` has an incompatible set of type parameters") ;
268
+ if impl_m. tps . len ( ) != trait_m. tps . len ( ) {
269
+ tcx. sess . span_err ( sp, #fmt ( "method `%s` \
270
+ has %u type %s, but its trait declaration has %u type %s",
271
+ tcx. sess . str_of ( trait_m. ident ) , impl_m. tps . len ( ) ,
272
+ pluralize ( impl_m. tps . len ( ) , ~"parameter") ,
273
+ trait_m. tps . len ( ) ,
274
+ pluralize ( trait_m. tps . len ( ) , ~"parameter") ) ) ;
269
275
return ;
270
276
}
271
277
@@ -278,6 +284,28 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span,
278
284
return ;
279
285
}
280
286
287
+ for trait_m. tps. eachi( ) |i, trait_param_bounds| {
288
+ // For each of the corresponding impl ty param's bounds...
289
+ let impl_param_bounds = impl_m. tps [ i] ;
290
+ // Make sure the bounds lists have the same length
291
+ // Would be nice to use the ty param names in the error message,
292
+ // but we don't have easy access to them here
293
+ if impl_param_bounds. len ( ) != trait_param_bounds. len ( ) {
294
+ tcx. sess . span_err ( sp, #fmt ( "in method `%s`, \
295
+ type parameter %u has %u %s, but the same type \
296
+ parameter in its trait declaration has %u %s",
297
+ tcx. sess . str_of ( trait_m. ident ) ,
298
+ i, impl_param_bounds. len ( ) ,
299
+ pluralize ( impl_param_bounds. len ( ) , ~"bound") ,
300
+ trait_param_bounds. len ( ) ,
301
+ pluralize ( trait_param_bounds. len ( ) , ~"bound") ) ) ;
302
+ return ;
303
+ }
304
+ // tjc: I'm mildly worried that there's something I'm
305
+ // not checking that require_same_types doesn't catch,
306
+ // but I can't figure out what.
307
+ }
308
+
281
309
// Perform substitutions so that the trait/impl methods are expressed
282
310
// in terms of the same set of type/region parameters:
283
311
// - replace trait type parameters with those from `trait_substs`
0 commit comments