Skip to content

Commit 5c2ac69

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

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

compiler/rustc_hir_typeck/src/fallback.rs

+13-12
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,10 +85,11 @@ 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.
90+
let mut fallback_occurred = false;
9291
for effect in unsolved_effects {
92+
fallback_occurred = true;
9393
let expected = self.tcx.consts.true_;
9494
let cause = self.misc(rustc_span::DUMMY_SP);
9595
match self.at(&cause, self.param_env).eq(DefineOpaqueTypes::Yes, expected, effect) {
@@ -102,7 +102,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
102102
}
103103
}
104104

105-
true
105+
fallback_occurred
106106
}
107107

108108
// Tries to apply a fallback to `ty` if it is an unsolved variable.
@@ -124,7 +124,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
124124
&self,
125125
ty: Ty<'tcx>,
126126
diverging_fallback: &UnordMap<Ty<'tcx>, Ty<'tcx>>,
127-
) {
127+
) -> bool {
128128
// Careful: we do NOT shallow-resolve `ty`. We know that `ty`
129129
// is an unsolved variable, and we determine its fallback
130130
// based solely on how it was created, not what other type
@@ -149,7 +149,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
149149
ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64,
150150
_ => match diverging_fallback.get(&ty) {
151151
Some(&fallback_ty) => fallback_ty,
152-
None => return,
152+
None => return false,
153153
},
154154
};
155155
debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback);
@@ -161,6 +161,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
161161
.unwrap_or(rustc_span::DUMMY_SP);
162162
self.demand_eqtype(span, ty, fallback);
163163
self.fallback_has_occurred.set(true);
164+
true
164165
}
165166

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

0 commit comments

Comments
 (0)