@@ -52,16 +52,14 @@ pub trait AstConv<'gcx, 'tcx> {
52
52
fn ast_ty_to_ty_cache ( & self ) -> & RefCell < NodeMap < Ty < ' tcx > > > ;
53
53
54
54
/// Returns the generic type and lifetime parameters for an item.
55
- fn get_generics ( & self , span : Span , id : DefId )
56
- -> Result < & ' tcx ty:: Generics , ErrorReported > ;
55
+ fn get_generics ( & self , id : DefId ) -> & ' tcx ty:: Generics ;
57
56
58
57
/// Identify the type for an item, like a type alias, fn, or struct.
59
- fn get_item_type ( & self , span : Span , id : DefId ) -> Result < Ty < ' tcx > , ErrorReported > ;
58
+ fn get_item_type ( & self , span : Span , id : DefId ) -> Ty < ' tcx > ;
60
59
61
60
/// Returns the `TraitDef` for a given trait. This allows you to
62
61
/// figure out the set of type parameters defined on the trait.
63
- fn get_trait_def ( & self , span : Span , id : DefId )
64
- -> Result < & ' tcx ty:: TraitDef , ErrorReported > ;
62
+ fn get_trait_def ( & self , id : DefId ) -> & ' tcx ty:: TraitDef ;
65
63
66
64
/// Ensure that the super-predicates for the trait with the given
67
65
/// id are available and also for the transitive set of
@@ -251,14 +249,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
251
249
// If the type is parameterized by this region, then replace this
252
250
// region with the current anon region binding (in other words,
253
251
// whatever & would get replaced with).
254
- let decl_generics = match self . get_generics ( span, def_id) {
255
- Ok ( generics) => generics,
256
- Err ( ErrorReported ) => {
257
- // No convenient way to recover from a cycle here. Just bail. Sorry!
258
- self . tcx ( ) . sess . abort_if_errors ( ) ;
259
- bug ! ( "ErrorReported returned, but no errors reports?" )
260
- }
261
- } ;
252
+ let decl_generics = self . get_generics ( def_id) ;
262
253
let expected_num_region_params = decl_generics. regions . len ( ) ;
263
254
let supplied_num_region_params = lifetimes. len ( ) ;
264
255
if expected_num_region_params != supplied_num_region_params {
@@ -279,8 +270,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
279
270
let is_object = self_ty. map_or ( false , |ty| ty. sty == TRAIT_OBJECT_DUMMY_SELF ) ;
280
271
let default_needs_object_self = |p : & ty:: TypeParameterDef | {
281
272
if is_object && p. has_default {
282
- let default = self . get_item_type ( span, p. def_id ) . ok ( ) ;
283
- if default. has_self_ty ( ) {
273
+ if self . get_item_type ( span, p. def_id ) . has_self_ty ( ) {
284
274
// There is no suitable inference default for a type parameter
285
275
// that references self, in an object type.
286
276
return true ;
@@ -347,10 +337,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
347
337
tcx. types . err
348
338
} else {
349
339
// This is a default type parameter.
350
- match self . get_item_type ( span, def. def_id ) {
351
- Ok ( ty) => ty. subst_spanned ( tcx, substs, Some ( span) ) ,
352
- Err ( ErrorReported ) => tcx. types . err
353
- }
340
+ self . get_item_type ( span, def. def_id ) . subst_spanned ( tcx, substs, Some ( span) )
354
341
}
355
342
} else {
356
343
// We've already errored above about the mismatch.
@@ -499,14 +486,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
499
486
debug ! ( "create_substs_for_ast_trait_ref(trait_segment={:?})" ,
500
487
trait_segment) ;
501
488
502
- let trait_def = match self . get_trait_def ( span, trait_def_id) {
503
- Ok ( trait_def) => trait_def,
504
- Err ( ErrorReported ) => {
505
- // No convenient way to recover from a cycle here. Just bail. Sorry!
506
- self . tcx ( ) . sess . abort_if_errors ( ) ;
507
- bug ! ( "ErrorReported returned, but no errors reports?" )
508
- }
509
- } ;
489
+ let trait_def = self . get_trait_def ( trait_def_id) ;
510
490
511
491
match trait_segment. parameters {
512
492
hir:: AngleBracketedParameters ( _) => {
@@ -647,16 +627,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
647
627
item_segment : & hir:: PathSegment )
648
628
-> Ty < ' tcx >
649
629
{
650
- let tcx = self . tcx ( ) ;
651
- let decl_ty = match self . get_item_type ( span, did) {
652
- Ok ( ty) => ty,
653
- Err ( ErrorReported ) => {
654
- return tcx. types . err ;
655
- }
656
- } ;
657
-
658
630
let substs = self . ast_path_substs_for_ty ( span, did, item_segment) ;
659
- decl_ty . subst ( self . tcx ( ) , substs)
631
+ self . get_item_type ( span , did ) . subst ( self . tcx ( ) , substs)
660
632
}
661
633
662
634
/// Transform a PolyTraitRef into a PolyExistentialTraitRef by
@@ -1058,37 +1030,23 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1058
1030
tcx. prohibit_type_params ( & path. segments ) ;
1059
1031
1060
1032
let node_id = tcx. hir . as_local_node_id ( did) . unwrap ( ) ;
1061
- let item_def_id = tcx. hir . local_def_id ( :: ty_param_owner ( tcx, node_id) ) ;
1062
- let index = match self . get_generics ( span, item_def_id) {
1063
- Ok ( generics) => {
1064
- generics. type_param_to_index [ & tcx. hir . local_def_id ( node_id) . index ]
1065
- }
1066
- Err ( ErrorReported ) => return tcx. types . err
1067
- } ;
1068
- tcx. mk_param ( index, :: ty_param_name ( tcx, node_id) )
1033
+ let item_id = tcx. hir . get_parent_node ( node_id) ;
1034
+ let item_def_id = tcx. hir . local_def_id ( item_id) ;
1035
+ let generics = self . get_generics ( item_def_id) ;
1036
+ let index = generics. type_param_to_index [ & tcx. hir . local_def_id ( node_id) . index ] ;
1037
+ tcx. mk_param ( index, tcx. hir . name ( node_id) )
1069
1038
}
1070
1039
Def :: SelfTy ( _, Some ( def_id) ) => {
1071
1040
// Self in impl (we know the concrete type).
1072
1041
1073
1042
assert_eq ! ( opt_self_ty, None ) ;
1074
1043
tcx. prohibit_type_params ( & path. segments ) ;
1075
1044
1076
- // FIXME: Self type is not always computed when we are here because type parameter
1077
- // bounds may affect Self type and have to be converted before it.
1078
- let ty = if def_id. is_local ( ) {
1079
- tcx. item_types . borrow ( ) . get ( & def_id) . cloned ( )
1080
- } else {
1081
- Some ( tcx. item_type ( def_id) )
1082
- } ;
1083
- if let Some ( ty) = ty {
1084
- if let Some ( free_substs) = self . get_free_substs ( ) {
1085
- ty. subst ( tcx, free_substs)
1086
- } else {
1087
- ty
1088
- }
1045
+ let ty = self . get_item_type ( span, def_id) ;
1046
+ if let Some ( free_substs) = self . get_free_substs ( ) {
1047
+ ty. subst ( tcx, free_substs)
1089
1048
} else {
1090
- tcx. sess . span_err ( span, "`Self` type is used before it's determined" ) ;
1091
- tcx. types . err
1049
+ ty
1092
1050
}
1093
1051
}
1094
1052
Def :: SelfTy ( Some ( _) , None ) => {
@@ -1241,9 +1199,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1241
1199
// Create the anonymized type.
1242
1200
if allow {
1243
1201
let def_id = tcx. hir . local_def_id ( ast_ty. id ) ;
1244
- if let Err ( ErrorReported ) = self . get_generics ( ast_ty. span , def_id) {
1245
- return tcx. types . err ;
1246
- }
1202
+ self . get_generics ( def_id) ;
1247
1203
let substs = Substs :: identity_for_item ( tcx, def_id) ;
1248
1204
let ty = tcx. mk_anon ( tcx. hir . local_def_id ( ast_ty. id ) , substs) ;
1249
1205
0 commit comments