1
Fork 0

Cleanup retrieve_closure_constraint_info

This commit is contained in:
Jack Huey 2022-08-29 21:39:53 -04:00
parent 2be6301857
commit ff623ffc39
2 changed files with 30 additions and 42 deletions

View file

@ -73,7 +73,7 @@ impl<'tcx> Index<OutlivesConstraintIndex> for OutlivesConstraintSet<'tcx> {
} }
} }
#[derive(Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]
pub struct OutlivesConstraint<'tcx> { pub struct OutlivesConstraint<'tcx> {
// NB. The ordering here is not significant for correctness, but // NB. The ordering here is not significant for correctness, but
// it is for convenience. Before we dump the constraints in the // it is for convenience. Before we dump the constraints in the

View file

@ -1801,35 +1801,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
pub(crate) fn retrieve_closure_constraint_info( pub(crate) fn retrieve_closure_constraint_info(
&self, &self,
constraint: &OutlivesConstraint<'tcx>, constraint: OutlivesConstraint<'tcx>,
) -> BlameConstraint<'tcx> { ) -> Option<(ConstraintCategory<'tcx>, Span)> {
let loc = match constraint.locations { match constraint.locations {
Locations::All(span) => { Locations::All(_) => None,
return BlameConstraint { Locations::Single(loc) => {
category: constraint.category, self.closure_bounds_mapping[&loc].get(&(constraint.sup, constraint.sub)).copied()
from_closure: false, }
cause: ObligationCause::dummy_with_span(span),
variance_info: constraint.variance_info,
};
} }
Locations::Single(loc) => loc,
};
let opt_span_category =
self.closure_bounds_mapping[&loc].get(&(constraint.sup, constraint.sub));
opt_span_category
.map(|&(category, span)| BlameConstraint {
category,
from_closure: true,
cause: ObligationCause::dummy_with_span(span),
variance_info: constraint.variance_info,
})
.unwrap_or(BlameConstraint {
category: constraint.category,
from_closure: false,
cause: ObligationCause::dummy_with_span(constraint.span),
variance_info: constraint.variance_info,
})
} }
/// Finds a good `ObligationCause` to blame for the fact that `fr1` outlives `fr2`. /// Finds a good `ObligationCause` to blame for the fact that `fr1` outlives `fr2`.
@ -2072,19 +2051,28 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let mut categorized_path: Vec<BlameConstraint<'tcx>> = path let mut categorized_path: Vec<BlameConstraint<'tcx>> = path
.iter() .iter()
.map(|constraint| { .map(|constraint| {
let (category, span, from_closure, cause_code) =
if constraint.category == ConstraintCategory::ClosureBounds { if constraint.category == ConstraintCategory::ClosureBounds {
self.retrieve_closure_constraint_info(&constraint) if let Some((category, span)) =
self.retrieve_closure_constraint_info(*constraint)
{
(category, span, true, ObligationCauseCode::MiscObligation)
} else { } else {
BlameConstraint { (
category: constraint.category, constraint.category,
from_closure: false,
cause: ObligationCause::new(
constraint.span, constraint.span,
CRATE_HIR_ID, false,
cause_code.clone(), ObligationCauseCode::MiscObligation,
), )
variance_info: constraint.variance_info,
} }
} else {
(constraint.category, constraint.span, false, cause_code.clone())
};
BlameConstraint {
category,
from_closure,
cause: ObligationCause::new(span, CRATE_HIR_ID, cause_code),
variance_info: constraint.variance_info,
} }
}) })
.collect(); .collect();