@@ -873,11 +873,12 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
873873 } ;
874874
875875 // All type checking constraints were added, try to fallback unsolved variables.
876- fcx. select_obligations_where_possible ( ) ;
876+ fcx. select_obligations_where_possible ( false ) ;
877+ let mut fallback_has_occurred = false ;
877878 for ty in & fcx. unsolved_variables ( ) {
878- fcx. fallback_if_possible ( ty) ;
879+ fallback_has_occurred |= fcx. fallback_if_possible ( ty) ;
879880 }
880- fcx. select_obligations_where_possible ( ) ;
881+ fcx. select_obligations_where_possible ( fallback_has_occurred ) ;
881882
882883 // Even though coercion casts provide type hints, we check casts after fallback for
883884 // backwards compatibility. This makes fallback a stronger type hint than a cast coercion.
@@ -1837,7 +1838,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
18371838 // possible. This can help substantially when there are
18381839 // indirect dependencies that don't seem worth tracking
18391840 // precisely.
1840- self . select_obligations_where_possible ( ) ;
1841+ self . select_obligations_where_possible ( false ) ;
18411842 ty = self . resolve_type_vars_if_possible ( & ty) ;
18421843
18431844 debug ! ( "resolve_type_vars_with_obligations: ty={:?}" , ty) ;
@@ -2154,7 +2155,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21542155 fn resolve_generator_interiors ( & self , def_id : DefId ) {
21552156 let mut generators = self . deferred_generator_interiors . borrow_mut ( ) ;
21562157 for ( body_id, interior) in generators. drain ( ..) {
2157- self . select_obligations_where_possible ( ) ;
2158+ self . select_obligations_where_possible ( false ) ;
21582159 generator_interior:: resolve_interior ( self , def_id, body_id, interior) ;
21592160 }
21602161 }
@@ -2164,7 +2165,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21642165 // unconstrained floats with f64.
21652166 // Fallback becomes very dubious if we have encountered type-checking errors.
21662167 // In that case, fallback to TyError.
2167- fn fallback_if_possible ( & self , ty : Ty < ' tcx > ) {
2168+ // The return value indicates whether fallback has occured.
2169+ fn fallback_if_possible ( & self , ty : Ty < ' tcx > ) -> bool {
21682170 use rustc:: ty:: error:: UnconstrainedNumeric :: Neither ;
21692171 use rustc:: ty:: error:: UnconstrainedNumeric :: { UnconstrainedInt , UnconstrainedFloat } ;
21702172
@@ -2174,24 +2176,27 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21742176 UnconstrainedInt => self . tcx . types . i32 ,
21752177 UnconstrainedFloat => self . tcx . types . f64 ,
21762178 Neither if self . type_var_diverges ( ty) => self . tcx . types . never ,
2177- Neither => return
2179+ Neither => return false ,
21782180 } ;
21792181 debug ! ( "default_type_parameters: defaulting `{:?}` to `{:?}`" , ty, fallback) ;
21802182 self . demand_eqtype ( syntax_pos:: DUMMY_SP , ty, fallback) ;
2183+ true
21812184 }
21822185
21832186 fn select_all_obligations_or_error ( & self ) {
21842187 debug ! ( "select_all_obligations_or_error" ) ;
21852188 if let Err ( errors) = self . fulfillment_cx . borrow_mut ( ) . select_all_or_error ( & self ) {
2186- self . report_fulfillment_errors ( & errors, self . inh . body_id ) ;
2189+ self . report_fulfillment_errors ( & errors, self . inh . body_id , false ) ;
21872190 }
21882191 }
21892192
21902193 /// Select as many obligations as we can at present.
2191- fn select_obligations_where_possible ( & self ) {
2194+ fn select_obligations_where_possible ( & self , fallback_has_occurred : bool ) {
21922195 match self . fulfillment_cx . borrow_mut ( ) . select_where_possible ( self ) {
21932196 Ok ( ( ) ) => { }
2194- Err ( errors) => { self . report_fulfillment_errors ( & errors, self . inh . body_id ) ; }
2197+ Err ( errors) => {
2198+ self . report_fulfillment_errors ( & errors, self . inh . body_id , fallback_has_occurred) ;
2199+ } ,
21952200 }
21962201 }
21972202
@@ -2595,7 +2600,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
25952600 // an "opportunistic" vtable resolution of any trait bounds on
25962601 // the call. This helps coercions.
25972602 if check_closures {
2598- self . select_obligations_where_possible ( ) ;
2603+ self . select_obligations_where_possible ( false ) ;
25992604 }
26002605
26012606 // For variadic functions, we don't have a declared type for all of
0 commit comments