@@ -12,7 +12,6 @@ use crate::check::{
12
12
use crate :: structured_errors:: StructuredDiagnostic ;
13
13
14
14
use rustc_ast as ast;
15
- use rustc_data_structures:: sync:: Lrc ;
16
15
use rustc_errors:: { Applicability , Diagnostic , DiagnosticId , MultiSpan } ;
17
16
use rustc_hir as hir;
18
17
use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
@@ -1601,24 +1600,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1601
1600
// Peel derived obligation, because it's the type that originally
1602
1601
// started this inference chain that matters, not the one we wound
1603
1602
// 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;
1608
1607
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 ,
1613
1610
ObligationCauseCode :: BuiltinDerivedObligation ( c)
1614
- | ObligationCauseCode :: DerivedObligation ( c) => c. parent_code . clone ( ) ,
1615
- _ => break ,
1611
+ | ObligationCauseCode :: DerivedObligation ( c) => & c. parent_code ,
1612
+ _ => break result_code ,
1616
1613
} ;
1617
- result_code = std :: mem :: replace ( & mut code, parent) ;
1614
+ ( result_code, code ) = ( code, parent) ;
1618
1615
}
1619
- result_code
1620
1616
}
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 ( ) ) {
1622
1618
ObligationCauseCode :: BuiltinDerivedObligation ( code) |
1623
1619
ObligationCauseCode :: DerivedObligation ( code) => {
1624
1620
code. parent_trait_pred . self_ty ( ) . skip_binder ( ) . into ( )
0 commit comments