about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2014-12-09 20:25:09 -0500
committerNiko Matsakis <niko@alum.mit.edu>2014-12-12 20:25:21 -0500
commit97cf91aa30c84b14c72d88f51f9f22a50a8e3b54 (patch)
treeac7b84be02e3f1d8124b33bdffbd20cbed10e3f1
parent07eebf69107b50082386fa8c74d31aebcba8e6f1 (diff)
downloadrust-97cf91aa30c84b14c72d88f51f9f22a50a8e3b54.tar.gz
rust-97cf91aa30c84b14c72d88f51f9f22a50a8e3b54.zip
Fix the opt-out-copy behavior so that values with dtor etc are considered affine
-rw-r--r--src/librustc/middle/traits/select.rs9
-rw-r--r--src/librustc_typeck/check/mod.rs1
-rw-r--r--src/test/compile-fail/opt-out-copy-bad.rs42
3 files changed, 51 insertions, 1 deletions
diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs
index c55335ea190..88c70f5557c 100644
--- a/src/librustc/middle/traits/select.rs
+++ b/src/librustc/middle/traits/select.rs
@@ -1289,6 +1289,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
                     // don't supply any form of builtin impl.
                     if !this.tcx().sess.features.borrow().opt_out_copy {
                         return Ok(ParameterBuiltin)
+                    } else {
+                        // Older, backwards compatibility behavior:
+                        if
+                            Some(def_id) == tcx.lang_items.no_copy_bound() ||
+                            Some(def_id) == tcx.lang_items.managed_bound() ||
+                            ty::has_dtor(tcx, def_id)
+                        {
+                            return Err(Unimplemented);
+                        }
                     }
                 }
 
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 73fae976097..573c63eb6af 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -104,7 +104,6 @@ use {CrateCtxt, lookup_def_ccx, no_params, require_same_types};
 use TypeAndSubsts;
 use middle::lang_items::TypeIdLangItem;
 use lint;
-use util::common::ErrorReported;
 use util::common::{block_query, indenter, loop_query};
 use util::ppaux::{mod, UserString, Repr};
 use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};
diff --git a/src/test/compile-fail/opt-out-copy-bad.rs b/src/test/compile-fail/opt-out-copy-bad.rs
new file mode 100644
index 00000000000..80f8a154d58
--- /dev/null
+++ b/src/test/compile-fail/opt-out-copy-bad.rs
@@ -0,0 +1,42 @@
+// 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.
+
+#![feature(opt_out_copy)]
+
+// Test that when using the `opt-out-copy` feature we still consider
+// destructors to be non-movable
+
+struct CantCopyThis;
+
+impl Drop for CantCopyThis {
+    fn drop(&mut self) { }
+}
+
+struct IWantToCopyThis {
+    but_i_cant: CantCopyThis,
+}
+
+impl Copy for IWantToCopyThis {}
+//~^ ERROR the trait `Copy` may not be implemented for this type
+
+enum CantCopyThisEither {
+    A,
+    B(::std::kinds::marker::NoCopy),
+}
+
+enum IWantToCopyThisToo {
+    ButICant(CantCopyThisEither),
+}
+
+impl Copy for IWantToCopyThisToo {}
+//~^ ERROR the trait `Copy` may not be implemented for this type
+
+fn main() {}
+