Skip to content

Commit

Permalink
Structurally resolve before adjust_for_branches
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 28, 2024
1 parent c322cd5 commit 4a70611
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// type in that case)
let mut all_arms_diverge = Diverges::WarnedAlways;

let expected = orig_expected.adjust_for_branches(self);
let expected = orig_expected.adjust_for_branches(self, expr.span);
debug!(?expected);

let mut coercion = {
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_hir_typeck/src/expectation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ impl<'a, 'tcx> Expectation<'tcx> {
// an expected type. Otherwise, we might write parts of the type
// when checking the 'then' block which are incompatible with the
// 'else' branch.
pub(super) fn adjust_for_branches(&self, fcx: &FnCtxt<'a, 'tcx>) -> Expectation<'tcx> {
pub(super) fn adjust_for_branches(
&self,
fcx: &FnCtxt<'a, 'tcx>,
span: Span,
) -> Expectation<'tcx> {
match *self {
ExpectHasType(ety) => {
let ety = fcx.shallow_resolve(ety);
let ety = fcx.try_structurally_resolve_type(span, ety);
if !ety.is_ty_var() { ExpectHasType(ety) } else { NoExpectation }
}
ExpectRvalueLikeUnsized(ety) => ExpectRvalueLikeUnsized(ety),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let cond_diverges = self.diverges.get();
self.diverges.set(Diverges::Maybe);

let expected = orig_expected.adjust_for_branches(self);
let expected = orig_expected.adjust_for_branches(self, sp);
let then_ty = self.check_expr_with_expectation(then_expr, expected);
let then_diverges = self.diverges.get();
self.diverges.set(Diverges::Maybe);
Expand Down

0 comments on commit 4a70611

Please sign in to comment.