Skip to content

Commit 2bf3b94

Browse files
Rollup merge of rust-lang#54825 - davidtwco:issue-52663-deref-raw-pointer, r=pnkfelix
NLL says "borrowed content" instead of more precise "dereference of raw pointer" Part of rust-lang#52663. Previously, move errors involving the dereference of a raw pointer would say "borrowed content". This commit changes it to say "dereference of raw pointer". r? @nikomatsakis cc @pnkfelix
2 parents e33cd16 + fe8ace8 commit 2bf3b94

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/librustc_mir/borrow_check/move_errors.rs

+15
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ enum GroupedMoveError<'tcx> {
6868
enum BorrowedContentSource {
6969
Arc,
7070
Rc,
71+
DerefRawPointer,
7172
Other,
7273
}
7374

@@ -76,6 +77,7 @@ impl Display for BorrowedContentSource {
7677
match *self {
7778
BorrowedContentSource::Arc => write!(f, "an `Arc`"),
7879
BorrowedContentSource::Rc => write!(f, "an `Rc`"),
80+
BorrowedContentSource::DerefRawPointer => write!(f, "dereference of raw pointer"),
7981
BorrowedContentSource::Other => write!(f, "borrowed content"),
8082
}
8183
}
@@ -279,6 +281,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
279281
self.prefixes(&original_path, PrefixSet::All)
280282
.any(|p| p.is_upvar_field_projection(self.mir, &self.infcx.tcx)
281283
.is_some());
284+
debug!("report: ty={:?}", ty);
282285
match ty.sty {
283286
ty::Array(..) | ty::Slice(..) =>
284287
self.infcx.tcx.cannot_move_out_of_interior_noncopy(
@@ -582,6 +585,18 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
582585
}
583586
}
584587

588+
// If we didn't find an `Arc` or an `Rc`, then check specifically for
589+
// a dereference of a place that has the type of a raw pointer.
590+
// We can't use `place.ty(..).to_ty(..)` here as that strips away the raw pointer.
591+
if let Place::Projection(box Projection {
592+
base,
593+
elem: ProjectionElem::Deref,
594+
}) = place {
595+
if base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx).is_unsafe_ptr() {
596+
return BorrowedContentSource::DerefRawPointer;
597+
}
598+
}
599+
585600
BorrowedContentSource::Other
586601
}
587602
}

src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.nll.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0507]: cannot move out of borrowed content
1+
error[E0507]: cannot move out of dereference of raw pointer
22
--> $DIR/borrowck-move-from-unsafe-ptr.rs:13:13
33
|
44
LL | let y = *x; //~ ERROR cannot move out of dereference of raw pointer
55
| ^^
66
| |
7-
| cannot move out of borrowed content
7+
| cannot move out of dereference of raw pointer
88
| help: consider removing the `*`: `x`
99

1010
error: aborting due to previous error

src/test/ui/issues/issue-20801.nll.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ LL | let b = unsafe { *imm_ref() };
1616
| cannot move out of borrowed content
1717
| help: consider removing the `*`: `imm_ref()`
1818

19-
error[E0507]: cannot move out of borrowed content
19+
error[E0507]: cannot move out of dereference of raw pointer
2020
--> $DIR/issue-20801.rs:42:22
2121
|
2222
LL | let c = unsafe { *mut_ptr() };
2323
| ^^^^^^^^^^
2424
| |
25-
| cannot move out of borrowed content
25+
| cannot move out of dereference of raw pointer
2626
| help: consider removing the `*`: `mut_ptr()`
2727

28-
error[E0507]: cannot move out of borrowed content
28+
error[E0507]: cannot move out of dereference of raw pointer
2929
--> $DIR/issue-20801.rs:45:22
3030
|
3131
LL | let d = unsafe { *const_ptr() };
3232
| ^^^^^^^^^^^^
3333
| |
34-
| cannot move out of borrowed content
34+
| cannot move out of dereference of raw pointer
3535
| help: consider removing the `*`: `const_ptr()`
3636

3737
error: aborting due to 4 previous errors

0 commit comments

Comments
 (0)