Skip to content

Commit c6f2ddf

Browse files
committed
Fix rebase and add comments
1 parent dc53cfe commit c6f2ddf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/rustc_typeck/src/check/_match.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_infer::traits::Obligation;
66
use rustc_middle::ty::{self, ToPredicate, Ty};
77
use rustc_span::Span;
88
use rustc_trait_selection::opaque_types::InferCtxtExt as _;
9-
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
9+
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
1010
use rustc_trait_selection::traits::{
1111
IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode,
1212
};
@@ -153,12 +153,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
153153
);
154154
suggest_box &= self.infcx.predicate_must_hold_modulo_regions(&obl);
155155
if !suggest_box {
156+
// We've encountered some obligation that didn't hold, so the
157+
// return expression can't just be boxed. We don't need to
158+
// evaluate the rest of the obligations.
156159
break;
157160
}
158161
}
159162
_ => {}
160163
}
161164
}
165+
// If all the obligations hold (or there are no obligations) the tail expression
166+
// we can suggest to return a boxed trait object instead of an opaque type.
162167
if suggest_box { self.ret_type_span.clone() } else { None }
163168
}
164169
_ => None,

0 commit comments

Comments
 (0)