@@ -1113,6 +1113,7 @@ fn report_ambiguous_associated_type(tcx: &ty::ctxt,
1113
1113
// any ambiguity.
1114
1114
fn find_bound_for_assoc_item < ' tcx > ( this : & AstConv < ' tcx > ,
1115
1115
ty_param_node_id : ast:: NodeId ,
1116
+ ty_param_name : Option < ast:: Name > ,
1116
1117
assoc_name : ast:: Name ,
1117
1118
span : Span )
1118
1119
-> Result < ty:: PolyTraitRef < ' tcx > , ErrorReported >
@@ -1138,12 +1139,21 @@ fn find_bound_for_assoc_item<'tcx>(this: &AstConv<'tcx>,
1138
1139
. filter ( |b| this. trait_defines_associated_type_named ( b. def_id ( ) , assoc_name) )
1139
1140
. collect ( ) ;
1140
1141
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
+ }
1147
1157
}
1148
1158
1149
1159
@@ -1240,12 +1250,20 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
1240
1250
_ => unreachable ! ( )
1241
1251
}
1242
1252
}
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) {
1249
1267
Ok ( bound) => bound,
1250
1268
Err ( ErrorReported ) => return ( tcx. types . err , ty_path_def) ,
1251
1269
}
0 commit comments