Forbid moves out of static items Closes #10577
This commit is contained in:
parent
c75dd78ccb
commit
8784d2fa95
@ -104,7 +104,7 @@ fn check_is_legal_to_move_from(bccx: &BorrowckCtxt,
|
||||
mc::cat_deref(_, _, mc::BorrowedPtr(..)) |
|
||||
mc::cat_deref(_, _, mc::GcPtr) |
|
||||
mc::cat_deref(_, _, mc::UnsafePtr(..)) |
|
||||
mc::cat_upvar(..) |
|
||||
mc::cat_upvar(..) | mc::cat_static_item |
|
||||
mc::cat_copied_upvar(mc::CopiedUpvar { onceness: ast::Many, .. }) => {
|
||||
bccx.span_err(
|
||||
cmt0.span,
|
||||
@ -120,19 +120,6 @@ fn check_is_legal_to_move_from(bccx: &BorrowckCtxt,
|
||||
true
|
||||
}
|
||||
|
||||
// It seems strange to allow a move out of a static item,
|
||||
// but what happens in practice is that you have a
|
||||
// reference to a constant with a type that should be
|
||||
// moved, like `None::<~int>`. The type of this constant
|
||||
// is technically `Option<~int>`, which moves, but we know
|
||||
// that the content of static items will never actually
|
||||
// contain allocated pointers, so we can just memcpy it.
|
||||
// Since static items can never have allocated memory,
|
||||
// this is ok. For now anyhow.
|
||||
mc::cat_static_item => {
|
||||
true
|
||||
}
|
||||
|
||||
mc::cat_rvalue(..) |
|
||||
mc::cat_local(..) |
|
||||
mc::cat_arg(..) => {
|
||||
|
29
src/test/compile-fail/borrowck-move-out-of-static-item.rs
Normal file
29
src/test/compile-fail/borrowck-move-out-of-static-item.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Ensure that moves out of static items is forbidden
|
||||
|
||||
use std::kinds::marker;
|
||||
|
||||
struct Foo {
|
||||
foo: int,
|
||||
nopod: marker::NoPod
|
||||
}
|
||||
|
||||
static BAR: Foo = Foo{foo: 5, nopod: marker::NoPod};
|
||||
|
||||
|
||||
fn test(f: Foo) {
|
||||
let _f = Foo{foo: 4, ..f};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test(BAR); //~ ERROR cannot move out of static item
|
||||
}
|
@ -25,5 +25,5 @@ fn test(f: Foo) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test(BAR);
|
||||
test(BAR); //~ ERROR cannot move out of static item
|
||||
}
|
||||
|
@ -16,13 +16,13 @@ use std::sync::atomics::*;
|
||||
use std::ptr;
|
||||
|
||||
fn main() {
|
||||
let x = INIT_ATOMIC_FLAG;
|
||||
let x = INIT_ATOMIC_FLAG; //~ ERROR cannot move out of static item
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
let x = INIT_ATOMIC_BOOL;
|
||||
let x = INIT_ATOMIC_BOOL; //~ ERROR cannot move out of static item
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
let x = INIT_ATOMIC_INT;
|
||||
let x = INIT_ATOMIC_INT; //~ ERROR cannot move out of static item
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
let x = INIT_ATOMIC_UINT;
|
||||
let x = INIT_ATOMIC_UINT; //~ ERROR cannot move out of static item
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
let x: AtomicPtr<uint> = AtomicPtr::new(ptr::mut_null());
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
|
@ -15,6 +15,6 @@
|
||||
extern crate issue6919_3;
|
||||
|
||||
pub fn main() {
|
||||
issue6919_3::D.k;
|
||||
let _ = issue6919_3::D.k;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user