@@ -7,16 +7,16 @@ use rustc_data_structures::{
7
7
use rustc_middle:: ty:: { self , Ty } ;
8
8
9
9
impl < ' tcx > FnCtxt < ' _ , ' tcx > {
10
- /// Performs type inference fallback, returning true if any fallback
11
- /// occurs .
12
- pub ( super ) fn type_inference_fallback ( & self ) -> bool {
10
+ /// Performs type inference fallback, setting `FnCtxt::fallback_has_occurred`
11
+ /// if fallback has occurred .
12
+ pub ( super ) fn type_inference_fallback ( & self ) {
13
13
debug ! (
14
14
"type-inference-fallback start obligations: {:#?}" ,
15
15
self . fulfillment_cx. borrow_mut( ) . pending_obligations( )
16
16
) ;
17
17
18
18
// All type checking constraints were added, try to fallback unsolved variables.
19
- self . select_obligations_where_possible ( false , |_| { } ) ;
19
+ self . select_obligations_where_possible ( |_| { } ) ;
20
20
21
21
debug ! (
22
22
"type-inference-fallback post selection obligations: {:#?}" ,
@@ -26,18 +26,17 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
26
26
// Check if we have any unsolved variables. If not, no need for fallback.
27
27
let unsolved_variables = self . unsolved_variables ( ) ;
28
28
if unsolved_variables. is_empty ( ) {
29
- return false ;
29
+ return ;
30
30
}
31
31
32
32
let diverging_fallback = self . calculate_diverging_fallback ( & unsolved_variables) ;
33
33
34
- let mut fallback_has_occurred = false ;
35
34
// We do fallback in two passes, to try to generate
36
35
// better error messages.
37
36
// The first time, we do *not* replace opaque types.
38
37
for ty in unsolved_variables {
39
38
debug ! ( "unsolved_variable = {:?}" , ty) ;
40
- fallback_has_occurred |= self . fallback_if_possible ( ty, & diverging_fallback) ;
39
+ self . fallback_if_possible ( ty, & diverging_fallback) ;
41
40
}
42
41
43
42
// We now see if we can make progress. This might cause us to
@@ -63,9 +62,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
63
62
// If we had tried to fallback the opaque inference variable to `MyType`,
64
63
// we will generate a confusing type-check error that does not explicitly
65
64
// refer to opaque types.
66
- self . select_obligations_where_possible ( fallback_has_occurred, |_| { } ) ;
67
-
68
- fallback_has_occurred
65
+ self . select_obligations_where_possible ( |_| { } ) ;
69
66
}
70
67
71
68
// Tries to apply a fallback to `ty` if it is an unsolved variable.
@@ -81,12 +78,13 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
81
78
// Fallback becomes very dubious if we have encountered
82
79
// type-checking errors. In that case, fallback to Error.
83
80
//
84
- // The return value indicates whether fallback has occurred.
81
+ // Sets `FnCtxt::fallback_has_occurred` if fallback is performed
82
+ // during this call.
85
83
fn fallback_if_possible (
86
84
& self ,
87
85
ty : Ty < ' tcx > ,
88
86
diverging_fallback : & FxHashMap < Ty < ' tcx > , Ty < ' tcx > > ,
89
- ) -> bool {
87
+ ) {
90
88
// Careful: we do NOT shallow-resolve `ty`. We know that `ty`
91
89
// is an unsolved variable, and we determine its fallback
92
90
// based solely on how it was created, not what other type
@@ -111,7 +109,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
111
109
ty:: Infer ( ty:: FloatVar ( _) ) => self . tcx . types . f64 ,
112
110
_ => match diverging_fallback. get ( & ty) {
113
111
Some ( & fallback_ty) => fallback_ty,
114
- None => return false ,
112
+ None => return ,
115
113
} ,
116
114
} ;
117
115
debug ! ( "fallback_if_possible(ty={:?}): defaulting to `{:?}`" , ty, fallback) ;
@@ -122,7 +120,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
122
120
. map ( |origin| origin. span )
123
121
. unwrap_or ( rustc_span:: DUMMY_SP ) ;
124
122
self . demand_eqtype ( span, ty, fallback) ;
125
- true
123
+ self . fallback_has_occurred . set ( true ) ;
126
124
}
127
125
128
126
/// The "diverging fallback" system is rather complicated. This is
0 commit comments