Auto merge of #89000 - Mark-Simulacrum:no-new-lrc, r=petrochenkov

Reuse existing shared Lrc for MatchImpl parent

This is a small performance win for the hot path, which helps to address this regression: https://github.com/rust-lang/rust/pull/87244#issuecomment-883635813.
This commit is contained in:
bors 2021-09-18 20:13:21 +00:00
commit aa8f2d432b
4 changed files with 4 additions and 4 deletions

View File

@ -39,7 +39,7 @@ pub(super) fn try_report_mismatched_static_lifetime(&self) -> Option<ErrorReport
ObligationCauseCode::MatchImpl(parent, impl_def_id) => (parent, impl_def_id), ObligationCauseCode::MatchImpl(parent, impl_def_id) => (parent, impl_def_id),
_ => return None, _ => return None,
}; };
let binding_span = match **parent { let binding_span = match parent.code {
ObligationCauseCode::BindingObligation(_def_id, binding_span) => binding_span, ObligationCauseCode::BindingObligation(_def_id, binding_span) => binding_span,
_ => return None, _ => return None,
}; };

View File

@ -189,7 +189,7 @@ pub(super) fn try_report_static_impl_trait(&self) -> Option<ErrorReported> {
} }
if let SubregionOrigin::Subtype(box TypeTrace { cause, .. }) = &sub_origin { if let SubregionOrigin::Subtype(box TypeTrace { cause, .. }) = &sub_origin {
let code = match &cause.code { let code = match &cause.code {
ObligationCauseCode::MatchImpl(parent, ..) => &**parent, ObligationCauseCode::MatchImpl(parent, ..) => &parent.code,
_ => &cause.code, _ => &cause.code,
}; };
if let ObligationCauseCode::ItemObligation(item_def_id) = *code { if let ObligationCauseCode::ItemObligation(item_def_id) = *code {

View File

@ -349,7 +349,7 @@ pub enum ObligationCauseCode<'tcx> {
WellFormed(Option<WellFormedLoc>), WellFormed(Option<WellFormedLoc>),
/// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching against. /// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching against.
MatchImpl(Lrc<ObligationCauseCode<'tcx>>, DefId), MatchImpl(ObligationCause<'tcx>, DefId),
} }
/// The 'location' at which we try to perform HIR-based wf checking. /// The 'location' at which we try to perform HIR-based wf checking.

View File

@ -2034,7 +2034,7 @@ fn match_impl(
let cause = ObligationCause::new( let cause = ObligationCause::new(
obligation.cause.span, obligation.cause.span,
obligation.cause.body_id, obligation.cause.body_id,
ObligationCauseCode::MatchImpl(Lrc::new(obligation.cause.code.clone()), impl_def_id), ObligationCauseCode::MatchImpl(obligation.cause.clone(), impl_def_id),
); );
let InferOk { obligations, .. } = self let InferOk { obligations, .. } = self