Lifetime variance fixes for rustc

This commit is contained in:
Michael Goulet
2022-05-22 12:48:19 -07:00
parent 4bb4dc4672
commit 1784634a39
22 changed files with 92 additions and 86 deletions

View File

@@ -115,8 +115,6 @@ impl Hash for ObligationCause<'_> {
}
}
const MISC_OBLIGATION_CAUSE_CODE: ObligationCauseCode<'static> = MiscObligation;
impl<'tcx> ObligationCause<'tcx> {
#[inline]
pub fn new(
@@ -201,7 +199,7 @@ pub struct UnifyReceiverContext<'tcx> {
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift, Default)]
pub struct InternedObligationCauseCode<'tcx> {
/// `None` for `MISC_OBLIGATION_CAUSE_CODE` (a common case, occurs ~60% of
/// `None` for `ObligationCauseCode::MiscObligation` (a common case, occurs ~60% of
/// the time). `Some` otherwise.
code: Option<Lrc<ObligationCauseCode<'tcx>>>,
}
@@ -210,7 +208,11 @@ impl<'tcx> ObligationCauseCode<'tcx> {
#[inline(always)]
fn into(self) -> InternedObligationCauseCode<'tcx> {
InternedObligationCauseCode {
code: if let MISC_OBLIGATION_CAUSE_CODE = self { None } else { Some(Lrc::new(self)) },
code: if let ObligationCauseCode::MiscObligation = self {
None
} else {
Some(Lrc::new(self))
},
}
}
}
@@ -219,7 +221,7 @@ impl<'tcx> std::ops::Deref for InternedObligationCauseCode<'tcx> {
type Target = ObligationCauseCode<'tcx>;
fn deref(&self) -> &Self::Target {
self.code.as_deref().unwrap_or(&MISC_OBLIGATION_CAUSE_CODE)
self.code.as_deref().unwrap_or(&ObligationCauseCode::MiscObligation)
}
}