Skip to content

Commit ff623ff

Browse files
committed
Cleanup retrieve_closure_constraint_info
1 parent 2be6301 commit ff623ff

File tree

2 files changed

+30
-42
lines changed
  • compiler/rustc_borrowck/src

2 files changed

+30
-42
lines changed

compiler/rustc_borrowck/src/constraints/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'tcx> Index<OutlivesConstraintIndex> for OutlivesConstraintSet<'tcx> {
7373
}
7474
}
7575

76-
#[derive(Clone, PartialEq, Eq)]
76+
#[derive(Copy, Clone, PartialEq, Eq)]
7777
pub struct OutlivesConstraint<'tcx> {
7878
// NB. The ordering here is not significant for correctness, but
7979
// it is for convenience. Before we dump the constraints in the

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,35 +1801,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
18011801

18021802
pub(crate) fn retrieve_closure_constraint_info(
18031803
&self,
1804-
constraint: &OutlivesConstraint<'tcx>,
1805-
) -> BlameConstraint<'tcx> {
1806-
let loc = match constraint.locations {
1807-
Locations::All(span) => {
1808-
return BlameConstraint {
1809-
category: constraint.category,
1810-
from_closure: false,
1811-
cause: ObligationCause::dummy_with_span(span),
1812-
variance_info: constraint.variance_info,
1813-
};
1804+
constraint: OutlivesConstraint<'tcx>,
1805+
) -> Option<(ConstraintCategory<'tcx>, Span)> {
1806+
match constraint.locations {
1807+
Locations::All(_) => None,
1808+
Locations::Single(loc) => {
1809+
self.closure_bounds_mapping[&loc].get(&(constraint.sup, constraint.sub)).copied()
18141810
}
1815-
Locations::Single(loc) => loc,
1816-
};
1817-
1818-
let opt_span_category =
1819-
self.closure_bounds_mapping[&loc].get(&(constraint.sup, constraint.sub));
1820-
opt_span_category
1821-
.map(|&(category, span)| BlameConstraint {
1822-
category,
1823-
from_closure: true,
1824-
cause: ObligationCause::dummy_with_span(span),
1825-
variance_info: constraint.variance_info,
1826-
})
1827-
.unwrap_or(BlameConstraint {
1828-
category: constraint.category,
1829-
from_closure: false,
1830-
cause: ObligationCause::dummy_with_span(constraint.span),
1831-
variance_info: constraint.variance_info,
1832-
})
1811+
}
18331812
}
18341813

18351814
/// Finds a good `ObligationCause` to blame for the fact that `fr1` outlives `fr2`.
@@ -2072,19 +2051,28 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20722051
let mut categorized_path: Vec<BlameConstraint<'tcx>> = path
20732052
.iter()
20742053
.map(|constraint| {
2075-
if constraint.category == ConstraintCategory::ClosureBounds {
2076-
self.retrieve_closure_constraint_info(&constraint)
2077-
} else {
2078-
BlameConstraint {
2079-
category: constraint.category,
2080-
from_closure: false,
2081-
cause: ObligationCause::new(
2082-
constraint.span,
2083-
CRATE_HIR_ID,
2084-
cause_code.clone(),
2085-
),
2086-
variance_info: constraint.variance_info,
2087-
}
2054+
let (category, span, from_closure, cause_code) =
2055+
if constraint.category == ConstraintCategory::ClosureBounds {
2056+
if let Some((category, span)) =
2057+
self.retrieve_closure_constraint_info(*constraint)
2058+
{
2059+
(category, span, true, ObligationCauseCode::MiscObligation)
2060+
} else {
2061+
(
2062+
constraint.category,
2063+
constraint.span,
2064+
false,
2065+
ObligationCauseCode::MiscObligation,
2066+
)
2067+
}
2068+
} else {
2069+
(constraint.category, constraint.span, false, cause_code.clone())
2070+
};
2071+
BlameConstraint {
2072+
category,
2073+
from_closure,
2074+
cause: ObligationCause::new(span, CRATE_HIR_ID, cause_code),
2075+
variance_info: constraint.variance_info,
20882076
}
20892077
})
20902078
.collect();

0 commit comments

Comments
 (0)