@@ -1113,6 +1113,7 @@ fn report_ambiguous_associated_type(tcx: &ty::ctxt,
11131113// any ambiguity.
11141114fn find_bound_for_assoc_item < ' tcx > ( this : & AstConv < ' tcx > ,
11151115 ty_param_node_id : ast:: NodeId ,
1116+ ty_param_name : Option < ast:: Name > ,
11161117 assoc_name : ast:: Name ,
11171118 span : Span )
11181119 -> Result < ty:: PolyTraitRef < ' tcx > , ErrorReported >
@@ -1138,12 +1139,21 @@ fn find_bound_for_assoc_item<'tcx>(this: &AstConv<'tcx>,
11381139 . filter ( |b| this. trait_defines_associated_type_named ( b. def_id ( ) , assoc_name) )
11391140 . collect ( ) ;
11401141
1141- let ty_param_name = tcx. type_parameter_def ( ty_param_node_id) . name ;
1142- one_bound_for_assoc_type ( tcx,
1143- suitable_bounds,
1144- & token:: get_name ( ty_param_name) ,
1145- & token:: get_name ( assoc_name) ,
1146- span)
1142+ if let Some ( s) = ty_param_name {
1143+ // borrowck doesn't like this any other way
1144+ one_bound_for_assoc_type ( tcx,
1145+ suitable_bounds,
1146+ & token:: get_name ( s) ,
1147+ & token:: get_name ( assoc_name) ,
1148+ span)
1149+ } else {
1150+ one_bound_for_assoc_type ( tcx,
1151+ suitable_bounds,
1152+ "Self" ,
1153+ & token:: get_name ( assoc_name) ,
1154+ span)
1155+
1156+ }
11471157}
11481158
11491159
@@ -1240,12 +1250,20 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
12401250 _ => unreachable ! ( )
12411251 }
12421252 }
1243- ( & ty:: TyParam ( _) , def:: DefTyParam ( ..) ) |
1244- ( & ty:: TyParam ( _) , def:: DefSelfTy ( Some ( _) , None ) ) => {
1245- // A type parameter or Self, we need to find the associated item from
1246- // a bound.
1247- let ty_param_node_id = ty_path_def. local_node_id ( ) ;
1248- match find_bound_for_assoc_item ( this, ty_param_node_id, assoc_name, span) {
1253+ ( & ty:: TyParam ( _) , def:: DefSelfTy ( Some ( trait_did) , None ) ) => {
1254+ assert_eq ! ( trait_did. krate, ast:: LOCAL_CRATE ) ;
1255+ match find_bound_for_assoc_item ( this, trait_did. node , None , assoc_name, span) {
1256+ Ok ( bound) => bound,
1257+ Err ( ErrorReported ) => return ( tcx. types . err , ty_path_def) ,
1258+ }
1259+ }
1260+ ( & ty:: TyParam ( _) , def:: DefTyParam ( _, _, param_did, param_name) ) => {
1261+ assert_eq ! ( param_did. krate, ast:: LOCAL_CRATE ) ;
1262+ match find_bound_for_assoc_item ( this,
1263+ param_did. node ,
1264+ Some ( param_name) ,
1265+ assoc_name,
1266+ span) {
12491267 Ok ( bound) => bound,
12501268 Err ( ErrorReported ) => return ( tcx. types . err , ty_path_def) ,
12511269 }
0 commit comments