@@ -12,7 +12,6 @@ use crate::check::{
1212use crate :: structured_errors:: StructuredDiagnostic ;
1313
1414use rustc_ast as ast;
15- use rustc_data_structures:: sync:: Lrc ;
1615use rustc_errors:: { Applicability , Diagnostic , DiagnosticId , MultiSpan } ;
1716use rustc_hir as hir;
1817use 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