@@ -3585,7 +3585,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3585
3585
self . tcx . lang_items ( ) . deref_trait ( ) ,
3586
3586
self . tcx . lang_items ( ) . deref_mut_trait ( ) ,
3587
3587
self . tcx . lang_items ( ) . drop_trait ( ) ,
3588
- self . tcx . lang_items ( ) . pin_type ( ) ,
3589
3588
self . tcx . get_diagnostic_item ( sym:: AsRef ) ,
3590
3589
] ;
3591
3590
// Try alternative arbitrary self types that could fulfill this call.
@@ -3720,8 +3719,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3720
3719
&& !alt_rcvr_sugg
3721
3720
// `T: !Unpin`
3722
3721
&& !unpin
3723
- // The method isn't `as_ref`, as it would provide a wrong suggestion for `Pin`.
3724
- && sym:: as_ref != item_name. name
3725
3722
// Either `Pin::as_ref` or `Pin::as_mut`.
3726
3723
&& let Some ( pin_call) = pin_call
3727
3724
// Search for `item_name` as a method accessible on `Pin<T>`.
@@ -3735,12 +3732,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3735
3732
// We skip some common traits that we don't want to consider because autoderefs
3736
3733
// would take care of them.
3737
3734
&& !skippable. contains ( & Some ( pick. item . container_id ( self . tcx ) ) )
3738
- && !skippable. contains ( & pick. item . impl_container ( self . tcx ) . and_then ( |did| {
3735
+ // Do not suggest pinning when the method is directly on `Pin`.
3736
+ && pick. item . impl_container ( self . tcx ) . map_or ( true , |did| {
3739
3737
match self . tcx . type_of ( did) . instantiate_identity ( ) . kind ( ) {
3740
- ty:: Adt ( def, _) => Some ( def. did ( ) ) ,
3741
- _ => None ,
3738
+ ty:: Adt ( def, _) => Some ( def. did ( ) ) != self . tcx . lang_items ( ) . pin_type ( ) ,
3739
+ _ => true ,
3742
3740
}
3743
- } ) )
3741
+ } )
3744
3742
// We don't want to go through derefs.
3745
3743
&& pick. autoderefs == 0
3746
3744
// Check that the method of the same name that was found on the new `Pin<T>`
0 commit comments