Remove some unnecessary clones
This commit is contained in:
parent
2ea2ced2be
commit
312d27d0a2
3 changed files with 31 additions and 26 deletions
|
@ -143,10 +143,6 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
ObligationCause { span, body_id: hir::CRATE_HIR_ID, code: None }
|
||||
}
|
||||
|
||||
pub fn make_mut_code(&mut self) -> &mut ObligationCauseCode<'tcx> {
|
||||
Lrc::make_mut(self.code.get_or_insert_with(|| Lrc::new(MISC_OBLIGATION_CAUSE_CODE)))
|
||||
}
|
||||
|
||||
pub fn span(&self, tcx: TyCtxt<'tcx>) -> Span {
|
||||
match *self.code() {
|
||||
ObligationCauseCode::CompareImplMethodObligation { .. }
|
||||
|
@ -173,6 +169,16 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
None => Lrc::new(MISC_OBLIGATION_CAUSE_CODE),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_code(
|
||||
&mut self,
|
||||
f: impl FnOnce(Lrc<ObligationCauseCode<'tcx>>) -> Lrc<ObligationCauseCode<'tcx>>,
|
||||
) {
|
||||
self.code = Some(f(match self.code.take() {
|
||||
Some(code) => code,
|
||||
None => Lrc::new(MISC_OBLIGATION_CAUSE_CODE),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue