@@ -305,9 +305,9 @@ fn create_region_substs<'tcx>(
305
305
rscope. anon_regions ( span, expected_num_region_params) ;
306
306
307
307
if supplied_num_region_params != 0 || anon_regions. is_err ( ) {
308
- span_err ! ( tcx. sess , span, E0107 ,
309
- "wrong number of lifetime parameters: expected {}, found {}" ,
310
- expected_num_region_params , supplied_num_region_params ) ;
308
+ report_lifetime_number_error ( tcx, span,
309
+ supplied_num_region_params ,
310
+ expected_num_region_params ) ;
311
311
}
312
312
313
313
match anon_regions {
@@ -355,31 +355,14 @@ fn create_substs_for_ast_path<'tcx>(
355
355
. count ( ) ;
356
356
357
357
let mut type_substs = types_provided;
358
+ check_type_argument_count ( this. tcx ( ) , span, supplied_ty_param_count,
359
+ required_ty_param_count, formal_ty_param_count) ;
360
+
358
361
if supplied_ty_param_count < required_ty_param_count {
359
- let expected = if required_ty_param_count < formal_ty_param_count {
360
- "expected at least"
361
- } else {
362
- "expected"
363
- } ;
364
- span_err ! ( this. tcx( ) . sess, span, E0243 ,
365
- "wrong number of type arguments: {} {}, found {}" ,
366
- expected,
367
- required_ty_param_count,
368
- supplied_ty_param_count) ;
369
362
while type_substs. len ( ) < required_ty_param_count {
370
363
type_substs. push ( tcx. types . err ) ;
371
364
}
372
365
} else if supplied_ty_param_count > formal_ty_param_count {
373
- let expected = if required_ty_param_count < formal_ty_param_count {
374
- "expected at most"
375
- } else {
376
- "expected"
377
- } ;
378
- span_err ! ( this. tcx( ) . sess, span, E0244 ,
379
- "wrong number of type arguments: {} {}, found {}" ,
380
- expected,
381
- formal_ty_param_count,
382
- supplied_ty_param_count) ;
383
366
type_substs. truncate ( formal_ty_param_count) ;
384
367
}
385
368
assert ! ( type_substs. len( ) >= required_ty_param_count &&
@@ -1849,10 +1832,13 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
1849
1832
& mut builtin_bounds) {
1850
1833
let segments = & b. trait_ref . path . segments ;
1851
1834
let parameters = & segments[ segments. len ( ) - 1 ] . parameters ;
1852
- if !parameters. is_empty ( ) {
1853
- span_err ! ( tcx. sess, b. trait_ref. path. span, E0316 ,
1854
- "builtin bounds do not require arguments, {} given" ,
1855
- parameters. lifetimes( ) . len( ) + parameters. types( ) . len( ) ) ;
1835
+ if parameters. types ( ) . len ( ) > 0 {
1836
+ check_type_argument_count ( tcx, b. trait_ref . path . span ,
1837
+ parameters. types ( ) . len ( ) , 0 , 0 ) ;
1838
+ }
1839
+ if parameters. lifetimes ( ) . len ( ) > 0 {
1840
+ report_lifetime_number_error ( tcx, b. trait_ref . path . span ,
1841
+ parameters. lifetimes ( ) . len ( ) , 0 ) ;
1856
1842
}
1857
1843
continue ; // success
1858
1844
}
@@ -1886,3 +1872,34 @@ fn prohibit_projections<'tcx>(tcx: &ty::ctxt<'tcx>,
1886
1872
"associated type bindings are not allowed here" ) ;
1887
1873
}
1888
1874
}
1875
+
1876
+ fn check_type_argument_count ( tcx : & ty:: ctxt , span : Span , supplied : usize ,
1877
+ required : usize , accepted : usize ) {
1878
+ if supplied < required {
1879
+ let expected = if required < accepted {
1880
+ "expected at least"
1881
+ } else {
1882
+ "expected"
1883
+ } ;
1884
+ span_err ! ( tcx. sess, span, E0243 ,
1885
+ "wrong number of type arguments: {} {}, found {}" ,
1886
+ expected, required, supplied) ;
1887
+ } else if supplied > accepted {
1888
+ let expected = if required < accepted {
1889
+ "expected at most"
1890
+ } else {
1891
+ "expected"
1892
+ } ;
1893
+ span_err ! ( tcx. sess, span, E0244 ,
1894
+ "wrong number of type arguments: {} {}, found {}" ,
1895
+ expected,
1896
+ accepted,
1897
+ supplied) ;
1898
+ }
1899
+ }
1900
+
1901
+ fn report_lifetime_number_error ( tcx : & ty:: ctxt , span : Span , number : usize , expected : usize ) {
1902
+ span_err ! ( tcx. sess, span, E0107 ,
1903
+ "wrong number of lifetime parameters: expected {}, found {}" ,
1904
+ expected, number) ;
1905
+ }
0 commit comments