Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust cannot move out of static error in prep for removing Statics from Place #66328

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions src/librustc_mir/borrow_check/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
(
match kind {
IllegalMoveOriginKind::Static => {
self.report_cannot_move_from_static(original_path, span)
self.cannot_move_out_of(span, "an immutable place")
}
IllegalMoveOriginKind::BorrowedContent { target_place } => {
self.report_cannot_move_from_borrowed_content(
Expand All @@ -267,29 +267,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.buffer(&mut self.errors_buffer);
}

fn report_cannot_move_from_static(
&mut self,
place: &Place<'tcx>,
span: Span
) -> DiagnosticBuilder<'a> {
let description = if place.projection.is_empty() {
format!("static item `{}`", self.describe_place(place.as_ref()).unwrap())
} else {
let base_static = PlaceRef {
base: &place.base,
projection: &place.projection[..1],
};

format!(
"`{:?}` as `{:?}` is a static item",
self.describe_place(place.as_ref()).unwrap(),
self.describe_place(base_static).unwrap(),
)
};

self.cannot_move_out_of(span, &description)
}

fn report_cannot_move_from_borrowed_content(
&mut self,
move_place: &Place<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/borrowck-move-out-of-static-item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ fn test(f: Foo) {
}

fn main() {
test(BAR); //~ ERROR cannot move out of static item `BAR` [E0507]
test(BAR); //~ ERROR cannot move out of an immutable place [E0507]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0507]: cannot move out of static item `BAR`
error[E0507]: cannot move out of an immutable place
--> $DIR/borrowck-move-out-of-static-item.rs:15:10
|
LL | test(BAR);
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/borrowck/issue-47215-ice-from-drop-elab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// thread-local statics as a temporary rvalue, as a way to enforce
// that they are only valid for a given lifetime.
//
// The problem with this is that you cannot move out of static items,
// but you *can* move temporary rvalues. I.e., the categorization
// The problem with this is that you cannot move out of an immutable
// place but you *can* move temporary rvalues. I.e., the categorization
// above only solves half of the problem presented by thread-local
// statics.

Expand All @@ -14,7 +14,7 @@ static mut X: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::AtomicUsiz

fn main() {
unsafe {
let mut x = X; //~ ERROR cannot move out of static item `X` [E0507]
let mut x = X; //~ ERROR cannot move out of an immutable place [E0507]
let _y = x.get_mut();
}
}
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/issue-47215-ice-from-drop-elab.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0507]: cannot move out of static item `X`
error[E0507]: cannot move out of an immutable place
--> $DIR/issue-47215-ice-from-drop-elab.rs:17:21
|
LL | let mut x = X;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/issue-64453.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn set_editor(_: Value) {}

fn main() {
let settings_data = from_string(settings_dir);
//~^ ERROR cannot move out of static item `settings_dir` [E0507]
//~^ ERROR cannot move out of an immutable place [E0507]
let args: i32 = 0;

match args {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/issue-64453.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0507]: cannot move out of static item `settings_dir`
error[E0507]: cannot move out of an immutable place
--> $DIR/issue-64453.rs:15:37
|
LL | let settings_data = from_string(settings_dir);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/move-error-snippets.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0507]: cannot move out of static item `D`
error[E0507]: cannot move out of an immutable place
--> $DIR/move-error-snippets.rs:16:18
|
LL | | #[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/check-static-values-constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ static STATIC19: Box<isize> =
pub fn main() {
let y = { static x: Box<isize> = box 3; x };
//~^ ERROR allocations are not allowed in statics
//~| ERROR cannot move out of static item
//~| ERROR cannot move out of an immutable place
//~| ERROR contains unimplemented expression
}
2 changes: 1 addition & 1 deletion src/test/ui/check-static-values-constraints.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ error[E0019]: static contains unimplemented expression type
LL | box 3;
| ^

error[E0507]: cannot move out of static item `x`
error[E0507]: cannot move out of an immutable place
--> $DIR/check-static-values-constraints.rs:116:45
|
LL | let y = { static x: Box<isize> = box 3; x };
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-17718-static-move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ const INIT: Foo = Foo;
static FOO: Foo = INIT;

fn main() {
let _a = FOO; //~ ERROR: cannot move out of static item
let _a = FOO; //~ ERROR: cannot move out of an immutable place
}
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-17718-static-move.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0507]: cannot move out of static item `FOO`
error[E0507]: cannot move out of an immutable place
--> $DIR/issue-17718-static-move.rs:6:14
|
LL | let _a = FOO;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/static/static-items-cant-move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ fn test(f: Foo) {
}

fn main() {
test(BAR); //~ ERROR cannot move out of static item
test(BAR); //~ ERROR cannot move out of an immutable place
}
2 changes: 1 addition & 1 deletion src/test/ui/static/static-items-cant-move.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0507]: cannot move out of static item `BAR`
error[E0507]: cannot move out of an immutable place
--> $DIR/static-items-cant-move.rs:18:10
|
LL | test(BAR);
Expand Down