@@ -1860,6 +1860,29 @@ fn ty_generics<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
1860
1860
result
1861
1861
}
1862
1862
1863
+ fn convert_default_type_parameter < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > ,
1864
+ path : & P < ast:: Ty > ,
1865
+ space : ParamSpace ,
1866
+ index : u32 )
1867
+ -> Ty < ' tcx >
1868
+ {
1869
+ let ty = ast_ty_to_ty ( & ccx. icx ( & ( ) ) , & ExplicitRscope , & path) ;
1870
+
1871
+ for leaf_ty in ty. walk ( ) {
1872
+ if let ty:: TyParam ( p) = leaf_ty. sty {
1873
+ if p. space == space && p. idx >= index {
1874
+ span_err ! ( ccx. tcx. sess, path. span, E0128 ,
1875
+ "type parameters with a default cannot use \
1876
+ forward declared identifiers") ;
1877
+
1878
+ return ccx. tcx . types . err
1879
+ }
1880
+ }
1881
+ }
1882
+
1883
+ ty
1884
+ }
1885
+
1863
1886
fn get_or_create_type_parameter_def < ' a , ' tcx > ( ccx : & CrateCtxt < ' a , ' tcx > ,
1864
1887
ast_generics : & ast:: Generics ,
1865
1888
space : ParamSpace ,
@@ -1874,25 +1897,9 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
1874
1897
None => { }
1875
1898
}
1876
1899
1877
- let default = match param. default {
1878
- None => None ,
1879
- Some ( ref path) => {
1880
- let ty = ast_ty_to_ty ( & ccx. icx ( & ( ) ) , & ExplicitRscope , & * * path) ;
1881
- let cur_idx = index;
1882
-
1883
- for leaf_ty in ty. walk ( ) {
1884
- if let ty:: TyParam ( p) = leaf_ty. sty {
1885
- if p. idx > cur_idx {
1886
- span_err ! ( tcx. sess, path. span, E0128 ,
1887
- "type parameters with a default cannot use \
1888
- forward declared identifiers") ;
1889
- }
1890
- }
1891
- }
1892
-
1893
- Some ( ty)
1894
- }
1895
- } ;
1900
+ let default = param. default . as_ref ( ) . map (
1901
+ |def| convert_default_type_parameter ( ccx, def, space, index)
1902
+ ) ;
1896
1903
1897
1904
let object_lifetime_default =
1898
1905
compute_object_lifetime_default ( ccx, param. id ,
0 commit comments