@@ -232,7 +232,7 @@ pub struct Inherited<'a, 'tcx> {
232
232
opaque_types : RefCell < DefIdMap < OpaqueTypeDecl < ' tcx > > > ,
233
233
234
234
/// A map from inference variables created from opaque
235
- /// type instantiations (ty::Infer) to the actual opaque
235
+ /// type instantiations (` ty::Infer` ) to the actual opaque
236
236
/// type (`ty::Opaque`). Used during fallback to map unconstrained
237
237
/// opaque type inference variables to their corresponding
238
238
/// opaque type.
@@ -950,7 +950,7 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
950
950
// better error messages.
951
951
// The first time, we do *not* replace opaque types.
952
952
for ty in & fcx. unsolved_variables ( ) {
953
- fallback_has_occurred |= fcx. fallback_if_possible ( ty, false /* opaque_fallback */ ) ;
953
+ fallback_has_occurred |= fcx. fallback_if_possible ( ty, FallbackMode :: NoOpaque ) ;
954
954
}
955
955
// We now see if we can make progress. This might
956
956
// cause us to unify inference variables for opaque types,
@@ -968,7 +968,7 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
968
968
// ```
969
969
//
970
970
// we want to unify the opaque inference variable in `bad_produce`
971
- // with the diverging fallback for `panic!` (e.g. `()` or `!`),
971
+ // with the diverging fallback for `panic!` (e.g. `()` or `!`).
972
972
// This will produce a nice error message about conflicting concrete
973
973
// types for `MyType`.
974
974
//
@@ -981,10 +981,10 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
981
981
// unconstrained opaque type variables, in addition to performing
982
982
// other kinds of fallback.
983
983
for ty in & fcx. unsolved_variables ( ) {
984
- fallback_has_occurred |= fcx. fallback_if_possible ( ty, true /* opaque_fallback */ ) ;
984
+ fallback_has_occurred |= fcx. fallback_if_possible ( ty, FallbackMode :: All ) ;
985
985
}
986
986
987
- // See if we can make any more progress
987
+ // See if we can make any more progress.
988
988
fcx. select_obligations_where_possible ( fallback_has_occurred, |_| { } ) ;
989
989
990
990
// Even though coercion casts provide type hints, we check casts after fallback for
@@ -2544,6 +2544,16 @@ enum TupleArgumentsFlag {
2544
2544
TupleArguments ,
2545
2545
}
2546
2546
2547
+ /// Controls how we perform fallback for unconstrained
2548
+ /// type variables.
2549
+ enum FallbackMode {
2550
+ /// Do not fallback type variables to opaque types.
2551
+ NoOpaque ,
2552
+ /// Perform all possible kinds of fallback, including
2553
+ /// turning type variables to opaque types.
2554
+ All ,
2555
+ }
2556
+
2547
2557
impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
2548
2558
pub fn new (
2549
2559
inh : & ' a Inherited < ' a , ' tcx > ,
@@ -3125,7 +3135,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3125
3135
// Fallback becomes very dubious if we have encountered type-checking errors.
3126
3136
// In that case, fallback to Error.
3127
3137
// The return value indicates whether fallback has occurred.
3128
- fn fallback_if_possible ( & self , ty : Ty < ' tcx > , opaque_fallback : bool ) -> bool {
3138
+ fn fallback_if_possible ( & self , ty : Ty < ' tcx > , mode : FallbackMode ) -> bool {
3129
3139
use rustc:: ty:: error:: UnconstrainedNumeric :: Neither ;
3130
3140
use rustc:: ty:: error:: UnconstrainedNumeric :: { UnconstrainedInt , UnconstrainedFloat } ;
3131
3141
@@ -3170,7 +3180,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3170
3180
// instantiating `Option<Foo>` will be completely unconstrained.
3171
3181
// We treat this as a non-defining use by making the inference
3172
3182
// variable fall back to the opaque type itself.
3173
- if opaque_fallback {
3183
+ if let FallbackMode :: All = mode {
3174
3184
if let Some ( opaque_ty) = self . opaque_types_vars . borrow ( ) . get ( ty) {
3175
3185
debug ! ( "fallback_if_possible: falling back opaque type var {:?} to {:?}" ,
3176
3186
ty, opaque_ty) ;
0 commit comments