Skip to content

Commit 5ff6cdc

Browse files
authored
Rollup merge of #107422 - Nilstrieb:erase-the-ice, r=compiler-errors
Also erase substs for new infcx in pin move error The code originally correctly erased the regions of the type it passed to the newly created infcx. But after the `fn_sig` query was made to return an `EarlyBinder<T>`, some substs that were around were substituted there without erasing their regions. They were then passed into the newly cerated infcx, which caused the ICE. Fixes #107419 r? compiler-errors who reviewed the original PR adding this diagnostic
2 parents 74655dc + 832751f commit 5ff6cdc

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1128,8 +1128,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11281128
"{place_name} {partially_str}moved due to this method call{loop_message}",
11291129
),
11301130
);
1131+
11311132
let infcx = tcx.infer_ctxt().build();
1133+
// Erase and shadow everything that could be passed to the new infcx.
11321134
let ty = tcx.erase_regions(moved_place.ty(self.body, tcx).ty);
1135+
let method_substs = tcx.erase_regions(method_substs);
1136+
11331137
if let ty::Adt(def, substs) = ty.kind()
11341138
&& Some(def.did()) == tcx.lang_items().pin_type()
11351139
&& let ty::Ref(_, _, hir::Mutability::Mut) = substs.type_at(0).kind()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-rustfix
2+
use std::pin::Pin;
3+
4+
fn foo(_: &mut ()) {}
5+
6+
fn main() {
7+
let mut uwu = ();
8+
let mut r = Pin::new(&mut uwu);
9+
foo(r.as_mut().get_mut());
10+
foo(r.get_mut()); //~ ERROR use of moved value
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-rustfix
2+
use std::pin::Pin;
3+
4+
fn foo(_: &mut ()) {}
5+
6+
fn main() {
7+
let mut uwu = ();
8+
let mut r = Pin::new(&mut uwu);
9+
foo(r.get_mut());
10+
foo(r.get_mut()); //~ ERROR use of moved value
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0382]: use of moved value: `r`
2+
--> $DIR/pin-mut-reborrow-infer-var-issue-107419.rs:10:9
3+
|
4+
LL | let mut r = Pin::new(&mut uwu);
5+
| ----- move occurs because `r` has type `Pin<&mut ()>`, which does not implement the `Copy` trait
6+
LL | foo(r.get_mut());
7+
| --------- `r` moved due to this method call
8+
LL | foo(r.get_mut());
9+
| ^ value used here after move
10+
|
11+
note: `Pin::<&'a mut T>::get_mut` takes ownership of the receiver `self`, which moves `r`
12+
--> $SRC_DIR/core/src/pin.rs:LL:COL
13+
help: consider reborrowing the `Pin` instead of moving it
14+
|
15+
LL | foo(r.as_mut().get_mut());
16+
| +++++++++
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)