@@ -813,24 +813,26 @@ fn compare_impl_method(tcx: ty::ctxt,
813
813
if num_impl_m_type_params != num_trait_m_type_params {
814
814
tcx. sess . span_err (
815
815
impl_m_span,
816
- format ! ( "method `{}` has {} type parameter(s), but its trait \
817
- declaration has {} type parameter(s)",
818
- token:: get_ident( trait_m. ident) ,
819
- num_impl_m_type_params,
820
- num_trait_m_type_params) ) ;
816
+ format ! ( "method `{method}` has {nimpl, plural, =1{# type parameter} \
817
+ other{# type parameters}}, \
818
+ but its trait declaration has {ntrait, plural, =1{# type parameter} \
819
+ other{# type parameters}}",
820
+ method = token:: get_ident( trait_m. ident) ,
821
+ nimpl = num_impl_m_type_params,
822
+ ntrait = num_trait_m_type_params) ) ;
821
823
return ;
822
824
}
823
825
824
826
if impl_m. fty . sig . inputs . len ( ) != trait_m. fty . sig . inputs . len ( ) {
825
827
tcx. sess . span_err (
826
828
impl_m_span,
827
- format ! ( "method `{}` has {} parameter{ } \
828
- but the declaration in trait `{}` has {}" ,
829
- token :: get_ident ( trait_m . ident ) ,
830
- impl_m . fty . sig . inputs . len ( ) ,
831
- if impl_m. fty. sig. inputs. len( ) == 1 { "" } else { "s" } ,
832
- ty:: item_path_str( tcx, trait_m. def_id) ,
833
- trait_m. fty. sig. inputs. len( ) ) ) ;
829
+ format ! ( "method `{method }` has {nimpl, plural, =1{# parameter } \
830
+ other{# parameters}} \
831
+ but the declaration in trait `{trait}` has {ntrait}" ,
832
+ method = token :: get_ident ( trait_m . ident ) ,
833
+ nimpl = impl_m. fty. sig. inputs. len( ) ,
834
+ trait = ty:: item_path_str( tcx, trait_m. def_id) ,
835
+ ntrait = trait_m. fty. sig. inputs. len( ) ) ) ;
834
836
return ;
835
837
}
836
838
@@ -865,13 +867,16 @@ fn compare_impl_method(tcx: ty::ctxt,
865
867
{
866
868
tcx. sess . span_err (
867
869
impl_m_span,
868
- format ! ( "in method `{}`, \
869
- type parameter {} has {} trait bound(s), but the \
870
- corresponding type parameter in \
871
- the trait declaration has {} trait bound(s)",
872
- token:: get_ident( trait_m. ident) ,
873
- i, impl_param_def. bounds. trait_bounds. len( ) ,
874
- trait_param_def. bounds. trait_bounds. len( ) ) ) ;
870
+ format ! ( "in method `{method}`, \
871
+ type parameter {typaram} has \
872
+ {nimpl, plural, =1{# trait bound} other{# trait bounds}}, \
873
+ but the corresponding type parameter in \
874
+ the trait declaration has \
875
+ {ntrait, plural, =1{# trait bound} other{# trait bounds}}",
876
+ method = token:: get_ident( trait_m. ident) ,
877
+ typaram = i,
878
+ nimpl = impl_param_def. bounds. trait_bounds. len( ) ,
879
+ ntrait = trait_param_def. bounds. trait_bounds. len( ) ) ) ;
875
880
return ;
876
881
}
877
882
}
@@ -1507,10 +1512,12 @@ fn check_type_parameter_positions_in_path(function_context: @FnCtxt,
1507
1512
function_context. tcx ( )
1508
1513
. sess
1509
1514
. span_err ( path. span ,
1510
- format ! ( "expected {} lifetime parameter(s), \
1511
- found {} lifetime parameter(s)",
1512
- trait_region_parameter_count,
1513
- supplied_region_parameter_count) ) ;
1515
+ format ! ( "expected {nexpected, plural, =1{# lifetime parameter} \
1516
+ other{# lifetime parameters}}, \
1517
+ found {nsupplied, plural, =1{# lifetime parameter} \
1518
+ other{# lifetime parameters}}",
1519
+ nexpected = trait_region_parameter_count,
1520
+ nsupplied = supplied_region_parameter_count) ) ;
1514
1521
}
1515
1522
1516
1523
// Make sure the number of type parameters supplied on the trait
@@ -1522,49 +1529,47 @@ fn check_type_parameter_positions_in_path(function_context: @FnCtxt,
1522
1529
. len ( ) ;
1523
1530
let supplied_ty_param_count = trait_segment. types . len ( ) ;
1524
1531
if supplied_ty_param_count < required_ty_param_count {
1525
- let trait_count_suffix = if required_ty_param_count == 1 {
1526
- ""
1527
- } else {
1528
- "s"
1529
- } ;
1530
- let supplied_count_suffix = if supplied_ty_param_count == 1 {
1531
- ""
1532
+ let msg = if required_ty_param_count < generics. type_param_defs ( ) . len ( ) {
1533
+ format ! ( "the {trait_or_impl} referenced by this path needs at least \
1534
+ {nexpected, plural, =1{# type parameter} \
1535
+ other{# type parameters}}, \
1536
+ but {nsupplied, plural, =1{# type parameter} \
1537
+ other{# type parameters}} were supplied",
1538
+ trait_or_impl = name,
1539
+ nexpected = required_ty_param_count,
1540
+ nsupplied = supplied_ty_param_count)
1532
1541
} else {
1533
- "s"
1542
+ format ! ( "the {trait_or_impl} referenced by this path needs \
1543
+ {nexpected, plural, =1{# type parameter} \
1544
+ other{# type parameters}}, \
1545
+ but {nsupplied, plural, =1{# type parameter} \
1546
+ other{# type parameters}} were supplied",
1547
+ trait_or_impl = name,
1548
+ nexpected = required_ty_param_count,
1549
+ nsupplied = supplied_ty_param_count)
1534
1550
} ;
1535
- let needs = if required_ty_param_count < generics. type_param_defs ( ) . len ( ) {
1536
- "needs at least"
1537
- } else {
1538
- "needs"
1539
- } ;
1540
- function_context. tcx ( ) . sess . span_err ( path. span ,
1541
- format ! ( "the {} referenced by this path {} {} type \
1542
- parameter{}, but {} type parameter{} were supplied",
1543
- name, needs,
1544
- required_ty_param_count, trait_count_suffix,
1545
- supplied_ty_param_count, supplied_count_suffix) )
1551
+ function_context. tcx ( ) . sess . span_err ( path. span , msg)
1546
1552
} else if supplied_ty_param_count > formal_ty_param_count {
1547
- let trait_count_suffix = if formal_ty_param_count == 1 {
1548
- ""
1553
+ let msg = if required_ty_param_count < generics. type_param_defs ( ) . len ( ) {
1554
+ format ! ( "the {trait_or_impl} referenced by this path needs at most \
1555
+ {nexpected, plural, =1{# type parameter} \
1556
+ other{# type parameters}}, \
1557
+ but {nsupplied, plural, =1{# type parameter} \
1558
+ other{# type parameters}} were supplied",
1559
+ trait_or_impl = name,
1560
+ nexpected = formal_ty_param_count,
1561
+ nsupplied = supplied_ty_param_count)
1549
1562
} else {
1550
- "s"
1563
+ format ! ( "the {trait_or_impl} referenced by this path needs \
1564
+ {nexpected, plural, =1{# type parameter} \
1565
+ other{# type parameters}}, \
1566
+ but {nsupplied, plural, =1{# type parameter} \
1567
+ other{# type parameters}} were supplied",
1568
+ trait_or_impl = name,
1569
+ nexpected = formal_ty_param_count,
1570
+ nsupplied = supplied_ty_param_count)
1551
1571
} ;
1552
- let supplied_count_suffix = if supplied_ty_param_count == 1 {
1553
- ""
1554
- } else {
1555
- "s"
1556
- } ;
1557
- let needs = if required_ty_param_count < generics. type_param_defs ( ) . len ( ) {
1558
- "needs at most"
1559
- } else {
1560
- "needs"
1561
- } ;
1562
- function_context. tcx ( ) . sess . span_err ( path. span ,
1563
- format ! ( "the {} referenced by this path {} {} type \
1564
- parameter{}, but {} type parameter{} were supplied",
1565
- name, needs,
1566
- formal_ty_param_count, trait_count_suffix,
1567
- supplied_ty_param_count, supplied_count_suffix) )
1572
+ function_context. tcx ( ) . sess . span_err ( path. span , msg)
1568
1573
}
1569
1574
}
1570
1575
_ => {
@@ -1665,24 +1670,25 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
1665
1670
fn_inputs. map ( |a| * a)
1666
1671
} else {
1667
1672
let msg = format ! (
1668
- "this function takes at least {} parameter{ } \
1669
- but {} parameter{} supplied" ,
1670
- expected_arg_count ,
1671
- if expected_arg_count == 1 { "" } else { "s" } ,
1672
- supplied_arg_count ,
1673
- if supplied_arg_count == 1 { " was" } else { "s were" } ) ;
1673
+ "this function takes at least {nexpected, plural, =1{# parameter } \
1674
+ other{# parameters}} \
1675
+ but {nsupplied, plural, =1{# parameter was} \
1676
+ other{# parameters were}} supplied" ,
1677
+ nexpected = expected_arg_count ,
1678
+ nsupplied = supplied_arg_count ) ;
1674
1679
1675
1680
tcx. sess . span_err ( sp, msg) ;
1676
1681
1677
1682
err_args ( supplied_arg_count)
1678
1683
}
1679
1684
} else {
1680
1685
let msg = format ! (
1681
- "this function takes {} parameter{} \
1682
- but {} parameter{} supplied",
1683
- expected_arg_count, if expected_arg_count == 1 { "" } else { "s" } ,
1684
- supplied_arg_count,
1685
- if supplied_arg_count == 1 { " was" } else { "s were" } ) ;
1686
+ "this function takes {nexpected, plural, =1{# parameter} \
1687
+ other{# parameters}} \
1688
+ but {nsupplied, plural, =1{# parameter was} \
1689
+ other{# parameters were}} supplied",
1690
+ nexpected = expected_arg_count,
1691
+ nsupplied = supplied_arg_count) ;
1686
1692
1687
1693
tcx. sess . span_err ( sp, msg) ;
1688
1694
@@ -2384,13 +2390,9 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
2384
2390
}
2385
2391
2386
2392
tcx. sess . span_err ( span,
2387
- format ! ( "missing field{}: {}" ,
2388
- if missing_fields. len( ) == 1 {
2389
- ""
2390
- } else {
2391
- "s"
2392
- } ,
2393
- missing_fields. connect( ", " ) ) ) ;
2393
+ format ! ( "missing {nfields, plural, =1{field} other{fields}}: {fields}" ,
2394
+ nfields = missing_fields. len( ) ,
2395
+ fields = missing_fields. connect( ", " ) ) ) ;
2394
2396
}
2395
2397
}
2396
2398
@@ -3556,8 +3558,12 @@ pub fn check_enum_variants(ccx: @CrateCtxt,
3556
3558
3557
3559
let hint = ty:: lookup_repr_hint ( ccx. tcx , ast:: DefId { krate : ast:: LOCAL_CRATE , node : id } ) ;
3558
3560
if hint != attr:: ReprAny && vs. len ( ) <= 1 {
3559
- ccx. tcx . sess . span_err ( sp, format ! ( "unsupported representation for {}variant enum" ,
3560
- if vs. len( ) == 1 { "uni" } else { "zero-" } ) )
3561
+ let msg = if vs. len ( ) == 1 {
3562
+ "unsupported representation for univariant enum"
3563
+ } else {
3564
+ "unsupported representation for zero-variant enum"
3565
+ } ;
3566
+ ccx. tcx . sess . span_err ( sp, msg)
3561
3567
}
3562
3568
3563
3569
let variants = do_check ( ccx, vs, id, hint) ;
@@ -3666,9 +3672,12 @@ pub fn instantiate_path(fcx: @FnCtxt,
3666
3672
if num_supplied_regions != 0 {
3667
3673
fcx. ccx . tcx . sess . span_err (
3668
3674
span,
3669
- format ! ( "expected {} lifetime parameter(s), \
3670
- found {} lifetime parameter(s)",
3671
- num_expected_regions, num_supplied_regions) ) ;
3675
+ format ! ( "expected {nexpected, plural, =1{# lifetime parameter} \
3676
+ other{# lifetime parameters}}, \
3677
+ found {nsupplied, plural, =1{# lifetime parameter} \
3678
+ other{# lifetime parameters}}",
3679
+ nexpected = num_expected_regions,
3680
+ nsupplied = num_supplied_regions) ) ;
3672
3681
}
3673
3682
3674
3683
opt_vec:: from ( fcx. infcx ( ) . next_region_vars (
0 commit comments