@@ -75,6 +75,7 @@ mod diverges;
75
75
pub mod dropck;
76
76
mod expectation;
77
77
mod expr;
78
+ mod fallback;
78
79
mod fn_ctxt;
79
80
mod gather_locals;
80
81
mod generator_interior;
@@ -445,50 +446,7 @@ fn typeck_with_fallback<'tcx>(
445
446
fcx
446
447
} ;
447
448
448
- // All type checking constraints were added, try to fallback unsolved variables.
449
- fcx. select_obligations_where_possible ( false , |_| { } ) ;
450
- let mut fallback_has_occurred = false ;
451
-
452
- // We do fallback in two passes, to try to generate
453
- // better error messages.
454
- // The first time, we do *not* replace opaque types.
455
- for ty in & fcx. unsolved_variables ( ) {
456
- fallback_has_occurred |= fcx. fallback_if_possible ( ty, FallbackMode :: NoOpaque ) ;
457
- }
458
- // We now see if we can make progress. This might
459
- // cause us to unify inference variables for opaque types,
460
- // since we may have unified some other type variables
461
- // during the first phase of fallback.
462
- // This means that we only replace inference variables with their underlying
463
- // opaque types as a last resort.
464
- //
465
- // In code like this:
466
- //
467
- // ```rust
468
- // type MyType = impl Copy;
469
- // fn produce() -> MyType { true }
470
- // fn bad_produce() -> MyType { panic!() }
471
- // ```
472
- //
473
- // we want to unify the opaque inference variable in `bad_produce`
474
- // with the diverging fallback for `panic!` (e.g. `()` or `!`).
475
- // This will produce a nice error message about conflicting concrete
476
- // types for `MyType`.
477
- //
478
- // If we had tried to fallback the opaque inference variable to `MyType`,
479
- // we will generate a confusing type-check error that does not explicitly
480
- // refer to opaque types.
481
- fcx. select_obligations_where_possible ( fallback_has_occurred, |_| { } ) ;
482
-
483
- // We now run fallback again, but this time we allow it to replace
484
- // unconstrained opaque type variables, in addition to performing
485
- // other kinds of fallback.
486
- for ty in & fcx. unsolved_variables ( ) {
487
- fallback_has_occurred |= fcx. fallback_if_possible ( ty, FallbackMode :: All ) ;
488
- }
489
-
490
- // See if we can make any more progress.
491
- fcx. select_obligations_where_possible ( fallback_has_occurred, |_| { } ) ;
449
+ fcx. type_inference_fallback ( ) ;
492
450
493
451
// Even though coercion casts provide type hints, we check casts after fallback for
494
452
// backwards compatibility. This makes fallback a stronger type hint than a cast coercion.
0 commit comments