Skip to content

Commit 965feb1

Browse files
committed
track never type fallback specifically
the only diagnostic that was using this field specifically сares for the never type fallback, not the integer fallback.
1 parent e492343 commit 965feb1

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

compiler/rustc_hir_typeck/src/fallback.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ pub(crate) enum DivergingFallbackBehavior {
3131
}
3232

3333
impl<'tcx> FnCtxt<'_, 'tcx> {
34-
/// Performs type inference fallback, setting `FnCtxt::fallback_has_occurred`
35-
/// if fallback has occurred.
34+
/// Performs type inference fallback, setting [`FnCtxt::diverging_fallback_has_occurred`]
35+
/// if the never type fallback has occurred.
3636
pub(super) fn type_inference_fallback(&self) {
3737
debug!(
3838
"type-inference-fallback start obligations: {:#?}",
@@ -115,8 +115,8 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
115115
/// Fallback becomes very dubious if we have encountered
116116
/// type-checking errors. In that case, fallback to Error.
117117
///
118-
/// Sets [`FnCtxt::fallback_has_occurred`] if fallback is performed
119-
/// during this call.
118+
/// Sets [`FnCtxt::diverging_fallback_has_occurred`] if never type fallback
119+
/// is performed during this call.
120120
fn fallback_if_possible(
121121
&self,
122122
ty: Ty<'tcx>,
@@ -145,15 +145,17 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
145145
ty::Infer(ty::IntVar(_)) => self.tcx.types.i32,
146146
ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64,
147147
_ => match diverging_fallback.get(&ty) {
148-
Some(&fallback_ty) => fallback_ty,
148+
Some(&fallback_ty) => {
149+
self.diverging_fallback_has_occurred.set(true);
150+
fallback_ty
151+
}
149152
None => return false,
150153
},
151154
};
152155
debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback);
153156

154157
let span = ty.ty_vid().map_or(DUMMY_SP, |vid| self.infcx.type_var_origin(vid).span);
155158
self.demand_eqtype(span, ty, fallback);
156-
self.fallback_has_occurred.set(true);
157159
true
158160
}
159161

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ pub(crate) struct FnCtxt<'a, 'tcx> {
115115

116116
pub(super) root_ctxt: &'a TypeckRootCtxt<'tcx>,
117117

118-
pub(super) fallback_has_occurred: Cell<bool>,
118+
/// True if a divirging inference variable has been set to `()`/`!` because
119+
/// of never type fallback. This is only used for diagnostics.
120+
pub(super) diverging_fallback_has_occurred: Cell<bool>,
119121

120122
pub(super) diverging_fallback_behavior: DivergingFallbackBehavior,
121123
pub(super) diverging_block_behavior: DivergingBlockBehavior,
@@ -153,7 +155,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
153155
by_id: Default::default(),
154156
}),
155157
root_ctxt,
156-
fallback_has_occurred: Cell::new(false),
158+
diverging_fallback_has_occurred: Cell::new(false),
157159
diverging_fallback_behavior,
158160
diverging_block_behavior,
159161
trait_ascriptions: Default::default(),
@@ -190,7 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
190192
TypeErrCtxt {
191193
infcx: &self.infcx,
192194
typeck_results: Some(self.typeck_results.borrow()),
193-
fallback_has_occurred: self.fallback_has_occurred.get(),
195+
diverging_fallback_has_occurred: self.diverging_fallback_has_occurred.get(),
194196
normalize_fn_sig: Box::new(|fn_sig| {
195197
if fn_sig.has_escaping_bound_vars() {
196198
return fn_sig;

compiler/rustc_trait_selection/src/error_reporting/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct TypeErrCtxt<'a, 'tcx> {
2121
pub infcx: &'a InferCtxt<'tcx>,
2222

2323
pub typeck_results: Option<std::cell::Ref<'a, ty::TypeckResults<'tcx>>>,
24-
pub fallback_has_occurred: bool,
24+
pub diverging_fallback_has_occurred: bool,
2525

2626
pub normalize_fn_sig: Box<dyn Fn(ty::PolyFnSig<'tcx>) -> ty::PolyFnSig<'tcx> + 'a>,
2727

@@ -36,7 +36,7 @@ impl<'tcx> InferCtxt<'tcx> {
3636
TypeErrCtxt {
3737
infcx: self,
3838
typeck_results: None,
39-
fallback_has_occurred: false,
39+
diverging_fallback_has_occurred: false,
4040
normalize_fn_sig: Box::new(|fn_sig| fn_sig),
4141
autoderef_steps: Box::new(|ty| {
4242
debug_assert!(false, "shouldn't be using autoderef_steps outside of typeck");

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
541541
// variable that used to fallback to `()` now falling back to `!`. Issue a
542542
// note informing about the change in behaviour.
543543
if leaf_trait_predicate.skip_binder().self_ty().is_never()
544-
&& self.fallback_has_occurred
544+
&& self.diverging_fallback_has_occurred
545545
{
546546
let predicate = leaf_trait_predicate.map_bound(|trait_pred| {
547547
trait_pred.with_replaced_self_ty(self.tcx, tcx.types.unit)

0 commit comments

Comments
 (0)