Skip to content

Commit f47df01

Browse files
committed
review comment
1 parent 775e287 commit f47df01

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3585,7 +3585,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
35853585
self.tcx.lang_items().deref_trait(),
35863586
self.tcx.lang_items().deref_mut_trait(),
35873587
self.tcx.lang_items().drop_trait(),
3588-
self.tcx.lang_items().pin_type(),
35893588
self.tcx.get_diagnostic_item(sym::AsRef),
35903589
];
35913590
// Try alternative arbitrary self types that could fulfill this call.
@@ -3720,8 +3719,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37203719
&& !alt_rcvr_sugg
37213720
// `T: !Unpin`
37223721
&& !unpin
3723-
// The method isn't `as_ref`, as it would provide a wrong suggestion for `Pin`.
3724-
&& sym::as_ref != item_name.name
37253722
// Either `Pin::as_ref` or `Pin::as_mut`.
37263723
&& let Some(pin_call) = pin_call
37273724
// Search for `item_name` as a method accessible on `Pin<T>`.
@@ -3735,12 +3732,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37353732
// We skip some common traits that we don't want to consider because autoderefs
37363733
// would take care of them.
37373734
&& !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| {
37393737
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,
37423740
}
3743-
}))
3741+
})
37443742
// We don't want to go through derefs.
37453743
&& pick.autoderefs == 0
37463744
// Check that the method of the same name that was found on the new `Pin<T>`

0 commit comments

Comments
 (0)