@@ -11,6 +11,7 @@ pub use self::CandidateSource::*;
11
11
pub use self :: MethodError :: * ;
12
12
13
13
use crate :: check:: FnCtxt ;
14
+ use rustc_ast:: ast:: Mutability ;
14
15
use rustc_data_structures:: sync:: Lrc ;
15
16
use rustc_errors:: { Applicability , DiagnosticBuilder } ;
16
17
use rustc_hir as hir;
@@ -222,12 +223,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
222
223
if let Ok ( self_expr) =
223
224
self . sess ( ) . source_map ( ) . span_to_snippet ( self_expr. span )
224
225
{
226
+ let derefs = "*" . repeat ( pick. autoderefs ) ;
227
+ let self_adjusted = match pick. autoref_or_ptr_adjustment {
228
+ Some ( probe:: AutorefOrPtrAdjustment :: Autoref {
229
+ mutbl : Mutability :: Mut , ..
230
+ } ) => format ! ( "&mut {}{}" , derefs, self_expr) ,
231
+ Some ( probe:: AutorefOrPtrAdjustment :: Autoref {
232
+ mutbl : Mutability :: Not , ..
233
+ } ) => format ! ( "&{}{}" , derefs, self_expr) ,
234
+ Some ( probe:: AutorefOrPtrAdjustment :: ToConstPtr ) | None
235
+ => format ! ( "{}{}" , derefs, self_expr) ,
236
+ } ;
225
237
lint. span_suggestion (
226
238
sp,
227
239
"disambiguate the associated function" ,
228
240
format ! (
229
241
"{}::{}({})" ,
230
- trait_name, segment. ident. name, self_expr ,
242
+ trait_name, segment. ident. name, self_adjusted ,
231
243
) ,
232
244
Applicability :: MachineApplicable ,
233
245
) ;
0 commit comments