@@ -244,20 +244,7 @@ where
244
244
. map ( |pred| goal. with ( cx, pred) ) ,
245
245
) ;
246
246
247
- // In case the associated item is hidden due to specialization, we have to
248
- // return ambiguity this would otherwise be incomplete, resulting in
249
- // unsoundness during coherence (#105782).
250
- let Some ( target_item_def_id) = ecx. fetch_eligible_assoc_item (
251
- goal_trait_ref,
252
- goal. predicate . def_id ( ) ,
253
- impl_def_id,
254
- ) ?
255
- else {
256
- return ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS ) ;
257
- } ;
258
-
259
- let error_response = |ecx : & mut EvalCtxt < ' _ , D > , msg : & str | {
260
- let guar = cx. delay_bug ( msg) ;
247
+ let error_response = |ecx : & mut EvalCtxt < ' _ , D > , guar| {
261
248
let error_term = match goal. predicate . alias . kind ( cx) {
262
249
ty:: AliasTermKind :: ProjectionTy => Ty :: new_error ( cx, guar) . into ( ) ,
263
250
ty:: AliasTermKind :: ProjectionConst => Const :: new_error ( cx, guar) . into ( ) ,
@@ -267,8 +254,24 @@ where
267
254
ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
268
255
} ;
269
256
257
+ // In case the associated item is hidden due to specialization, we have to
258
+ // return ambiguity this would otherwise be incomplete, resulting in
259
+ // unsoundness during coherence (#105782).
260
+ let target_item_def_id = match ecx. fetch_eligible_assoc_item (
261
+ goal_trait_ref,
262
+ goal. predicate . def_id ( ) ,
263
+ impl_def_id,
264
+ ) {
265
+ Ok ( Some ( target_item_def_id) ) => target_item_def_id,
266
+ Ok ( None ) => {
267
+ return ecx
268
+ . evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS ) ;
269
+ }
270
+ Err ( guar) => return error_response ( ecx, guar) ,
271
+ } ;
272
+
270
273
if !cx. has_item_definition ( target_item_def_id) {
271
- return error_response ( ecx, "missing item" ) ;
274
+ return error_response ( ecx, cx . delay_bug ( "missing item" ) ) ;
272
275
}
273
276
274
277
let target_container_def_id = cx. parent ( target_item_def_id) ;
@@ -292,7 +295,10 @@ where
292
295
) ?;
293
296
294
297
if !cx. check_args_compatible ( target_item_def_id, target_args) {
295
- return error_response ( ecx, "associated item has mismatched arguments" ) ;
298
+ return error_response (
299
+ ecx,
300
+ cx. delay_bug ( "associated item has mismatched arguments" ) ,
301
+ ) ;
296
302
}
297
303
298
304
// Finally we construct the actual value of the associated type.
0 commit comments