@@ -64,13 +64,12 @@ pub trait AstConv<'gcx, 'tcx> {
64
64
/// Ensure that the super-predicates for the trait with the given
65
65
/// id are available and also for the transitive set of
66
66
/// super-predicates.
67
- fn ensure_super_predicates ( & self , span : Span , id : DefId )
68
- -> Result < ( ) , ErrorReported > ;
67
+ fn ensure_super_predicates ( & self , span : Span , id : DefId ) ;
69
68
70
69
/// Returns the set of bounds in scope for the type parameter with
71
70
/// the given id.
72
- fn get_type_parameter_bounds ( & self , span : Span , def_id : ast :: NodeId )
73
- -> Result < Vec < ty:: PolyTraitRef < ' tcx > > , ErrorReported > ;
71
+ fn get_type_parameter_bounds ( & self , span : Span , def_id : DefId )
72
+ -> Vec < ty:: Predicate < ' tcx > > ;
74
73
75
74
/// Return an (optional) substitution to convert bound type parameters that
76
75
/// are in scope into free ones. This function should only return Some
@@ -599,7 +598,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
599
598
600
599
// Otherwise, we have to walk through the supertraits to find
601
600
// those that do.
602
- self . ensure_super_predicates ( binding. span , trait_ref. def_id ( ) ) ? ;
601
+ self . ensure_super_predicates ( binding. span , trait_ref. def_id ( ) ) ;
603
602
604
603
let candidates =
605
604
traits:: supertraits ( tcx, trait_ref. clone ( ) )
@@ -685,10 +684,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
685
684
} )
686
685
} ) ;
687
686
688
- // ensure the super predicates and stop if we encountered an error
689
- if self . ensure_super_predicates ( span, principal. def_id ( ) ) . is_err ( ) {
690
- return tcx. types . err ;
691
- }
687
+ // ensure the super predicates
688
+ self . ensure_super_predicates ( span, principal. def_id ( ) ) ;
692
689
693
690
// check that there are no gross object safety violations,
694
691
// most importantly, that the supertraits don't contain Self,
@@ -774,29 +771,23 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
774
771
}
775
772
776
773
// Search for a bound on a type parameter which includes the associated item
777
- // given by assoc_name. ty_param_node_id is the node id for the type parameter
778
- // (which might be `Self`, but only if it is the `Self` of a trait, not an
779
- // impl). This function will fail if there are no suitable bounds or there is
774
+ // given by `assoc_name`. `ty_param_def_id` is the `DefId` for the type parameter
775
+ // This function will fail if there are no suitable bounds or there is
780
776
// any ambiguity.
781
777
fn find_bound_for_assoc_item ( & self ,
782
- ty_param_node_id : ast:: NodeId ,
783
- ty_param_name : ast:: Name ,
778
+ ty_param_def_id : DefId ,
784
779
assoc_name : ast:: Name ,
785
780
span : Span )
786
781
-> Result < ty:: PolyTraitRef < ' tcx > , ErrorReported >
787
782
{
788
783
let tcx = self . tcx ( ) ;
789
784
790
- let bounds = match self . get_type_parameter_bounds ( span, ty_param_node_id) {
791
- Ok ( v) => v,
792
- Err ( ErrorReported ) => {
793
- return Err ( ErrorReported ) ;
794
- }
795
- } ;
785
+ let bounds: Vec < _ > = self . get_type_parameter_bounds ( span, ty_param_def_id)
786
+ . into_iter ( ) . filter_map ( |p| p. to_opt_poly_trait_ref ( ) ) . collect ( ) ;
796
787
797
- // Ensure the super predicates and stop if we encountered an error .
798
- if bounds . iter ( ) . any ( |b| self . ensure_super_predicates ( span , b . def_id ( ) ) . is_err ( ) ) {
799
- return Err ( ErrorReported ) ;
788
+ // Ensure the super predicates.
789
+ for b in & bounds {
790
+ self . ensure_super_predicates ( span , b . def_id ( ) ) ;
800
791
}
801
792
802
793
// Check that there is exactly one way to find an associated type with the
@@ -805,8 +796,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
805
796
traits:: transitive_bounds ( tcx, & bounds)
806
797
. filter ( |b| self . trait_defines_associated_type_named ( b. def_id ( ) , assoc_name) ) ;
807
798
799
+ let param_node_id = tcx. hir . as_local_node_id ( ty_param_def_id) . unwrap ( ) ;
800
+ let param_name = tcx. hir . ty_param_name ( param_node_id) ;
808
801
self . one_bound_for_assoc_type ( suitable_bounds,
809
- & ty_param_name . as_str ( ) ,
802
+ & param_name . as_str ( ) ,
810
803
& assoc_name. as_str ( ) ,
811
804
span)
812
805
}
@@ -914,9 +907,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
914
907
trait_ref
915
908
} ;
916
909
917
- if self . ensure_super_predicates ( span, trait_ref. def_id ) . is_err ( ) {
918
- return ( tcx. types . err , Def :: Err ) ;
919
- }
910
+ self . ensure_super_predicates ( span, trait_ref. def_id ) ;
920
911
921
912
let candidates =
922
913
traits:: supertraits ( tcx, ty:: Binder ( trait_ref) )
@@ -933,12 +924,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
933
924
}
934
925
( & ty:: TyParam ( _) , Def :: SelfTy ( Some ( param_did) , None ) ) |
935
926
( & ty:: TyParam ( _) , Def :: TyParam ( param_did) ) => {
936
- let param_node_id = tcx. hir . as_local_node_id ( param_did) . unwrap ( ) ;
937
- let param_name = :: ty_param_name ( tcx, param_node_id) ;
938
- match self . find_bound_for_assoc_item ( param_node_id,
939
- param_name,
940
- assoc_name,
941
- span) {
927
+ match self . find_bound_for_assoc_item ( param_did, assoc_name, span) {
942
928
Ok ( bound) => bound,
943
929
Err ( ErrorReported ) => return ( tcx. types . err , Def :: Err ) ,
944
930
}
@@ -1375,9 +1361,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1375
1361
existential_predicates) ;
1376
1362
1377
1363
if let Some ( principal) = existential_predicates. principal ( ) {
1378
- if let Err ( ErrorReported ) = self . ensure_super_predicates ( span, principal. def_id ( ) ) {
1379
- return Some ( tcx. mk_region ( ty:: ReStatic ) ) ;
1380
- }
1364
+ self . ensure_super_predicates ( span, principal. def_id ( ) ) ;
1381
1365
}
1382
1366
1383
1367
// No explicit region bound specified. Therefore, examine trait
0 commit comments