@@ -858,17 +858,19 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
858858 fcx
859859 } ;
860860
861- fcx. check_casts ( ) ;
862-
863861 // All type checking constraints were added, try to fallback unsolved variables.
864862 fcx. select_obligations_where_possible ( ) ;
865863 for ty in & fcx. unsolved_variables ( ) {
866- fcx. fallback_if_possible ( ty, Fallback :: Full ) ;
864+ fcx. fallback_if_possible ( ty) ;
867865 }
868866 fcx. select_obligations_where_possible ( ) ;
869867
868+ // Even though coercion casts provide type hints, we check casts after fallback for
869+ // backwards compatibility. This makes fallback a stronger type hint than a cast coercion.
870+ fcx. check_casts ( ) ;
871+
870872 // Closure and generater analysis may run after fallback
871- // because they doen 't constrain other type variables.
873+ // because they don 't constrain other type variables.
872874 fcx. closure_analyze ( body) ;
873875 assert ! ( fcx. deferred_call_resolutions. borrow( ) . is_empty( ) ) ;
874876 fcx. resolve_generator_interiors ( def_id) ;
@@ -1734,12 +1736,6 @@ enum TupleArgumentsFlag {
17341736 TupleArguments ,
17351737}
17361738
1737- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
1738- pub enum Fallback {
1739- Full ,
1740- Numeric
1741- }
1742-
17431739impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
17441740 pub fn new ( inh : & ' a Inherited < ' a , ' gcx , ' tcx > ,
17451741 param_env : ty:: ParamEnv < ' tcx > ,
@@ -2149,7 +2145,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21492145 // unconstrained floats with f64.
21502146 // Fallback becomes very dubious if we have encountered type-checking errors.
21512147 // In that case, fallback to TyError.
2152- fn fallback_if_possible ( & self , ty : Ty < ' tcx > , fallback : Fallback ) {
2148+ fn fallback_if_possible ( & self , ty : Ty < ' tcx > ) {
21532149 use rustc:: ty:: error:: UnconstrainedNumeric :: Neither ;
21542150 use rustc:: ty:: error:: UnconstrainedNumeric :: { UnconstrainedInt , UnconstrainedFloat } ;
21552151
@@ -2158,12 +2154,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21582154 _ if self . is_tainted_by_errors ( ) => self . tcx ( ) . types . err ,
21592155 UnconstrainedInt => self . tcx . types . i32 ,
21602156 UnconstrainedFloat => self . tcx . types . f64 ,
2161- Neither if self . type_var_diverges ( ty) => {
2162- match fallback {
2163- Fallback :: Full => self . tcx . mk_diverging_default ( ) ,
2164- Fallback :: Numeric => return ,
2165- }
2166- }
2157+ Neither if self . type_var_diverges ( ty) => self . tcx . mk_diverging_default ( ) ,
21672158 Neither => return
21682159 } ;
21692160 debug ! ( "default_type_parameters: defaulting `{:?}` to `{:?}`" , ty, fallback) ;
0 commit comments