@@ -715,7 +715,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
715
715
// Create generics from the generics specified in the impl head.
716
716
debug ! ( "convert: ast_generics={:?}" , generics) ;
717
717
let def_id = ccx. tcx . map . local_def_id ( it. id ) ;
718
- let ty_generics = ty_generics_for_type_or_impl ( ccx, generics) ;
718
+ let ty_generics = ty_generics_for_impl ( ccx, generics) ;
719
719
let mut ty_predicates = ty_generic_predicates_for_type_or_impl ( ccx, generics) ;
720
720
721
721
debug ! ( "convert: impl_bounds={:?}" , ty_predicates) ;
@@ -1455,19 +1455,19 @@ fn compute_type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
1455
1455
ty:: TypeScheme { ty : ty, generics : ty_generics }
1456
1456
}
1457
1457
hir:: ItemTy ( ref t, ref generics) => {
1458
- let ty_generics = ty_generics_for_type_or_impl ( ccx, generics) ;
1458
+ let ty_generics = ty_generics_for_type ( ccx, generics) ;
1459
1459
let ty = ccx. icx ( generics) . to_ty ( & ExplicitRscope , & t) ;
1460
1460
ty:: TypeScheme { ty : ty, generics : ty_generics }
1461
1461
}
1462
1462
hir:: ItemEnum ( ref ei, ref generics) => {
1463
- let ty_generics = ty_generics_for_type_or_impl ( ccx, generics) ;
1463
+ let ty_generics = ty_generics_for_type ( ccx, generics) ;
1464
1464
let substs = mk_item_substs ( ccx, & ty_generics) ;
1465
1465
let def = convert_enum_def ( tcx, it, ei) ;
1466
1466
let t = tcx. mk_enum ( def, tcx. mk_substs ( substs) ) ;
1467
1467
ty:: TypeScheme { ty : t, generics : ty_generics }
1468
1468
}
1469
1469
hir:: ItemStruct ( ref si, ref generics) => {
1470
- let ty_generics = ty_generics_for_type_or_impl ( ccx, generics) ;
1470
+ let ty_generics = ty_generics_for_type ( ccx, generics) ;
1471
1471
let substs = mk_item_substs ( ccx, & ty_generics) ;
1472
1472
let def = convert_struct_def ( tcx, it, si) ;
1473
1473
let t = tcx. mk_struct ( def, tcx. mk_substs ( substs) ) ;
@@ -1611,10 +1611,14 @@ fn convert_foreign_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
1611
1611
assert ! ( prev_predicates. is_none( ) ) ;
1612
1612
}
1613
1613
1614
- fn ty_generics_for_type_or_impl < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > ,
1615
- generics : & hir:: Generics )
1616
- -> ty:: Generics < ' tcx > {
1617
- ty_generics ( ccx, TypeSpace , generics, & ty:: Generics :: empty ( ) )
1614
+ fn ty_generics_for_type < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > , generics : & hir:: Generics )
1615
+ -> ty:: Generics < ' tcx > {
1616
+ ty_generics ( ccx, TypeSpace , generics, & ty:: Generics :: empty ( ) , true )
1617
+ }
1618
+
1619
+ fn ty_generics_for_impl < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > , generics : & hir:: Generics )
1620
+ -> ty:: Generics < ' tcx > {
1621
+ ty_generics ( ccx, TypeSpace , generics, & ty:: Generics :: empty ( ) , false )
1618
1622
}
1619
1623
1620
1624
fn ty_generic_predicates_for_type_or_impl < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > ,
@@ -1633,7 +1637,7 @@ fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
1633
1637
debug ! ( "ty_generics_for_trait(trait_id={:?}, substs={:?})" ,
1634
1638
ccx. tcx. map. local_def_id( trait_id) , substs) ;
1635
1639
1636
- let mut generics = ty_generics_for_type_or_impl ( ccx, ast_generics) ;
1640
+ let mut generics = ty_generics_for_type ( ccx, ast_generics) ;
1637
1641
1638
1642
// Add in the self type parameter.
1639
1643
//
@@ -1665,7 +1669,7 @@ fn ty_generics_for_fn<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
1665
1669
base_generics : & ty:: Generics < ' tcx > )
1666
1670
-> ty:: Generics < ' tcx >
1667
1671
{
1668
- ty_generics ( ccx, FnSpace , generics, base_generics)
1672
+ ty_generics ( ccx, FnSpace , generics, base_generics, false )
1669
1673
}
1670
1674
1671
1675
fn ty_generic_predicates_for_fn < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > ,
@@ -1840,7 +1844,8 @@ fn ty_generic_predicates<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
1840
1844
fn ty_generics < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > ,
1841
1845
space : ParamSpace ,
1842
1846
ast_generics : & hir:: Generics ,
1843
- base_generics : & ty:: Generics < ' tcx > )
1847
+ base_generics : & ty:: Generics < ' tcx > ,
1848
+ allow_defaults : bool )
1844
1849
-> ty:: Generics < ' tcx >
1845
1850
{
1846
1851
let tcx = ccx. tcx ;
@@ -1863,7 +1868,8 @@ fn ty_generics<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
1863
1868
1864
1869
// Now create the real type parameters.
1865
1870
for i in 0 ..ast_generics. ty_params . len ( ) {
1866
- let def = get_or_create_type_parameter_def ( ccx, ast_generics, space, i as u32 ) ;
1871
+ let def =
1872
+ get_or_create_type_parameter_def ( ccx, ast_generics, space, i as u32 , allow_defaults) ;
1867
1873
debug ! ( "ty_generics: def for type param: {:?}, {:?}" , def, space) ;
1868
1874
result. types . push ( space, def) ;
1869
1875
}
@@ -1897,7 +1903,8 @@ fn convert_default_type_parameter<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
1897
1903
fn get_or_create_type_parameter_def < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > ,
1898
1904
ast_generics : & hir:: Generics ,
1899
1905
space : ParamSpace ,
1900
- index : u32 )
1906
+ index : u32 ,
1907
+ allow_defaults : bool )
1901
1908
-> ty:: TypeParameterDef < ' tcx >
1902
1909
{
1903
1910
let param = & ast_generics. ty_params [ index as usize ] ;
@@ -1918,7 +1925,7 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
1918
1925
1919
1926
let parent = tcx. map . get_parent ( param. id ) ;
1920
1927
1921
- if space != TypeSpace && default. is_some ( ) {
1928
+ if !allow_defaults && default. is_some ( ) {
1922
1929
if !tcx. sess . features . borrow ( ) . default_type_parameter_fallback {
1923
1930
tcx. sess . add_lint (
1924
1931
lint:: builtin:: INVALID_TYPE_PARAM_DEFAULT ,
0 commit comments