@@ -278,14 +278,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
278
278
} )
279
279
} ;
280
280
281
+ // If we encountered an `_` type or an error type during autoderef, this is
282
+ // ambiguous.
281
283
if let Some ( CreateStepsBadTy { reached_raw_pointer, ty } ) = & steps. opt_bad_ty {
282
- // Ended in an inference variable. If we are doing
283
- // a real method lookup, this is a hard error because it's
284
- // possible that there will be multiple applicable methods.
285
- if !is_suggestion. 0
286
- && * reached_raw_pointer
287
- && !self . tcx . features ( ) . arbitrary_self_types
288
- {
284
+ if is_suggestion. 0 {
285
+ // Ambiguity was encountered during a suggestion. Just keep going.
286
+ debug ! ( "ProbeContext: encountered ambiguity in suggestion" ) ;
287
+ } else if * reached_raw_pointer && !self . tcx . features ( ) . arbitrary_self_types {
289
288
// this case used to be allowed by the compiler,
290
289
// so we do a future-compat lint here for the 2015 edition
291
290
// (see https://github.com/rust-lang/rust/issues/46906)
@@ -301,6 +300,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
301
300
"type annotations needed" ) ;
302
301
}
303
302
} else {
303
+ // Encountered a real ambiguity, so abort the lookup. If `ty` is not
304
+ // an `Err`, report the right "type annotations needed" error pointing
305
+ // to it.
304
306
let ty = do_instantiate_query_result ( self , span, & orig_values, ty)
305
307
. unwrap_or_else ( |_| span_bug ! ( span, "instantiating {:?} failed?" , ty) ) ;
306
308
let t = self . structurally_resolved_type ( span, ty. value ) ;
@@ -310,7 +312,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
310
312
Vec :: new ( ) ,
311
313
None ,
312
314
mode) ) ) ;
313
-
314
315
}
315
316
}
316
317
@@ -392,7 +393,7 @@ fn create_steps_inner<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
392
393
let mut steps: Vec < _ > = autoderef. by_ref ( )
393
394
. map ( |( ty, d) | {
394
395
let step = CandidateStep {
395
- self_ty : do_make_query_result ( infcx, & inference_vars, infcx . tcx . mk_slice ( ty ) ) ,
396
+ self_ty : do_make_query_result ( infcx, & inference_vars, ty ) ,
396
397
autoderefs : d,
397
398
from_unsafe_deref : reached_raw_pointer,
398
399
unsize : false ,
0 commit comments