Skip to content

Commit 063795c

Browse files
committed
Remove another use of clone_code
1 parent 704bbe5 commit 063795c

File tree

1 file changed

+10
-14
lines changed
  • compiler/rustc_typeck/src/check/fn_ctxt

1 file changed

+10
-14
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::check::{
1212
use crate::structured_errors::StructuredDiagnostic;
1313

1414
use rustc_ast as ast;
15-
use rustc_data_structures::sync::Lrc;
1615
use rustc_errors::{Applicability, Diagnostic, DiagnosticId, MultiSpan};
1716
use rustc_hir as hir;
1817
use rustc_hir::def::{CtorOf, DefKind, Res};
@@ -1601,24 +1600,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16011600
// Peel derived obligation, because it's the type that originally
16021601
// started this inference chain that matters, not the one we wound
16031602
// up with at the end.
1604-
fn unpeel_to_top(
1605-
mut code: Lrc<ObligationCauseCode<'_>>,
1606-
) -> Lrc<ObligationCauseCode<'_>> {
1607-
let mut result_code = code.clone();
1603+
fn unpeel_to_top<'a, 'tcx>(
1604+
mut code: &'a ObligationCauseCode<'tcx>,
1605+
) -> &'a ObligationCauseCode<'tcx> {
1606+
let mut result_code = code;
16081607
loop {
1609-
let parent = match &*code {
1610-
ObligationCauseCode::ImplDerivedObligation(c) => {
1611-
c.derived.parent_code.clone()
1612-
}
1608+
let parent = match code {
1609+
ObligationCauseCode::ImplDerivedObligation(c) => &c.derived.parent_code,
16131610
ObligationCauseCode::BuiltinDerivedObligation(c)
1614-
| ObligationCauseCode::DerivedObligation(c) => c.parent_code.clone(),
1615-
_ => break,
1611+
| ObligationCauseCode::DerivedObligation(c) => &c.parent_code,
1612+
_ => break result_code,
16161613
};
1617-
result_code = std::mem::replace(&mut code, parent);
1614+
(result_code, code) = (code, parent);
16181615
}
1619-
result_code
16201616
}
1621-
let self_: ty::subst::GenericArg<'_> = match &*unpeel_to_top(error.obligation.cause.clone_code()) {
1617+
let self_: ty::subst::GenericArg<'_> = match unpeel_to_top(error.obligation.cause.code()) {
16221618
ObligationCauseCode::BuiltinDerivedObligation(code) |
16231619
ObligationCauseCode::DerivedObligation(code) => {
16241620
code.parent_trait_pred.self_ty().skip_binder().into()

0 commit comments

Comments
 (0)