mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Make FunctionArgumentObligation
also use the "no allocation for misc" trick
This commit is contained in:
parent
1b51e1ad20
commit
213c17486e
@ -165,12 +165,9 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||||||
|
|
||||||
pub fn map_code(
|
pub fn map_code(
|
||||||
&mut self,
|
&mut self,
|
||||||
f: impl FnOnce(Lrc<ObligationCauseCode<'tcx>>) -> Lrc<ObligationCauseCode<'tcx>>,
|
f: impl FnOnce(InternedObligationCauseCode<'tcx>) -> Lrc<ObligationCauseCode<'tcx>>,
|
||||||
) {
|
) {
|
||||||
self.code = Some(f(match self.code.take() {
|
self.code = Some(f(InternedObligationCauseCode { code: self.code.take() }));
|
||||||
Some(code) => code,
|
|
||||||
None => Lrc::new(MISC_OBLIGATION_CAUSE_CODE),
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn derived_cause(
|
pub fn derived_cause(
|
||||||
@ -206,6 +203,19 @@ pub struct UnifyReceiverContext<'tcx> {
|
|||||||
pub substs: SubstsRef<'tcx>,
|
pub substs: SubstsRef<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
|
||||||
|
pub struct InternedObligationCauseCode<'tcx> {
|
||||||
|
code: Option<Lrc<ObligationCauseCode<'tcx>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
|
||||||
pub enum ObligationCauseCode<'tcx> {
|
pub enum ObligationCauseCode<'tcx> {
|
||||||
/// Not well classified or should be obvious from the span.
|
/// Not well classified or should be obvious from the span.
|
||||||
@ -293,7 +303,7 @@ pub enum ObligationCauseCode<'tcx> {
|
|||||||
/// The node of the function call.
|
/// The node of the function call.
|
||||||
call_hir_id: hir::HirId,
|
call_hir_id: hir::HirId,
|
||||||
/// The obligation introduced by this argument.
|
/// The obligation introduced by this argument.
|
||||||
parent_code: Lrc<ObligationCauseCode<'tcx>>,
|
parent_code: InternedObligationCauseCode<'tcx>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Error derived when matching traits/impls; see ObligationCause for more details
|
/// Error derived when matching traits/impls; see ObligationCause for more details
|
||||||
|
@ -1652,7 +1652,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
|
debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
|
||||||
match code {
|
match code {
|
||||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => {
|
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => {
|
||||||
next_code = Some(parent_code.as_ref());
|
next_code = Some(parent_code);
|
||||||
}
|
}
|
||||||
ObligationCauseCode::ImplDerivedObligation(cause) => {
|
ObligationCauseCode::ImplDerivedObligation(cause) => {
|
||||||
let ty = cause.derived.parent_trait_pred.skip_binder().self_ty();
|
let ty = cause.derived.parent_trait_pred.skip_binder().self_ty();
|
||||||
|
Loading…
Reference in New Issue
Block a user