Skip to content

Commit 12fd901

Browse files
committed
Verify receiver is of self: Pin<&mut Self>
1 parent a929316 commit 12fd901

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,9 +1132,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11321132
place_name, partially_str, loop_message
11331133
),
11341134
);
1135-
let ty = moved_place.ty(self.body, self.infcx.tcx).ty;
1136-
if let ty::Adt(def, ..) = ty.kind()
1135+
let ty = tcx.erase_regions(moved_place.ty(self.body, self.infcx.tcx).ty);
1136+
if let ty::Adt(def, substs) = ty.kind()
11371137
&& Some(def.did()) == self.infcx.tcx.lang_items().pin_type()
1138+
&& let ty::Ref(_, _, hir::Mutability::Mut) = substs.type_at(0).kind()
1139+
// FIXME: this is a hack because we can't call `can_eq`
1140+
&& ty.to_string() ==
1141+
tcx.fn_sig(method_did).input(0).skip_binder().to_string()
11381142
{
11391143
err.span_suggestion_verbose(
11401144
fn_call_span.shrink_to_lo(),

src/test/ui/moves/move-fn-self-receiver.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ note: `Foo::use_pin_box_self` takes ownership of the receiver `self`, which move
6767
|
6868
LL | fn use_pin_box_self(self: Pin<Box<Self>>) {}
6969
| ^^^^
70-
help: consider reborrowing the `Pin` instead of moving it
71-
|
72-
LL | pin_box_foo.as_mut().use_pin_box_self();
73-
| +++++++++
7470

7571
error[E0505]: cannot move out of `mut_foo` because it is borrowed
7672
--> $DIR/move-fn-self-receiver.rs:50:5

0 commit comments

Comments
 (0)