Skip to content

Commit f549cac

Browse files
committed
Destructure InferenceResult in resolve_all()
so that whenever new fields are added we don't forget to handle them.
1 parent a3789ea commit f549cac

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

crates/hir-ty/src/infer.rs

+35-13
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,31 @@ impl<'a> InferenceContext<'a> {
579579
// used this function for another workaround, mention it here. If you really need this function and believe that
580580
// there is no problem in it being `pub(crate)`, remove this comment.
581581
pub(crate) fn resolve_all(self) -> InferenceResult {
582-
// NOTE: `InferenceResult::closure_info` is `resolve_completely()`'d during
583-
// `InferenceContext::infer_closures()` (in `HirPlace::ty()` specifically).
584582
let InferenceContext { mut table, mut result, .. } = self;
583+
// Destructure every single field so whenever new fields are added to `InferenceResult` we
584+
// don't forget to handle them here.
585+
let InferenceResult {
586+
method_resolutions,
587+
field_resolutions: _,
588+
variant_resolutions: _,
589+
assoc_resolutions,
590+
diagnostics,
591+
type_of_expr,
592+
type_of_pat,
593+
type_of_binding,
594+
type_of_rpit,
595+
type_of_for_iterator,
596+
type_mismatches,
597+
standard_types: _,
598+
pat_adjustments,
599+
binding_modes: _,
600+
expr_adjustments,
601+
// Types in `closure_info` have already been `resolve_completely()`'d during
602+
// `InferenceContext::infer_closures()` (in `HirPlace::ty()` specifically), so no need
603+
// to resolve them here.
604+
closure_info: _,
605+
mutated_bindings_in_closure: _,
606+
} = &mut result;
585607

586608
table.fallback_if_possible();
587609

@@ -590,26 +612,26 @@ impl<'a> InferenceContext<'a> {
590612

591613
// make sure diverging type variables are marked as such
592614
table.propagate_diverging_flag();
593-
for ty in result.type_of_expr.values_mut() {
615+
for ty in type_of_expr.values_mut() {
594616
*ty = table.resolve_completely(ty.clone());
595617
}
596-
for ty in result.type_of_pat.values_mut() {
618+
for ty in type_of_pat.values_mut() {
597619
*ty = table.resolve_completely(ty.clone());
598620
}
599-
for ty in result.type_of_binding.values_mut() {
621+
for ty in type_of_binding.values_mut() {
600622
*ty = table.resolve_completely(ty.clone());
601623
}
602-
for ty in result.type_of_rpit.values_mut() {
624+
for ty in type_of_rpit.values_mut() {
603625
*ty = table.resolve_completely(ty.clone());
604626
}
605-
for ty in result.type_of_for_iterator.values_mut() {
627+
for ty in type_of_for_iterator.values_mut() {
606628
*ty = table.resolve_completely(ty.clone());
607629
}
608-
for mismatch in result.type_mismatches.values_mut() {
630+
for mismatch in type_mismatches.values_mut() {
609631
mismatch.expected = table.resolve_completely(mismatch.expected.clone());
610632
mismatch.actual = table.resolve_completely(mismatch.actual.clone());
611633
}
612-
result.diagnostics.retain_mut(|diagnostic| {
634+
diagnostics.retain_mut(|diagnostic| {
613635
use InferenceDiagnostic::*;
614636
match diagnostic {
615637
ExpectedFunction { found: ty, .. }
@@ -637,16 +659,16 @@ impl<'a> InferenceContext<'a> {
637659
}
638660
true
639661
});
640-
for (_, subst) in result.method_resolutions.values_mut() {
662+
for (_, subst) in method_resolutions.values_mut() {
641663
*subst = table.resolve_completely(subst.clone());
642664
}
643-
for (_, subst) in result.assoc_resolutions.values_mut() {
665+
for (_, subst) in assoc_resolutions.values_mut() {
644666
*subst = table.resolve_completely(subst.clone());
645667
}
646-
for adjustment in result.expr_adjustments.values_mut().flatten() {
668+
for adjustment in expr_adjustments.values_mut().flatten() {
647669
adjustment.target = table.resolve_completely(adjustment.target.clone());
648670
}
649-
for adjustment in result.pat_adjustments.values_mut().flatten() {
671+
for adjustment in pat_adjustments.values_mut().flatten() {
650672
*adjustment = table.resolve_completely(adjustment.clone());
651673
}
652674
result

0 commit comments

Comments
 (0)