diff --git a/src/librustc/middle/borrowck/gather_loans/gather_moves.rs b/src/librustc/middle/borrowck/gather_loans/gather_moves.rs index 49b12a6db1fb5..7ec9f1f8f4795 100644 --- a/src/librustc/middle/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc/middle/borrowck/gather_loans/gather_moves.rs @@ -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(..) => { diff --git a/src/test/compile-fail/borrowck-move-out-of-static-item.rs b/src/test/compile-fail/borrowck-move-out-of-static-item.rs new file mode 100644 index 0000000000000..a7e5573ccfc66 --- /dev/null +++ b/src/test/compile-fail/borrowck-move-out-of-static-item.rs @@ -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 or the MIT license +// , 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 +} diff --git a/src/test/compile-fail/static-items-cant-move.rs b/src/test/compile-fail/static-items-cant-move.rs index 1bd78d2b1a238..f089904dd9149 100644 --- a/src/test/compile-fail/static-items-cant-move.rs +++ b/src/test/compile-fail/static-items-cant-move.rs @@ -25,5 +25,5 @@ fn test(f: Foo) { } fn main() { - test(BAR); + test(BAR); //~ ERROR cannot move out of static item } diff --git a/src/test/compile-fail/std-uncopyable-atomics.rs b/src/test/compile-fail/std-uncopyable-atomics.rs index 57c66974fcd01..5c0e7e90aa932 100644 --- a/src/test/compile-fail/std-uncopyable-atomics.rs +++ b/src/test/compile-fail/std-uncopyable-atomics.rs @@ -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 = AtomicPtr::new(ptr::mut_null()); let x = *&x; //~ ERROR: cannot move out of dereference diff --git a/src/test/run-pass/issue-6919.rs b/src/test/run-pass/issue-6919.rs index 6d84268fb418d..5afffb3d029f7 100644 --- a/src/test/run-pass/issue-6919.rs +++ b/src/test/run-pass/issue-6919.rs @@ -15,6 +15,6 @@ extern crate issue6919_3; pub fn main() { - issue6919_3::D.k; + let _ = issue6919_3::D.k; }