Skip to content

Commit 9297826

Browse files
committed
only return true in `fallback_types' if fallback has occurred
1 parent 75cfeb1 commit 9297826

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

compiler/rustc_hir_typeck/src/fallback.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
2424
self.fulfillment_cx.borrow_mut().pending_obligations()
2525
);
2626

27-
let fallback_occured = self.fallback_types() | self.fallback_effects();
27+
let fallback_occurred = self.fallback_types() | self.fallback_effects();
2828

29-
if !fallback_occured {
29+
if !fallback_occurred {
3030
return;
3131
}
3232

@@ -69,14 +69,13 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
6969
// We do fallback in two passes, to try to generate
7070
// better error messages.
7171
// The first time, we do *not* replace opaque types.
72-
//
73-
// TODO: We return `true` even if no fallback occurs.
72+
let mut fallback_occurred = false;
7473
for ty in unresolved_variables {
7574
debug!("unsolved_variable = {:?}", ty);
76-
self.fallback_if_possible(ty, &diverging_fallback);
75+
fallback_occurred |= self.fallback_if_possible(ty, &diverging_fallback);
7776
}
7877

79-
true
78+
fallback_occurred
8079
}
8180

8281
fn fallback_effects(&self) -> bool {
@@ -86,9 +85,8 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
8685
return false;
8786
}
8887

89-
// not setting `fallback_has_occured` here because that field is only used for type fallback
90-
// diagnostics.
91-
88+
// not setting the `fallback_has_occured` field here because
89+
// that field is only used for type fallback diagnostics.
9290
for effect in unsolved_effects {
9391
let expected = self.tcx.consts.true_;
9492
let cause = self.misc(rustc_span::DUMMY_SP);
@@ -124,7 +122,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
124122
&self,
125123
ty: Ty<'tcx>,
126124
diverging_fallback: &UnordMap<Ty<'tcx>, Ty<'tcx>>,
127-
) {
125+
) -> bool {
128126
// Careful: we do NOT shallow-resolve `ty`. We know that `ty`
129127
// is an unsolved variable, and we determine its fallback
130128
// based solely on how it was created, not what other type
@@ -149,7 +147,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
149147
ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64,
150148
_ => match diverging_fallback.get(&ty) {
151149
Some(&fallback_ty) => fallback_ty,
152-
None => return,
150+
None => return false,
153151
},
154152
};
155153
debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback);
@@ -161,6 +159,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
161159
.unwrap_or(rustc_span::DUMMY_SP);
162160
self.demand_eqtype(span, ty, fallback);
163161
self.fallback_has_occurred.set(true);
162+
true
164163
}
165164

166165
/// The "diverging fallback" system is rather complicated. This is

0 commit comments

Comments
 (0)