@@ -8,11 +8,10 @@ use rustc_index::vec::Idx;
88use rustc_middle:: mir:: {
99 self , AggregateKind , BindingForm , BorrowKind , ClearCrossCrate , ConstraintCategory ,
1010 FakeReadCause , Local , LocalDecl , LocalInfo , LocalKind , Location , Operand , Place , PlaceRef ,
11- ProjectionElem , Rvalue , Statement , StatementKind , TerminatorKind , VarBindingForm ,
11+ ProjectionElem , Rvalue , Statement , StatementKind , Terminator , TerminatorKind , VarBindingForm ,
1212} ;
13- use rustc_middle:: ty:: { self , suggest_constraining_type_param, Ty } ;
14- use rustc_span:: source_map:: DesugaringKind ;
15- use rustc_span:: Span ;
13+ use rustc_middle:: ty:: { self , suggest_constraining_type_param, Instance , Ty } ;
14+ use rustc_span:: { source_map:: DesugaringKind , symbol:: sym, Span } ;
1615
1716use crate :: dataflow:: drop_flag_effects;
1817use crate :: dataflow:: indexes:: { MoveOutIndex , MovePathIndex } ;
@@ -1543,6 +1542,36 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15431542 None ,
15441543 ) ;
15451544
1545+ let tcx = self . infcx . tcx ;
1546+ // point out implicit deref coercion
1547+ if let (
1548+ Some ( Terminator { kind : TerminatorKind :: Call { from_hir_call : false , .. } , .. } ) ,
1549+ Some ( ( method_did, method_substs) ) ,
1550+ ) = (
1551+ & self . body [ loan. reserve_location . block ] . terminator ,
1552+ crate :: util:: find_self_call (
1553+ tcx,
1554+ self . body ,
1555+ loan. assigned_place . local ,
1556+ loan. reserve_location . block ,
1557+ ) ,
1558+ ) {
1559+ if tcx. is_diagnostic_item ( sym:: deref_method, method_did) {
1560+ let deref_target =
1561+ tcx. get_diagnostic_item ( sym:: deref_target) . and_then ( |deref_target| {
1562+ Instance :: resolve ( tcx, self . param_env , deref_target, method_substs)
1563+ . transpose ( )
1564+ } ) ;
1565+ if let Some ( Ok ( instance) ) = deref_target {
1566+ let deref_target_ty = instance. ty ( tcx, self . param_env ) ;
1567+ err. note ( & format ! (
1568+ "borrow occurs due to deref coercion to `{}`" ,
1569+ deref_target_ty
1570+ ) ) ;
1571+ }
1572+ }
1573+ }
1574+
15461575 err. buffer ( & mut self . errors_buffer ) ;
15471576 }
15481577
0 commit comments