From c6f2ddf1cb1e328245da59a4fb42f90403389a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 11 Sep 2020 17:20:56 -0700 Subject: [PATCH] Fix rebase and add comments --- compiler/rustc_typeck/src/check/_match.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index 08cf178c813..836a4ff78c7 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -6,7 +6,7 @@ use rustc_infer::traits::Obligation; use rustc_middle::ty::{self, ToPredicate, Ty}; use rustc_span::Span; use rustc_trait_selection::opaque_types::InferCtxtExt as _; -use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; +use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; use rustc_trait_selection::traits::{ IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode, }; @@ -153,12 +153,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); suggest_box &= self.infcx.predicate_must_hold_modulo_regions(&obl); if !suggest_box { + // We've encountered some obligation that didn't hold, so the + // return expression can't just be boxed. We don't need to + // evaluate the rest of the obligations. break; } } _ => {} } } + // If all the obligations hold (or there are no obligations) the tail expression + // we can suggest to return a boxed trait object instead of an opaque type. if suggest_box { self.ret_type_span.clone() } else { None } } _ => None,