From 5859dc1aa52cd2bc54fefcf1925a96defff5a9bb Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 1 Oct 2014 13:07:37 -0700 Subject: [PATCH] librustc: Make `Copy` opt-in. This change makes the compiler no longer infer whether types (structures and enumerations) implement the `Copy` trait (and thus are implicitly copyable). Rather, you must implement `Copy` yourself via `impl Copy for MyType {}`. A new warning has been added, `missing_copy_implementations`, to warn you if a non-generic public type has been added that could have implemented `Copy` but didn't. This breaks code like: #[deriving(Show)] struct Point2D { x: int, y: int, } fn main() { let mypoint = Point2D { x: 1, y: 1, }; let otherpoint = mypoint; println!("{}{}", mypoint, otherpoint); } Change this code to: #[deriving(Show)] struct Point2D { x: int, y: int, } impl Copy for Point2D {} fn main() { let mypoint = Point2D { x: 1, y: 1, }; let otherpoint = mypoint; println!("{}{}", mypoint, otherpoint); } This is the backwards-incompatible part of #13231. Part of RFC #3. [breaking-change] --- src/compiletest/common.rs | 2 + src/doc/guide-unsafe.md | 3 + src/doc/reference.md | 4 + src/libarena/lib.rs | 2 +- src/libcollections/binary_heap.rs | 2 + src/libcollections/dlist.rs | 9 +- src/libcollections/enum_set.rs | 7 + src/libcollections/hash/sip.rs | 3 + src/libcollections/slice.rs | 16 +- src/libcollections/str.rs | 34 ++- src/libcore/atomic.rs | 3 + src/libcore/char.rs | 1 + src/libcore/cmp.rs | 4 +- src/libcore/fmt/mod.rs | 4 + src/libcore/fmt/num.rs | 5 + src/libcore/fmt/rt.rs | 13 + src/libcore/intrinsics.rs | 6 + src/libcore/iter.rs | 11 +- src/libcore/kinds.rs | 17 ++ src/libcore/num/mod.rs | 2 + src/libcore/ops.rs | 32 +++ src/libcore/option.rs | 7 +- src/libcore/ptr.rs | 1 + src/libcore/raw.rs | 9 + src/libcore/result.rs | 5 + src/libcore/simd.rs | 23 ++ src/libcore/slice.rs | 6 + src/libcore/str.rs | 9 +- src/libfmt_macros/lib.rs | 14 ++ src/libgetopts/lib.rs | 26 +- src/liblibc/lib.rs | 73 +++++- src/liblog/lib.rs | 4 + src/librand/chacha.rs | 2 + src/librand/distributions/exponential.rs | 5 + src/librand/distributions/normal.rs | 7 + src/librand/isaac.rs | 5 + src/librand/lib.rs | 12 + src/librand/reseeding.rs | 2 + src/librbml/lib.rs | 6 + src/libregex/parse.rs | 2 + src/libregex/re.rs | 8 +- src/libregex/vm.rs | 4 + src/librustc/lint/builtin.rs | 102 +++++++- src/librustc/lint/context.rs | 1 + src/librustc/lint/mod.rs | 8 + src/librustc/metadata/common.rs | 2 + src/librustc/metadata/creader.rs | 6 +- src/librustc/metadata/csearch.rs | 7 +- src/librustc/metadata/cstore.rs | 17 +- src/librustc/metadata/decoder.rs | 6 +- src/librustc/metadata/filesearch.rs | 7 +- src/librustc/metadata/tydecode.rs | 2 + src/librustc/middle/borrowck/check_loans.rs | 14 +- .../middle/borrowck/gather_loans/mod.rs | 12 +- src/librustc/middle/borrowck/graphviz.rs | 2 + src/librustc/middle/borrowck/mod.rs | 37 ++- src/librustc/middle/borrowck/move_data.rs | 16 ++ src/librustc/middle/cfg/construct.rs | 2 + src/librustc/middle/cfg/mod.rs | 2 + src/librustc/middle/check_loop.rs | 4 + src/librustc/middle/check_match.rs | 26 +- src/librustc/middle/check_rvalues.rs | 6 +- src/librustc/middle/check_static.rs | 10 +- src/librustc/middle/const_eval.rs | 2 + src/librustc/middle/dataflow.rs | 7 +- src/librustc/middle/def.rs | 4 + src/librustc/middle/effect.rs | 2 + src/librustc/middle/expr_use_visitor.rs | 69 ++++-- src/librustc/middle/fast_reject.rs | 2 + src/librustc/middle/graph.rs | 6 + src/librustc/middle/lang_items.rs | 2 + src/librustc/middle/liveness.rs | 15 ++ src/librustc/middle/mem_categorization.rs | 22 ++ src/librustc/middle/region.rs | 4 + src/librustc/middle/resolve.rs | 40 ++++ src/librustc/middle/resolve_lifetime.rs | 2 + src/librustc/middle/subst.rs | 2 + src/librustc/middle/traits/mod.rs | 8 +- src/librustc/middle/traits/select.rs | 29 ++- src/librustc/middle/ty.rs | 224 ++++++++++++++---- .../middle/typeck/check/method/mod.rs | 2 + src/librustc/middle/typeck/check/mod.rs | 8 + src/librustc/middle/typeck/check/vtable.rs | 3 +- src/librustc/middle/typeck/check/wf.rs | 5 + src/librustc/middle/typeck/check/writeback.rs | 2 + src/librustc/middle/typeck/coherence/mod.rs | 87 ++++++- src/librustc/middle/typeck/collect.rs | 2 + src/librustc/middle/typeck/infer/mod.rs | 6 + .../typeck/infer/region_inference/mod.rs | 16 ++ .../middle/typeck/infer/type_variable.rs | 2 + src/librustc/middle/typeck/infer/unify.rs | 2 + src/librustc/middle/typeck/mod.rs | 6 + src/librustc/middle/typeck/rscope.rs | 3 + src/librustc/middle/typeck/variance.rs | 10 +- src/librustc/session/config.rs | 12 +- src/librustc/util/common.rs | 2 + src/librustc/util/nodemap.rs | 3 + src/librustc_llvm/diagnostic.rs | 6 + src/librustc_llvm/lib.rs | 65 +++++ src/librustc_trans/back/write.rs | 11 + src/librustc_trans/driver/driver.rs | 2 + src/librustc_trans/driver/pretty.rs | 4 + src/librustc_trans/save/mod.rs | 2 +- src/librustc_trans/save/recorder.rs | 7 +- src/librustc_trans/save/span_utils.rs | 1 + src/librustc_trans/trans/_match.rs | 29 ++- src/librustc_trans/trans/adt.rs | 5 +- src/librustc_trans/trans/base.rs | 24 +- src/librustc_trans/trans/basic_block.rs | 2 + src/librustc_trans/trans/cabi.rs | 4 + src/librustc_trans/trans/cabi_x86_64.rs | 2 + src/librustc_trans/trans/callee.rs | 4 + src/librustc_trans/trans/cleanup.rs | 18 ++ src/librustc_trans/trans/closure.rs | 2 + src/librustc_trans/trans/common.rs | 9 +- src/librustc_trans/trans/datum.rs | 24 +- src/librustc_trans/trans/debuginfo.rs | 6 + src/librustc_trans/trans/expr.rs | 4 + src/librustc_trans/trans/tvec.rs | 4 +- src/librustc_trans/trans/type_.rs | 2 + src/librustc_trans/trans/type_of.rs | 5 +- src/librustc_trans/trans/value.rs | 10 +- src/librustdoc/clean/mod.rs | 6 + src/librustdoc/doctree.rs | 2 + src/librustdoc/html/format.rs | 5 + src/librustdoc/html/item_type.rs | 2 + src/librustdoc/html/render.rs | 8 +- src/librustdoc/stability_summary.rs | 2 + src/librustrt/bookkeeping.rs | 1 + src/librustrt/c_str.rs | 1 + src/librustrt/mutex.rs | 12 + src/librustrt/unwind.rs | 1 + src/librustrt/util.rs | 3 + src/libserialize/base64.rs | 6 + src/libserialize/hex.rs | 2 + src/libserialize/json.rs | 4 + src/libstd/ascii.rs | 3 + src/libstd/bitflags.rs | 9 + src/libstd/collections/hash/table.rs | 6 +- src/libstd/comm/mod.rs | 2 + src/libstd/dynamic_lib.rs | 8 +- src/libstd/io/mod.rs | 17 ++ src/libstd/io/net/addrinfo.rs | 11 + src/libstd/io/net/ip.rs | 5 + src/libstd/io/process.rs | 4 + src/libstd/io/util.rs | 6 + src/libstd/num/strconv.rs | 51 ++-- src/libstd/os.rs | 12 + src/libstd/path/windows.rs | 3 + src/libstd/rand/mod.rs | 7 +- src/libstd/sync/raw.rs | 2 + src/libstd/time/duration.rs | 3 + src/libsyntax/abi.rs | 22 +- src/libsyntax/ast.rs | 65 ++++- src/libsyntax/ast_map/blocks.rs | 4 + src/libsyntax/ast_map/mod.rs | 6 + src/libsyntax/ast_util.rs | 2 + src/libsyntax/attr.rs | 8 + src/libsyntax/codemap.rs | 14 ++ src/libsyntax/diagnostic.rs | 10 + src/libsyntax/ext/base.rs | 10 +- src/libsyntax/ext/deriving/cmp/ord.rs | 2 + src/libsyntax/ext/mtwt.rs | 2 + src/libsyntax/feature_gate.rs | 2 + src/libsyntax/parse/lexer/comments.rs | 2 + src/libsyntax/parse/obsolete.rs | 2 + src/libsyntax/parse/parser.rs | 4 + src/libsyntax/parse/token.rs | 12 + src/libsyntax/print/pp.rs | 10 + src/libsyntax/print/pprust.rs | 4 + src/libsyntax/visit.rs | 2 + src/libterm/lib.rs | 3 + src/libterm/terminfo/parm.rs | 8 + src/libtest/lib.rs | 18 +- src/libtime/lib.rs | 12 +- src/libunicode/tables.rs | 3 + src/test/auxiliary/issue-14422.rs | 2 + src/test/auxiliary/issue13213aux.rs | 4 + src/test/auxiliary/lang-item-public.rs | 5 + src/test/auxiliary/method_self_arg1.rs | 2 + src/test/auxiliary/method_self_arg2.rs | 2 + src/test/auxiliary/xcrate_unit_struct.rs | 11 + src/test/bench/noise.rs | 2 + src/test/bench/shootout-chameneos-redux.rs | 11 +- src/test/bench/shootout-fannkuch-redux.rs | 4 + src/test/bench/shootout-fasta-redux.rs | 2 + src/test/bench/shootout-k-nucleotide.rs | 2 + src/test/bench/shootout-nbody.rs | 2 + .../borrowck-borrow-from-owned-ptr.rs | 4 + .../borrowck-borrow-from-stack-variable.rs | 4 + ...borrowck-loan-local-as-both-mut-and-imm.rs | 35 --- .../compile-fail/borrowck-use-mut-borrow.rs | 3 + src/test/compile-fail/dst-index.rs | 7 +- src/test/compile-fail/dst-rvalue.rs | 2 + src/test/compile-fail/issue-17651.rs | 3 +- src/test/compile-fail/kindck-copy.rs | 3 + src/test/compile-fail/lint-dead-code-1.rs | 1 + src/test/compile-fail/lint-missing-doc.rs | 1 + src/test/compile-fail/opt-in-copy.rs | 33 +++ .../stage0-clone-contravariant-lifetime.rs | 43 ---- src/test/compile-fail/stage0-cmp.rs | 39 --- .../generic-method-on-generic-struct.rs | 3 + src/test/debuginfo/method-on-enum.rs | 3 + .../debuginfo/method-on-generic-struct.rs | 3 + src/test/debuginfo/method-on-struct.rs | 3 + src/test/debuginfo/method-on-trait.rs | 3 + src/test/debuginfo/method-on-tuple-struct.rs | 3 + src/test/debuginfo/self-in-default-method.rs | 3 + .../self-in-generic-default-method.rs | 3 + src/test/pretty/block-disambig.rs | 2 + .../extern-fn-with-packed-struct/test.rs | 2 + src/test/run-make/target-specs/foo.rs | 3 + src/test/run-pass/borrowck-univariant-enum.rs | 2 + .../builtin-superkinds-in-metadata.rs | 8 +- src/test/run-pass/cell-does-not-clone.rs | 2 + .../class-impl-very-parameterized-trait.rs | 2 + src/test/run-pass/coherence-impl-in-fn.rs | 1 + src/test/run-pass/coherence-where-clause.rs | 2 + .../run-pass/const-nullary-univariant-enum.rs | 2 + src/test/run-pass/dst-struct-sole.rs | 2 + src/test/run-pass/dst-struct.rs | 2 + src/test/run-pass/dst-trait.rs | 4 + src/test/run-pass/empty-tag.rs | 2 + src/test/run-pass/enum-discrim-width-stuff.rs | 1 + src/test/run-pass/explicit-self-generic.rs | 4 + src/test/run-pass/export-unexported-dep.rs | 2 + src/test/run-pass/expr-copy.rs | 2 + src/test/run-pass/expr-if-struct.rs | 4 + src/test/run-pass/expr-match-struct.rs | 4 + src/test/run-pass/exterior.rs | 2 + src/test/run-pass/extern-pass-TwoU16s.rs | 2 + src/test/run-pass/extern-pass-TwoU32s.rs | 2 + src/test/run-pass/extern-pass-TwoU64s.rs | 2 + src/test/run-pass/extern-pass-TwoU8s.rs | 2 + src/test/run-pass/foreign-fn-with-byval.rs | 2 + src/test/run-pass/generic-fn.rs | 2 + src/test/run-pass/guards-not-exhaustive.rs | 2 + src/test/run-pass/guards.rs | 2 + src/test/run-pass/issue-12860.rs | 2 + src/test/run-pass/issue-19100.rs | 2 + src/test/run-pass/issue-2288.rs | 3 + src/test/run-pass/issue-2633.rs | 4 + src/test/run-pass/issue-3121.rs | 4 + src/test/run-pass/issue-3563-3.rs | 6 + src/test/run-pass/issue-3743.rs | 2 + src/test/run-pass/issue-3753.rs | 4 + src/test/run-pass/issue-5688.rs | 4 + src/test/run-pass/lang-item-public.rs | 1 + src/test/run-pass/match-arm-statics.rs | 2 + src/test/run-pass/method-self-arg-trait.rs | 2 + src/test/run-pass/method-self-arg.rs | 2 + .../run-pass/monomorphize-abi-alignment.rs | 15 +- src/test/run-pass/multidispatch1.rs | 2 + src/test/run-pass/multidispatch2.rs | 2 + src/test/run-pass/newtype.rs | 9 +- src/test/run-pass/out-pointer-aliasing.rs | 2 + .../run-pass/overloaded-autoderef-order.rs | 4 + src/test/run-pass/packed-struct-vec.rs | 2 + src/test/run-pass/rec-tup.rs | 2 + src/test/run-pass/rec.rs | 2 + .../run-pass/regions-dependent-addr-of.rs | 2 + ...egions-early-bound-used-in-bound-method.rs | 2 + .../regions-early-bound-used-in-bound.rs | 2 + .../regions-early-bound-used-in-type-param.rs | 2 + src/test/run-pass/regions-mock-tcx.rs | 9 + .../self-in-mut-slot-immediate-value.rs | 2 + .../run-pass/shape_intrinsic_tag_then_rec.rs | 67 ------ src/test/run-pass/simd-generics.rs | 2 + src/test/run-pass/small-enum-range-edge.rs | 6 + src/test/run-pass/struct-return.rs | 5 + src/test/run-pass/structured-compare.rs | 2 + src/test/run-pass/tag-variant-disr-val.rs | 2 + src/test/run-pass/trait-coercion-generic.rs | 2 + src/test/run-pass/trait-coercion.rs | 2 + .../run-pass/typeclasses-eq-example-static.rs | 11 +- src/test/run-pass/typeclasses-eq-example.rs | 8 +- src/test/run-pass/ufcs-explicit-self.rs | 4 + .../unboxed-closures-monomorphization.rs | 3 + 278 files changed, 2122 insertions(+), 404 deletions(-) delete mode 100644 src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs create mode 100644 src/test/compile-fail/opt-in-copy.rs delete mode 100644 src/test/compile-fail/stage0-clone-contravariant-lifetime.rs delete mode 100644 src/test/compile-fail/stage0-cmp.rs delete mode 100644 src/test/run-pass/shape_intrinsic_tag_then_rec.rs diff --git a/src/compiletest/common.rs b/src/compiletest/common.rs index 0a902d970ef32..62b757529dc9f 100644 --- a/src/compiletest/common.rs +++ b/src/compiletest/common.rs @@ -25,6 +25,8 @@ pub enum Mode { Codegen } +impl Copy for Mode {} + impl FromStr for Mode { fn from_str(s: &str) -> Option { match s { diff --git a/src/doc/guide-unsafe.md b/src/doc/guide-unsafe.md index 5b248126c80f0..bda1b34563208 100644 --- a/src/doc/guide-unsafe.md +++ b/src/doc/guide-unsafe.md @@ -661,6 +661,9 @@ extern { fn abort() -> !; } +#[lang = "owned_box"] +pub struct Box(*mut T); + #[lang="exchange_malloc"] unsafe fn allocate(size: uint, _align: uint) -> *mut u8 { let p = libc::malloc(size as libc::size_t) as *mut u8; diff --git a/src/doc/reference.md b/src/doc/reference.md index 1d27ac096df8a..6ee29326422a1 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1660,6 +1660,7 @@ Implementations are defined with the keyword `impl`. ``` # struct Point {x: f64, y: f64}; +# impl Copy for Point {} # type Surface = int; # struct BoundingBox {x: f64, y: f64, width: f64, height: f64}; # trait Shape { fn draw(&self, Surface); fn bounding_box(&self) -> BoundingBox; } @@ -1669,6 +1670,8 @@ struct Circle { center: Point, } +impl Copy for Circle {} + impl Shape for Circle { fn draw(&self, s: Surface) { do_draw_circle(s, *self); } fn bounding_box(&self) -> BoundingBox { @@ -1791,6 +1794,7 @@ default visibility with the `priv` keyword. When an item is declared as `pub`, it can be thought of as being accessible to the outside world. For example: ``` +# #![allow(missing_copy_implementations)] # fn main() {} // Declare a private struct struct Foo; diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 8b84ecb690455..95c4dff323ef0 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -466,7 +466,7 @@ impl TypedArena { } let ptr: &mut T = unsafe { - let ptr: &mut T = mem::transmute(self.ptr); + let ptr: &mut T = mem::transmute(self.ptr.clone()); ptr::write(ptr, object); self.ptr.set(self.ptr.get().offset(1)); ptr diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 330b93929746c..5a8d1c0a4f180 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -35,6 +35,8 @@ //! position: uint //! } //! +//! impl Copy for State {} +//! //! // The priority queue depends on `Ord`. //! // Explicitly implement the trait so the queue becomes a min-heap //! // instead of a max-heap. diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 39cdf0c456413..7e0f920d2760f 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -39,7 +39,12 @@ pub struct DList { } type Link = Option>>; -struct Rawlink { p: *mut T } + +struct Rawlink { + p: *mut T, +} + +impl Copy for Rawlink {} struct Node { next: Link, @@ -59,6 +64,8 @@ impl<'a, T> Clone for Items<'a, T> { fn clone(&self) -> Items<'a, T> { *self } } +impl<'a,T> Copy for Items<'a,T> {} + /// An iterator over mutable references to the items of a `DList`. pub struct MutItems<'a, T:'a> { list: &'a mut DList, diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index 2cbde0168a2e8..6523671d844d3 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -27,6 +27,8 @@ pub struct EnumSet { bits: uint } +impl Copy for EnumSet {} + impl fmt::Show for EnumSet { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "{{")); @@ -269,6 +271,8 @@ mod test { A, B, C } + impl Copy for Foo {} + impl CLike for Foo { fn to_uint(&self) -> uint { *self as uint @@ -477,6 +481,9 @@ mod test { V50, V51, V52, V53, V54, V55, V56, V57, V58, V59, V60, V61, V62, V63, V64, V65, V66, V67, V68, V69, } + + impl Copy for Bar {} + impl CLike for Bar { fn to_uint(&self) -> uint { *self as uint diff --git a/src/libcollections/hash/sip.rs b/src/libcollections/hash/sip.rs index ab69a3ad8b883..9a7aa8c20d3a1 100644 --- a/src/libcollections/hash/sip.rs +++ b/src/libcollections/hash/sip.rs @@ -43,6 +43,8 @@ pub struct SipState { ntail: uint, // how many bytes in tail are valid } +impl Copy for SipState {} + // sadly, these macro definitions can't appear later, // because they're needed in the following defs; // this design could be improved. @@ -211,6 +213,7 @@ impl Default for SipState { /// `SipHasher` computes the SipHash algorithm from a stream of bytes. #[deriving(Clone)] +#[allow(missing_copy_implementations)] pub struct SipHasher { k0: u64, k1: u64, diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 6c13abdaf892f..24abab07516b1 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -91,7 +91,7 @@ use self::Direction::*; use alloc::boxed::Box; use core::borrow::{BorrowFrom, BorrowFromMut, ToOwned}; use core::cmp; -use core::kinds::Sized; +use core::kinds::{Copy, Sized}; use core::mem::size_of; use core::mem; use core::prelude::{Clone, Greater, Iterator, IteratorExt, Less, None, Option}; @@ -177,12 +177,16 @@ impl ElementSwaps { enum Direction { Pos, Neg } +impl Copy for Direction {} + /// An `Index` and `Direction` together. struct SizeDirection { size: uint, dir: Direction, } +impl Copy for SizeDirection {} + impl Iterator<(uint, uint)> for ElementSwaps { #[inline] fn next(&mut self) -> Option<(uint, uint)> { @@ -1482,11 +1486,17 @@ mod tests { fn clone(&self) -> S { self.f.set(self.f.get() + 1); if self.f.get() == 10 { panic!() } - S { f: self.f, boxes: self.boxes.clone() } + S { + f: self.f.clone(), + boxes: self.boxes.clone(), + } } } - let s = S { f: Cell::new(0), boxes: (box 0, Rc::new(0)) }; + let s = S { + f: Cell::new(0), + boxes: (box 0, Rc::new(0)), + }; let _ = Vec::from_elem(100, s); } diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index ad0a5e7617646..0458752dacec3 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -228,24 +228,32 @@ impl<'a> Iterator for Decompositions<'a> { _ => self.sorted = false } - let decomposer = match self.kind { - Canonical => unicode::char::decompose_canonical, - Compatible => unicode::char::decompose_compatible - }; - if !self.sorted { for ch in self.iter { let buffer = &mut self.buffer; let sorted = &mut self.sorted; - decomposer(ch, |d| { - let class = unicode::char::canonical_combining_class(d); - if class == 0 && !*sorted { - canonical_sort(buffer.as_mut_slice()); - *sorted = true; + { + let callback = |d| { + let class = + unicode::char::canonical_combining_class(d); + if class == 0 && !*sorted { + canonical_sort(buffer.as_mut_slice()); + *sorted = true; + } + buffer.push((d, class)); + }; + match self.kind { + Canonical => { + unicode::char::decompose_canonical(ch, callback) + } + Compatible => { + unicode::char::decompose_compatible(ch, callback) + } } - buffer.push((d, class)); - }); - if *sorted { break } + } + if *sorted { + break + } } } diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index e930f353b5225..748f5d774a4bb 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -17,6 +17,7 @@ pub use self::Ordering::*; use intrinsics; use std::kinds::marker; use cell::UnsafeCell; +use kinds::Copy; /// A boolean type which can be safely shared between threads. #[stable] @@ -81,6 +82,8 @@ pub enum Ordering { SeqCst, } +impl Copy for Ordering {} + /// An `AtomicBool` initialized to `false`. #[unstable = "may be renamed, pending conventions for static initalizers"] pub const INIT_ATOMIC_BOOL: AtomicBool = diff --git a/src/libcore/char.rs b/src/libcore/char.rs index a729596e9d290..9cef2d2de5507 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -518,3 +518,4 @@ impl Iterator for DefaultEscapedChars { } } } + diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index df19256471ede..0c85fd11d869b 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -43,7 +43,7 @@ pub use self::Ordering::*; -use kinds::Sized; +use kinds::{Copy, Sized}; use option::{Option, Some, None}; /// Trait for values that can be compared for equality and inequality. @@ -105,6 +105,8 @@ pub enum Ordering { Greater = 1i, } +impl Copy for Ordering {} + impl Ordering { /// Reverse the `Ordering`, so that `Less` becomes `Greater` and /// vice versa. diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 1d6906c13a8fa..88a33139649aa 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -44,6 +44,8 @@ pub type Result = result::Result<(), Error>; #[experimental = "core and I/O reconciliation may alter this definition"] pub struct Error; +impl Copy for Error {} + /// A collection of methods that are required to format a message into a stream. /// /// This trait is the type which this modules requires when formatting @@ -102,6 +104,8 @@ pub struct Argument<'a> { value: &'a Void, } +impl<'a> Copy for Argument<'a> {} + impl<'a> Arguments<'a> { /// When using the format_args!() macro, this function is used to generate the /// Arguments structure. The compiler inserts an `unsafe` block to call this, diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index a441ced03b26e..fa6f48326b56b 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -16,6 +16,7 @@ use fmt; use iter::DoubleEndedIteratorExt; +use kinds::Copy; use num::{Int, cast}; use slice::SlicePrelude; @@ -114,6 +115,8 @@ pub struct Radix { base: u8, } +impl Copy for Radix {} + impl Radix { fn new(base: u8) -> Radix { assert!(2 <= base && base <= 36, "the base must be in the range of 2..36: {}", base); @@ -136,6 +139,8 @@ impl GenericRadix for Radix { #[unstable = "may be renamed or move to a different module"] pub struct RadixFmt(T, R); +impl Copy for RadixFmt where T: Copy, R: Copy {} + /// Constructs a radix formatter in the range of `2..36`. /// /// # Example diff --git a/src/libcore/fmt/rt.rs b/src/libcore/fmt/rt.rs index 145e78dc668ee..748bd0bc4bd00 100644 --- a/src/libcore/fmt/rt.rs +++ b/src/libcore/fmt/rt.rs @@ -20,6 +20,7 @@ pub use self::Alignment::*; pub use self::Count::*; pub use self::Position::*; pub use self::Flag::*; +use kinds::Copy; #[doc(hidden)] pub struct Argument<'a> { @@ -27,6 +28,8 @@ pub struct Argument<'a> { pub format: FormatSpec, } +impl<'a> Copy for Argument<'a> {} + #[doc(hidden)] pub struct FormatSpec { pub fill: char, @@ -36,6 +39,8 @@ pub struct FormatSpec { pub width: Count, } +impl Copy for FormatSpec {} + /// Possible alignments that can be requested as part of a formatting directive. #[deriving(PartialEq)] pub enum Alignment { @@ -49,16 +54,22 @@ pub enum Alignment { AlignUnknown, } +impl Copy for Alignment {} + #[doc(hidden)] pub enum Count { CountIs(uint), CountIsParam(uint), CountIsNextParam, CountImplied, } +impl Copy for Count {} + #[doc(hidden)] pub enum Position { ArgumentNext, ArgumentIs(uint) } +impl Copy for Position {} + /// Flags which can be passed to formatting via a directive. /// /// These flags are discovered through the `flags` field of the `Formatter` @@ -78,3 +89,5 @@ pub enum Flag { /// being aware of the sign to be printed. FlagSignAwareZeroPad, } + +impl Copy for Flag {} diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 347777b587aa5..6943e8a3615ac 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -42,6 +42,8 @@ #![experimental] #![allow(missing_docs)] +use kinds::Copy; + pub type GlueFn = extern "Rust" fn(*const i8); #[lang="ty_desc"] @@ -59,6 +61,8 @@ pub struct TyDesc { pub name: &'static str, } +impl Copy for TyDesc {} + extern "rust-intrinsic" { // NB: These intrinsics take unsafe pointers because they mutate aliased @@ -539,6 +543,8 @@ pub struct TypeId { t: u64, } +impl Copy for TypeId {} + impl TypeId { /// Returns the `TypeId` of the type this generic function has been instantiated with pub fn of() -> TypeId { diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index f9595f0663d57..7aa5abd36a3cd 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -59,6 +59,7 @@ pub use self::MinMaxResult::*; use clone::Clone; use cmp; use cmp::Ord; +use kinds::Copy; use mem; use num::{ToPrimitive, Int}; use ops::{Add, Deref}; @@ -1165,7 +1166,8 @@ pub struct Cycle { iter: T, } -#[unstable = "trait is unstable"] +impl Copy for Cycle {} + impl> Iterator for Cycle { #[inline] fn next(&mut self) -> Option { @@ -1575,7 +1577,8 @@ pub struct Peekable { peeked: Option, } -#[unstable = "trait is unstable"] +impl Copy for Peekable {} + impl> Iterator for Peekable { #[inline] fn next(&mut self) -> Option { @@ -2083,6 +2086,8 @@ pub struct Counter { step: A, } +impl Copy for Counter {} + /// Creates a new counter with the specified start/step #[inline] #[unstable = "may be renamed"] @@ -2114,6 +2119,8 @@ pub struct Range { one: A, } +impl Copy for Range {} + /// Returns an iterator over the given range [start, stop) (that is, starting /// at start (inclusive), and ending at stop (exclusive)). /// diff --git a/src/libcore/kinds.rs b/src/libcore/kinds.rs index 0c2cb9d591005..f932acffd3c2d 100644 --- a/src/libcore/kinds.rs +++ b/src/libcore/kinds.rs @@ -91,6 +91,8 @@ pub trait Sync for Sized? { /// implemented using unsafe code. In that case, you may want to embed /// some of the marker types below into your type. pub mod marker { + use super::Copy; + /// A marker type whose type parameter `T` is considered to be /// covariant with respect to the type itself. This is (typically) /// used to indicate that an instance of the type `T` is being stored @@ -132,6 +134,8 @@ pub mod marker { #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct CovariantType; + impl Copy for CovariantType {} + /// A marker type whose type parameter `T` is considered to be /// contravariant with respect to the type itself. This is (typically) /// used to indicate that an instance of the type `T` will be consumed @@ -175,6 +179,8 @@ pub mod marker { #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct ContravariantType; + impl Copy for ContravariantType {} + /// A marker type whose type parameter `T` is considered to be /// invariant with respect to the type itself. This is (typically) /// used to indicate that instances of the type `T` may be read or @@ -200,6 +206,8 @@ pub mod marker { #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct InvariantType; + impl Copy for InvariantType {} + /// As `CovariantType`, but for lifetime parameters. Using /// `CovariantLifetime<'a>` indicates that it is ok to substitute /// a *longer* lifetime for `'a` than the one you originally @@ -220,6 +228,8 @@ pub mod marker { #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct CovariantLifetime<'a>; + impl<'a> Copy for CovariantLifetime<'a> {} + /// As `ContravariantType`, but for lifetime parameters. Using /// `ContravariantLifetime<'a>` indicates that it is ok to /// substitute a *shorter* lifetime for `'a` than the one you @@ -236,6 +246,8 @@ pub mod marker { #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct ContravariantLifetime<'a>; + impl<'a> Copy for ContravariantLifetime<'a> {} + /// As `InvariantType`, but for lifetime parameters. Using /// `InvariantLifetime<'a>` indicates that it is not ok to /// substitute any other lifetime for `'a` besides its original @@ -253,6 +265,7 @@ pub mod marker { /// their instances remain thread-local. #[lang="no_send_bound"] #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] + #[allow(missing_copy_implementations)] pub struct NoSend; /// A type which is considered "not POD", meaning that it is not @@ -260,6 +273,7 @@ pub mod marker { /// ensure that they are never copied, even if they lack a destructor. #[lang="no_copy_bound"] #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] + #[allow(missing_copy_implementations)] pub struct NoCopy; /// A type which is considered "not sync", meaning that @@ -267,11 +281,14 @@ pub mod marker { /// shared between tasks. #[lang="no_sync_bound"] #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] + #[allow(missing_copy_implementations)] pub struct NoSync; /// A type which is considered managed by the GC. This is typically /// embedded in other types. #[lang="managed_bound"] #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] + #[allow(missing_copy_implementations)] pub struct Managed; } + diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index ce61bd97e1323..df14348f433cf 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1239,6 +1239,8 @@ pub enum FPCategory { FPNormal, } +impl Copy for FPCategory {} + /// A built-in floating point number. // FIXME(#5527): In a future version of Rust, many of these functions will // become constants. diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 4f4ec4867972e..df34b69caedde 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -90,6 +90,8 @@ pub trait Drop { /// ```rust /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl Add for Foo { /// fn add(&self, _rhs: &Foo) -> Foo { /// println!("Adding!"); @@ -128,6 +130,8 @@ add_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64) /// ```rust /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl Sub for Foo { /// fn sub(&self, _rhs: &Foo) -> Foo { /// println!("Subtracting!"); @@ -166,6 +170,8 @@ sub_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64) /// ```rust /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl Mul for Foo { /// fn mul(&self, _rhs: &Foo) -> Foo { /// println!("Multiplying!"); @@ -204,6 +210,8 @@ mul_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64) /// ``` /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl Div for Foo { /// fn div(&self, _rhs: &Foo) -> Foo { /// println!("Dividing!"); @@ -242,6 +250,8 @@ div_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64) /// ``` /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl Rem for Foo { /// fn rem(&self, _rhs: &Foo) -> Foo { /// println!("Remainder-ing!"); @@ -294,6 +304,8 @@ rem_float_impl!(f64, fmod) /// ``` /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl Neg for Foo { /// fn neg(&self) -> Foo { /// println!("Negating!"); @@ -348,6 +360,8 @@ neg_uint_impl!(u64, i64) /// ``` /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl Not for Foo { /// fn not(&self) -> Foo { /// println!("Not-ing!"); @@ -387,6 +401,8 @@ not_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64) /// ``` /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl BitAnd for Foo { /// fn bitand(&self, _rhs: &Foo) -> Foo { /// println!("Bitwise And-ing!"); @@ -425,6 +441,8 @@ bitand_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64) /// ``` /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl BitOr for Foo { /// fn bitor(&self, _rhs: &Foo) -> Foo { /// println!("Bitwise Or-ing!"); @@ -463,6 +481,8 @@ bitor_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64) /// ``` /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl BitXor for Foo { /// fn bitxor(&self, _rhs: &Foo) -> Foo { /// println!("Bitwise Xor-ing!"); @@ -501,6 +521,8 @@ bitxor_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64) /// ``` /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl Shl for Foo { /// fn shl(&self, _rhs: &Foo) -> Foo { /// println!("Shifting left!"); @@ -541,6 +563,8 @@ shl_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64) /// ``` /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl Shr for Foo { /// fn shr(&self, _rhs: &Foo) -> Foo { /// println!("Shifting right!"); @@ -580,6 +604,8 @@ shr_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64) /// ``` /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl Index for Foo { /// fn index<'a>(&'a self, _index: &Foo) -> &'a Foo { /// println!("Indexing!"); @@ -608,6 +634,8 @@ pub trait Index for Sized? { /// ``` /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl IndexMut for Foo { /// fn index_mut<'a>(&'a mut self, _index: &Foo) -> &'a mut Foo { /// println!("Indexing!"); @@ -636,6 +664,8 @@ pub trait IndexMut for Sized? { /// ```ignore /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl Slice for Foo { /// fn as_slice_<'a>(&'a self) -> &'a Foo { /// println!("Slicing!"); @@ -682,6 +712,8 @@ pub trait Slice for Sized? { /// ```ignore /// struct Foo; /// +/// impl Copy for Foo {} +/// /// impl SliceMut for Foo { /// fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo { /// println!("Slicing!"); diff --git a/src/libcore/option.rs b/src/libcore/option.rs index ef895a1d7fbcc..5d78af7afc74a 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -147,7 +147,9 @@ pub use self::Option::*; use cmp::{Eq, Ord}; use default::Default; -use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator}; +use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator}; +use iter::{ExactSizeIterator}; +use kinds::Copy; use mem; use result::{Result, Ok, Err}; use slice; @@ -856,3 +858,6 @@ impl> FromIterator> for Option { } } } + +impl Copy for Option {} + diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 416bc4588b43c..be9f1f2b8274d 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -434,3 +434,4 @@ impl PartialOrd for *mut T { #[inline] fn ge(&self, other: &*mut T) -> bool { *self >= *other } } + diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index d156f71462dd1..db1be94b2b83f 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -18,6 +18,7 @@ //! //! Their definition should always match the ABI defined in `rustc::back::abi`. +use kinds::Copy; use mem; use kinds::Sized; @@ -28,6 +29,8 @@ pub struct Slice { pub len: uint, } +impl Copy for Slice {} + /// The representation of a Rust closure #[repr(C)] pub struct Closure { @@ -35,6 +38,8 @@ pub struct Closure { pub env: *mut (), } +impl Copy for Closure {} + /// The representation of a Rust procedure (`proc()`) #[repr(C)] pub struct Procedure { @@ -42,6 +47,8 @@ pub struct Procedure { pub env: *mut (), } +impl Copy for Procedure {} + /// The representation of a Rust trait object. /// /// This struct does not have a `Repr` implementation @@ -52,6 +59,8 @@ pub struct TraitObject { pub vtable: *mut (), } +impl Copy for TraitObject {} + /// This trait is meant to map equivalences between raw structs and their /// corresponding rust values. pub trait Repr for Sized? { diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 7c88106c9eced..c014825343245 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -232,6 +232,7 @@ pub use self::Result::*; +use kinds::Copy; use std::fmt::Show; use slice; use slice::AsSlice; @@ -915,3 +916,7 @@ pub fn fold Copy for Result {} + diff --git a/src/libcore/simd.rs b/src/libcore/simd.rs index 2b6f97cf6a5c4..369a710658307 100644 --- a/src/libcore/simd.rs +++ b/src/libcore/simd.rs @@ -37,6 +37,8 @@ #![allow(non_camel_case_types)] #![allow(missing_docs)] +use kinds::Copy; + #[experimental] #[simd] #[deriving(Show)] @@ -46,6 +48,8 @@ pub struct i8x16(pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8); +impl Copy for i8x16 {} + #[experimental] #[simd] #[deriving(Show)] @@ -53,18 +57,24 @@ pub struct i8x16(pub i8, pub i8, pub i8, pub i8, pub struct i16x8(pub i16, pub i16, pub i16, pub i16, pub i16, pub i16, pub i16, pub i16); +impl Copy for i16x8 {} + #[experimental] #[simd] #[deriving(Show)] #[repr(C)] pub struct i32x4(pub i32, pub i32, pub i32, pub i32); +impl Copy for i32x4 {} + #[experimental] #[simd] #[deriving(Show)] #[repr(C)] pub struct i64x2(pub i64, pub i64); +impl Copy for i64x2 {} + #[experimental] #[simd] #[deriving(Show)] @@ -74,6 +84,8 @@ pub struct u8x16(pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8); +impl Copy for u8x16 {} + #[experimental] #[simd] #[deriving(Show)] @@ -81,26 +93,37 @@ pub struct u8x16(pub u8, pub u8, pub u8, pub u8, pub struct u16x8(pub u16, pub u16, pub u16, pub u16, pub u16, pub u16, pub u16, pub u16); +impl Copy for u16x8 {} + #[experimental] #[simd] #[deriving(Show)] #[repr(C)] pub struct u32x4(pub u32, pub u32, pub u32, pub u32); +impl Copy for u32x4 {} + #[experimental] #[simd] #[deriving(Show)] #[repr(C)] pub struct u64x2(pub u64, pub u64); +impl Copy for u64x2 {} + #[experimental] #[simd] #[deriving(Show)] #[repr(C)] pub struct f32x4(pub f32, pub f32, pub f32, pub f32); +impl Copy for f32x4 {} + #[experimental] #[simd] #[deriving(Show)] #[repr(C)] pub struct f64x2(pub f64, pub f64); + +impl Copy for f64x2 {} + diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 85bd6adf8b8a6..157437e8f2a58 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -40,6 +40,7 @@ use cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering, Less, Equal, Greater, Equiv} use cmp; use default::Default; use iter::*; +use kinds::Copy; use num::Int; use ops; use option::{None, Option, Some}; @@ -1155,6 +1156,8 @@ impl<'a, T> Items<'a, T> { } } +impl<'a,T> Copy for Items<'a,T> {} + iterator!{struct Items -> *const T, &'a T} #[experimental = "needs review"] @@ -1605,6 +1608,8 @@ pub enum BinarySearchResult { NotFound(uint) } +impl Copy for BinarySearchResult {} + #[experimental = "needs review"] impl BinarySearchResult { /// Converts a `Found` to `Some`, `NotFound` to `None`. @@ -1916,3 +1921,4 @@ impl_int_slice!(u16, i16) impl_int_slice!(u32, i32) impl_int_slice!(u64, i64) impl_int_slice!(uint, int) + diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 4be628f0ac3b3..7ceb67732ca12 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -26,7 +26,7 @@ use default::Default; use iter::{Map, Iterator, IteratorExt, DoubleEndedIterator}; use iter::{DoubleEndedIteratorExt, ExactSizeIterator}; use iter::range; -use kinds::Sized; +use kinds::{Copy, Sized}; use mem; use num::Int; use option::{Option, None, Some}; @@ -175,6 +175,8 @@ pub struct Chars<'a> { iter: slice::Items<'a, u8> } +impl<'a> Copy for Chars<'a> {} + // Return the initial codepoint accumulator for the first byte. // The first byte is special, only want bottom 5 bits for width 2, 4 bits // for width 3, and 3 bits for width 4 @@ -995,6 +997,8 @@ pub enum Utf16Item { LoneSurrogate(u16) } +impl Copy for Utf16Item {} + impl Utf16Item { /// Convert `self` to a `char`, taking `LoneSurrogate`s to the /// replacement character (U+FFFD). @@ -1138,6 +1142,8 @@ pub struct CharRange { pub next: uint, } +impl Copy for CharRange {} + /// Mask of the value bits of a continuation byte const CONT_MASK: u8 = 0b0011_1111u8; /// Value of the tag bits (tag mask is !CONT_MASK) of a continuation byte @@ -2312,3 +2318,4 @@ impl StrPrelude for str { impl<'a> Default for &'a str { fn default() -> &'a str { "" } } + diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 6b8fafbed5d77..7e53508b79566 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -39,6 +39,8 @@ pub enum Piece<'a> { NextArgument(Argument<'a>), } +impl<'a> Copy for Piece<'a> {} + /// Representation of an argument specification. #[deriving(PartialEq)] pub struct Argument<'a> { @@ -48,6 +50,8 @@ pub struct Argument<'a> { pub format: FormatSpec<'a>, } +impl<'a> Copy for Argument<'a> {} + /// Specification for the formatting of an argument in the format string. #[deriving(PartialEq)] pub struct FormatSpec<'a> { @@ -67,6 +71,8 @@ pub struct FormatSpec<'a> { pub ty: &'a str } +impl<'a> Copy for FormatSpec<'a> {} + /// Enum describing where an argument for a format can be located. #[deriving(PartialEq)] pub enum Position<'a> { @@ -78,6 +84,8 @@ pub enum Position<'a> { ArgumentNamed(&'a str), } +impl<'a> Copy for Position<'a> {} + /// Enum of alignments which are supported. #[deriving(PartialEq)] pub enum Alignment { @@ -91,6 +99,8 @@ pub enum Alignment { AlignUnknown, } +impl Copy for Alignment {} + /// Various flags which can be applied to format strings. The meaning of these /// flags is defined by the formatters themselves. #[deriving(PartialEq)] @@ -107,6 +117,8 @@ pub enum Flag { FlagSignAwareZeroPad, } +impl Copy for Flag {} + /// A count is used for the precision and width parameters of an integer, and /// can reference either an argument or a literal integer. #[deriving(PartialEq)] @@ -123,6 +135,8 @@ pub enum Count<'a> { CountImplied, } +impl<'a> Copy for Count<'a> {} + /// The parser structure for interpreting the input format string. This is /// modelled as an iterator over `Piece` structures to form a stream of tokens /// being output. diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 1204ac18f99dc..c764520ade31a 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -97,6 +97,9 @@ use self::HasArg::*; use self::Occur::*; use self::Fail::*; use self::Optval::*; +use self::SplitWithinState::*; +use self::Whitespace::*; +use self::LengthLimit::*; use std::fmt; use std::result::{Err, Ok}; @@ -125,6 +128,8 @@ pub enum HasArg { Maybe, } +impl Copy for HasArg {} + /// Describes how often an option may occur. #[deriving(Clone, PartialEq, Eq)] pub enum Occur { @@ -136,6 +141,8 @@ pub enum Occur { Multi, } +impl Copy for Occur {} + /// A description of a possible option. #[deriving(Clone, PartialEq, Eq)] pub struct Opt { @@ -203,6 +210,19 @@ pub enum Fail { UnexpectedArgument(String), } +/// The type of failure that occurred. +#[deriving(PartialEq, Eq)] +#[allow(missing_docs)] +pub enum FailType { + ArgumentMissing_, + UnrecognizedOption_, + OptionMissing_, + OptionDuplicated_, + UnexpectedArgument_, +} + +impl Copy for FailType {} + /// The result of parsing a command line with a set of options. pub type Result = result::Result; @@ -825,14 +845,17 @@ enum SplitWithinState { B, // words C, // internal and trailing whitespace } +impl Copy for SplitWithinState {} enum Whitespace { Ws, // current char is whitespace Cr // current char is not whitespace } +impl Copy for Whitespace {} enum LengthLimit { UnderLim, // current char makes current substring still fit in limit OverLim // current char makes current substring no longer fit in limit } +impl Copy for LengthLimit {} /// Splits a string into substrings with possibly internal whitespace, @@ -848,9 +871,6 @@ enum LengthLimit { /// sequence longer than the limit. fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool) -> bool { - use self::SplitWithinState::*; - use self::Whitespace::*; - use self::LengthLimit::*; // Just for fun, let's write this as a state machine: let mut slice_start = 0; diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 18e9d832c003d..4c92e015aba45 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -340,12 +340,15 @@ pub mod types { /// variants, because the compiler complains about the repr attribute /// otherwise. #[repr(u8)] + #[allow(missing_copy_implementations)] pub enum c_void { __variant1, __variant2, } + #[allow(missing_copy_implementations)] pub enum FILE {} + #[allow(missing_copy_implementations)] pub enum fpos_t {} } pub mod c99 { @@ -359,7 +362,9 @@ pub mod types { pub type uint64_t = u64; } pub mod posix88 { + #[allow(missing_copy_implementations)] pub enum DIR {} + #[allow(missing_copy_implementations)] pub enum dirent_t {} } pub mod posix01 {} @@ -1670,9 +1675,10 @@ pub mod types { pub mod os { pub mod common { pub mod posix01 { + use core::kinds::Copy; use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, size_t, - time_t, suseconds_t, c_long}; + use types::os::arch::c95::{c_char, c_int, size_t, time_t}; + use types::os::arch::c95::{suseconds_t, c_long}; use types::os::arch::c99::{uintptr_t}; pub type pthread_t = uintptr_t; @@ -1694,24 +1700,32 @@ pub mod types { pub __unused8: *mut c_void, } + impl Copy for glob_t {} + #[repr(C)] pub struct timeval { pub tv_sec: time_t, pub tv_usec: suseconds_t, } + impl Copy for timeval {} + #[repr(C)] pub struct timespec { pub tv_sec: time_t, pub tv_nsec: c_long, } + impl Copy for timespec {} + + #[allow(missing_copy_implementations)] pub enum timezone {} pub type sighandler_t = size_t; } pub mod bsd44 { + use core::kinds::Copy; use types::common::c95::{c_void}; use types::os::arch::c95::{c_char, c_int, c_uint}; @@ -1725,6 +1739,9 @@ pub mod types { pub sa_family: sa_family_t, pub sa_data: [u8, ..14], } + + impl Copy for sockaddr {} + #[repr(C)] pub struct sockaddr_storage { pub ss_len: u8, @@ -1733,6 +1750,9 @@ pub mod types { pub __ss_align: i64, pub __ss_pad2: [u8, ..112], } + + impl Copy for sockaddr_storage {} + #[repr(C)] pub struct sockaddr_in { pub sin_len: u8, @@ -1741,10 +1761,16 @@ pub mod types { pub sin_addr: in_addr, pub sin_zero: [u8, ..8], } + + impl Copy for sockaddr_in {} + #[repr(C)] pub struct in_addr { pub s_addr: in_addr_t, } + + impl Copy for in_addr {} + #[repr(C)] pub struct sockaddr_in6 { pub sin6_len: u8, @@ -1754,20 +1780,32 @@ pub mod types { pub sin6_addr: in6_addr, pub sin6_scope_id: u32, } + + impl Copy for sockaddr_in6 {} + #[repr(C)] pub struct in6_addr { pub s6_addr: [u16, ..8] } + + impl Copy for in6_addr {} + #[repr(C)] pub struct ip_mreq { pub imr_multiaddr: in_addr, pub imr_interface: in_addr, } + + impl Copy for ip_mreq {} + #[repr(C)] pub struct ip6_mreq { pub ipv6mr_multiaddr: in6_addr, pub ipv6mr_interface: c_uint, } + + impl Copy for ip6_mreq {} + #[repr(C)] pub struct addrinfo { pub ai_flags: c_int, @@ -1779,12 +1817,18 @@ pub mod types { pub ai_addr: *mut sockaddr, pub ai_next: *mut addrinfo, } + + impl Copy for addrinfo {} + #[repr(C)] pub struct sockaddr_un { pub sun_len: u8, pub sun_family: sa_family_t, pub sun_path: [c_char, ..104] } + + impl Copy for sockaddr_un {} + #[repr(C)] pub struct ifaddrs { pub ifa_next: *mut ifaddrs, @@ -1795,6 +1839,8 @@ pub mod types { pub ifa_dstaddr: *mut sockaddr, pub ifa_data: *mut c_void } + + impl Copy for ifaddrs {} } } @@ -1839,6 +1885,7 @@ pub mod types { pub type ssize_t = i32; } pub mod posix01 { + use core::kinds::Copy; use types::common::c99::{int32_t, int64_t, uint32_t}; use types::os::arch::c95::{c_char, c_long, time_t}; use types::os::arch::posix88::{dev_t, gid_t, ino_t, @@ -1874,29 +1921,40 @@ pub mod types { pub st_qspare: [int64_t, ..2], } + impl Copy for stat {} + + #[repr(C)] pub struct utimbuf { pub actime: time_t, pub modtime: time_t, } + impl Copy for utimbuf {} + #[repr(C)] pub struct pthread_attr_t { pub __sig: c_long, pub __opaque: [c_char, ..36] } + + impl Copy for pthread_attr_t {} } pub mod posix08 { } pub mod bsd44 { } pub mod extra { + use core::kinds::Copy; + #[repr(C)] pub struct mach_timebase_info { pub numer: u32, pub denom: u32, } + impl Copy for mach_timebase_info {} + pub type mach_timebase_info_data_t = mach_timebase_info; } } @@ -1942,6 +2000,7 @@ pub mod types { pub type ssize_t = i64; } pub mod posix01 { + use core::kinds::Copy; use types::common::c99::{int32_t, int64_t}; use types::common::c99::{uint32_t}; use types::os::arch::c95::{c_char, c_long, time_t}; @@ -1978,29 +2037,39 @@ pub mod types { pub st_qspare: [int64_t, ..2], } + impl Copy for stat {} + #[repr(C)] pub struct utimbuf { pub actime: time_t, pub modtime: time_t, } + impl Copy for utimbuf {} + #[repr(C)] pub struct pthread_attr_t { pub __sig: c_long, pub __opaque: [c_char, ..56] } + + impl Copy for pthread_attr_t {} } pub mod posix08 { } pub mod bsd44 { } pub mod extra { + use core::kinds::Copy; + #[repr(C)] pub struct mach_timebase_info { pub numer: u32, pub denom: u32, } + impl Copy for mach_timebase_info {} + pub type mach_timebase_info_data_t = mach_timebase_info; } } diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 5642ec91ba3b4..8b79078eac6ad 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -234,6 +234,8 @@ struct DefaultLogger { #[deriving(PartialEq, PartialOrd)] pub struct LogLevel(pub u32); +impl Copy for LogLevel {} + impl fmt::Show for LogLevel { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let LogLevel(level) = *self; @@ -344,6 +346,8 @@ pub struct LogLocation { pub line: uint, } +impl Copy for LogLocation {} + /// Tests whether a given module's name is enabled for a particular level of /// logging. This is the second layer of defense about determining whether a /// module's log statement should be emitted or not. diff --git a/src/librand/chacha.rs b/src/librand/chacha.rs index 2693f18364430..83a410674eefa 100644 --- a/src/librand/chacha.rs +++ b/src/librand/chacha.rs @@ -35,6 +35,8 @@ pub struct ChaChaRng { index: uint, // Index into state } +impl Copy for ChaChaRng {} + static EMPTY: ChaChaRng = ChaChaRng { buffer: [0, ..STATE_WORDS], state: [0, ..STATE_WORDS], diff --git a/src/librand/distributions/exponential.rs b/src/librand/distributions/exponential.rs index d874f1deed3c2..9a9f31e9339c8 100644 --- a/src/librand/distributions/exponential.rs +++ b/src/librand/distributions/exponential.rs @@ -10,6 +10,7 @@ //! The exponential distribution. +use core::kinds::Copy; use core::num::Float; use {Rng, Rand}; @@ -31,6 +32,8 @@ use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample}; /// College, Oxford pub struct Exp1(pub f64); +impl Copy for Exp1 {} + // This could be done via `-rng.gen::().ln()` but that is slower. impl Rand for Exp1 { #[inline] @@ -71,6 +74,8 @@ pub struct Exp { lambda_inverse: f64 } +impl Copy for Exp {} + impl Exp { /// Construct a new `Exp` with the given shape parameter /// `lambda`. Panics if `lambda <= 0`. diff --git a/src/librand/distributions/normal.rs b/src/librand/distributions/normal.rs index b3dc20819bc85..f5261f1db82ee 100644 --- a/src/librand/distributions/normal.rs +++ b/src/librand/distributions/normal.rs @@ -10,6 +10,7 @@ //! The normal and derived distributions. +use core::kinds::Copy; use core::num::Float; use {Rng, Rand, Open01}; @@ -30,6 +31,8 @@ use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample}; /// College, Oxford pub struct StandardNormal(pub f64); +impl Copy for StandardNormal {} + impl Rand for StandardNormal { fn rand(rng: &mut R) -> StandardNormal { #[inline] @@ -88,6 +91,8 @@ pub struct Normal { std_dev: f64, } +impl Copy for Normal {} + impl Normal { /// Construct a new `Normal` distribution with the given mean and /// standard deviation. @@ -134,6 +139,8 @@ pub struct LogNormal { norm: Normal } +impl Copy for LogNormal {} + impl LogNormal { /// Construct a new `LogNormal` distribution with the given mean /// and standard deviation. diff --git a/src/librand/isaac.rs b/src/librand/isaac.rs index 517b50c49c7ef..2c1853b195151 100644 --- a/src/librand/isaac.rs +++ b/src/librand/isaac.rs @@ -37,6 +37,9 @@ pub struct IsaacRng { b: u32, c: u32 } + +impl Copy for IsaacRng {} + static EMPTY: IsaacRng = IsaacRng { cnt: 0, rsl: [0, ..RAND_SIZE_UINT], @@ -271,6 +274,8 @@ pub struct Isaac64Rng { c: u64, } +impl Copy for Isaac64Rng {} + static EMPTY_64: Isaac64Rng = Isaac64Rng { cnt: 0, rsl: [0, .. RAND_SIZE_64], diff --git a/src/librand/lib.rs b/src/librand/lib.rs index de40ee4893d56..d357f247f1b74 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -377,6 +377,7 @@ pub trait SeedableRng: Rng { /// [1]: Marsaglia, George (July 2003). ["Xorshift /// RNGs"](http://www.jstatsoft.org/v08/i14/paper). *Journal of /// Statistical Software*. Vol. 8 (Issue 14). +#[allow(missing_copy_implementations)] pub struct XorShiftRng { x: u32, y: u32, @@ -384,6 +385,17 @@ pub struct XorShiftRng { w: u32, } +impl Clone for XorShiftRng { + fn clone(&self) -> XorShiftRng { + XorShiftRng { + x: self.x, + y: self.y, + z: self.z, + w: self.w, + } + } +} + impl XorShiftRng { /// Creates a new XorShiftRng instance which is not seeded. /// diff --git a/src/librand/reseeding.rs b/src/librand/reseeding.rs index 64c6b1739ebb1..88c870579e690 100644 --- a/src/librand/reseeding.rs +++ b/src/librand/reseeding.rs @@ -135,6 +135,8 @@ pub trait Reseeder { /// replacing the RNG with the result of a `Default::default` call. pub struct ReseedWithDefault; +impl Copy for ReseedWithDefault {} + impl Reseeder for ReseedWithDefault { fn reseed(&mut self, rng: &mut R) { *rng = Default::default(); diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index 6f3fbe1251008..55fe1910795dd 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -47,6 +47,8 @@ pub struct Doc<'a> { pub end: uint, } +impl<'doc> Copy for Doc<'doc> {} + impl<'doc> Doc<'doc> { pub fn new(data: &'doc [u8]) -> Doc<'doc> { Doc { data: data, start: 0u, end: data.len() } @@ -104,6 +106,8 @@ pub enum EbmlEncoderTag { EsLabel, // Used only when debugging } +impl Copy for EbmlEncoderTag {} + #[deriving(Show)] pub enum Error { IntTooBig(uint), @@ -150,6 +154,8 @@ pub mod reader { pub next: uint } + impl Copy for Res {} + #[inline(never)] fn vuint_at_slow(data: &[u8], start: uint) -> DecodeResult { let a = data[start]; diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index 2bf3fa992cd66..3e2876ce59942 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -83,6 +83,8 @@ pub enum Greed { Ungreedy, } +impl Copy for Greed {} + impl Greed { pub fn is_greedy(&self) -> bool { match *self { diff --git a/src/libregex/re.rs b/src/libregex/re.rs index 58ce72a31736d..2a1fda06431c8 100644 --- a/src/libregex/re.rs +++ b/src/libregex/re.rs @@ -135,8 +135,12 @@ pub struct ExNative { pub prog: fn(MatchKind, &str, uint, uint) -> Vec> } +impl Copy for ExNative {} + impl Clone for ExNative { - fn clone(&self) -> ExNative { *self } + fn clone(&self) -> ExNative { + *self + } } impl fmt::Show for Regex { @@ -917,7 +921,7 @@ fn exec_slice(re: &Regex, which: MatchKind, input: &str, s: uint, e: uint) -> CaptureLocs { match *re { Dynamic(ExDynamic { ref prog, .. }) => vm::run(which, prog, input, s, e), - Native(ExNative { prog, .. }) => prog(which, input, s, e), + Native(ExNative { ref prog, .. }) => (*prog)(which, input, s, e), } } diff --git a/src/libregex/vm.rs b/src/libregex/vm.rs index 79019d213b8ba..6a9cacc7f3596 100644 --- a/src/libregex/vm.rs +++ b/src/libregex/vm.rs @@ -60,6 +60,8 @@ pub enum MatchKind { Submatches, } +impl Copy for MatchKind {} + /// Runs an NFA simulation on the compiled expression given on the search text /// `input`. The search begins at byte index `start` and ends at byte index /// `end`. (The range is specified here so that zero-width assertions will work @@ -107,6 +109,8 @@ pub enum StepState { StepContinue, } +impl Copy for StepState {} + impl<'r, 't> Nfa<'r, 't> { fn run(&mut self) -> CaptureLocs { let ncaps = match self.which { diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 9a214d531d157..9ab2ce9f2c9b4 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -28,6 +28,7 @@ use self::MethodContext::*; use metadata::csearch; use middle::def::*; +use middle::subst::Substs; use middle::ty::{mod, Ty}; use middle::typeck::astconv::ast_ty_to_ty; use middle::typeck::{mod, infer}; @@ -42,11 +43,12 @@ use std::collections::hash_map::{Occupied, Vacant}; use std::num::SignedInt; use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64}; use syntax::{abi, ast, ast_map}; -use syntax::ast_util::{mod, is_shift_binop}; +use syntax::ast_util::is_shift_binop; use syntax::attr::{mod, AttrMetaMethods}; use syntax::codemap::{Span, DUMMY_SP}; use syntax::parse::token; use syntax::ast::{TyI, TyU, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64}; +use syntax::ast_util; use syntax::ptr::P; use syntax::visit::{mod, Visitor}; @@ -55,6 +57,8 @@ declare_lint!(WHILE_TRUE, Warn, pub struct WhileTrue; +impl Copy for WhileTrue {} + impl LintPass for WhileTrue { fn get_lints(&self) -> LintArray { lint_array!(WHILE_TRUE) @@ -77,6 +81,8 @@ declare_lint!(UNUSED_TYPECASTS, Allow, pub struct UnusedCasts; +impl Copy for UnusedCasts {} + impl LintPass for UnusedCasts { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_TYPECASTS) @@ -109,6 +115,8 @@ pub struct TypeLimits { negated_expr_id: ast::NodeId, } +impl Copy for TypeLimits {} + impl TypeLimits { pub fn new() -> TypeLimits { TypeLimits { @@ -417,6 +425,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ImproperCTypesVisitor<'a, 'tcx> { pub struct ImproperCTypes; +impl Copy for ImproperCTypes {} + impl LintPass for ImproperCTypes { fn get_lints(&self) -> LintArray { lint_array!(IMPROPER_CTYPES) @@ -456,6 +466,8 @@ declare_lint!(BOX_POINTERS, Allow, pub struct BoxPointers; +impl Copy for BoxPointers {} + impl BoxPointers { fn check_heap_type<'a, 'tcx>(&self, cx: &Context<'a, 'tcx>, span: Span, ty: Ty<'tcx>) { @@ -589,6 +601,8 @@ declare_lint!(UNUSED_ATTRIBUTES, Warn, pub struct UnusedAttributes; +impl Copy for UnusedAttributes {} + impl LintPass for UnusedAttributes { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_ATTRIBUTES) @@ -668,6 +682,8 @@ declare_lint!(pub PATH_STATEMENTS, Warn, pub struct PathStatements; +impl Copy for PathStatements {} + impl LintPass for PathStatements { fn get_lints(&self) -> LintArray { lint_array!(PATH_STATEMENTS) @@ -695,6 +711,8 @@ declare_lint!(pub UNUSED_RESULTS, Allow, pub struct UnusedResults; +impl Copy for UnusedResults {} + impl LintPass for UnusedResults { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_MUST_USE, UNUSED_RESULTS) @@ -759,6 +777,8 @@ declare_lint!(pub NON_CAMEL_CASE_TYPES, Warn, pub struct NonCamelCaseTypes; +impl Copy for NonCamelCaseTypes {} + impl NonCamelCaseTypes { fn check_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) { fn is_camel_case(ident: ast::Ident) -> bool { @@ -878,6 +898,8 @@ declare_lint!(pub NON_SNAKE_CASE, Warn, pub struct NonSnakeCase; +impl Copy for NonSnakeCase {} + impl NonSnakeCase { fn check_snake_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) { fn is_snake_case(ident: ast::Ident) -> bool { @@ -987,6 +1009,8 @@ declare_lint!(pub NON_UPPER_CASE_GLOBALS, Warn, pub struct NonUpperCaseGlobals; +impl Copy for NonUpperCaseGlobals {} + impl LintPass for NonUpperCaseGlobals { fn get_lints(&self) -> LintArray { lint_array!(NON_UPPER_CASE_GLOBALS) @@ -1036,6 +1060,8 @@ declare_lint!(UNUSED_PARENS, Warn, pub struct UnusedParens; +impl Copy for UnusedParens {} + impl UnusedParens { fn check_unused_parens_core(&self, cx: &Context, value: &ast::Expr, msg: &str, struct_lit_needs_parens: bool) { @@ -1126,6 +1152,8 @@ declare_lint!(UNUSED_IMPORT_BRACES, Allow, pub struct UnusedImportBraces; +impl Copy for UnusedImportBraces {} + impl LintPass for UnusedImportBraces { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_IMPORT_BRACES) @@ -1161,6 +1189,8 @@ declare_lint!(NON_SHORTHAND_FIELD_PATTERNS, Warn, pub struct NonShorthandFieldPatterns; +impl Copy for NonShorthandFieldPatterns {} + impl LintPass for NonShorthandFieldPatterns { fn get_lints(&self) -> LintArray { lint_array!(NON_SHORTHAND_FIELD_PATTERNS) @@ -1190,6 +1220,8 @@ declare_lint!(pub UNUSED_UNSAFE, Warn, pub struct UnusedUnsafe; +impl Copy for UnusedUnsafe {} + impl LintPass for UnusedUnsafe { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_UNSAFE) @@ -1211,6 +1243,8 @@ declare_lint!(UNSAFE_BLOCKS, Allow, pub struct UnsafeBlocks; +impl Copy for UnsafeBlocks {} + impl LintPass for UnsafeBlocks { fn get_lints(&self) -> LintArray { lint_array!(UNSAFE_BLOCKS) @@ -1231,6 +1265,8 @@ declare_lint!(pub UNUSED_MUT, Warn, pub struct UnusedMut; +impl Copy for UnusedMut {} + impl UnusedMut { fn check_unused_mut_pat(&self, cx: &Context, pats: &[P]) { // collect all mutable pattern and group their NodeIDs by their Identifier to @@ -1296,6 +1332,8 @@ declare_lint!(UNUSED_ALLOCATION, Warn, pub struct UnusedAllocation; +impl Copy for UnusedAllocation {} + impl LintPass for UnusedAllocation { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_ALLOCATION) @@ -1480,6 +1518,61 @@ impl LintPass for MissingDoc { } } +pub struct MissingCopyImplementations; + +impl Copy for MissingCopyImplementations {} + +impl LintPass for MissingCopyImplementations { + fn get_lints(&self) -> LintArray { + lint_array!(MISSING_COPY_IMPLEMENTATIONS) + } + + fn check_item(&mut self, cx: &Context, item: &ast::Item) { + if !cx.exported_items.contains(&item.id) { + return + } + if cx.tcx + .destructor_for_type + .borrow() + .contains_key(&ast_util::local_def(item.id)) { + return + } + let ty = match item.node { + ast::ItemStruct(_, ref ast_generics) => { + if ast_generics.is_parameterized() { + return + } + ty::mk_struct(cx.tcx, + ast_util::local_def(item.id), + Substs::empty()) + } + ast::ItemEnum(_, ref ast_generics) => { + if ast_generics.is_parameterized() { + return + } + ty::mk_enum(cx.tcx, + ast_util::local_def(item.id), + Substs::empty()) + } + _ => return, + }; + let parameter_environment = ty::empty_parameter_environment(); + if !ty::type_moves_by_default(cx.tcx, + ty, + ¶meter_environment) { + return + } + if ty::can_type_implement_copy(cx.tcx, + ty, + ¶meter_environment).is_ok() { + cx.span_lint(MISSING_COPY_IMPLEMENTATIONS, + item.span, + "type could implement `Copy`; consider adding `impl \ + Copy`") + } + } +} + declare_lint!(DEPRECATED, Warn, "detects use of #[deprecated] items") @@ -1494,6 +1587,8 @@ declare_lint!(UNSTABLE, Allow, /// `#[unstable]` attributes, or no stability attribute. pub struct Stability; +impl Copy for Stability {} + impl Stability { fn lint(&self, cx: &Context, id: ast::DefId, span: Span) { let stability = stability::lookup(cx.tcx, id); @@ -1683,10 +1778,15 @@ declare_lint!(pub VARIANT_SIZE_DIFFERENCES, Allow, declare_lint!(pub FAT_PTR_TRANSMUTES, Allow, "detects transmutes of fat pointers") +declare_lint!(pub MISSING_COPY_IMPLEMENTATIONS, Warn, + "detects potentially-forgotten implementations of `Copy`") + /// Does nothing as a lint pass, but registers some `Lint`s /// which are used by other parts of the compiler. pub struct HardwiredLints; +impl Copy for HardwiredLints {} + impl LintPass for HardwiredLints { fn get_lints(&self) -> LintArray { lint_array!( diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index c7bed838eb919..a504e6b1264b7 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -208,6 +208,7 @@ impl LintStore { UnusedMut, UnusedAllocation, Stability, + MissingCopyImplementations, ) add_builtin_with_new!(sess, diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index d6b83752cc50c..4b4ba2ab94cd2 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -64,6 +64,8 @@ pub struct Lint { pub desc: &'static str, } +impl Copy for Lint {} + impl Lint { /// Get the lint's name, with ASCII letters converted to lowercase. pub fn name_lower(&self) -> String { @@ -179,6 +181,8 @@ pub struct LintId { lint: &'static Lint, } +impl Copy for LintId {} + impl PartialEq for LintId { fn eq(&self, other: &LintId) -> bool { (self.lint as *const Lint) == (other.lint as *const Lint) @@ -214,6 +218,8 @@ pub enum Level { Allow, Warn, Deny, Forbid } +impl Copy for Level {} + impl Level { /// Convert a level to a lower-case string. pub fn as_str(self) -> &'static str { @@ -251,6 +257,8 @@ pub enum LintSource { CommandLine, } +impl Copy for LintSource {} + pub type LevelSource = (Level, LintSource); pub mod builtin; diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index 0da3b1b7a4e3e..315e0eea9b763 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -144,6 +144,8 @@ pub enum astencode_tag { // Reserves 0x40 -- 0x5f tag_table_capture_modes = 0x56, tag_table_object_cast_map = 0x57, } + +impl Copy for astencode_tag {} static first_astencode_tag: uint = tag_ast as uint; static last_astencode_tag: uint = tag_table_object_cast_map as uint; impl astencode_tag { diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 5a8d60fbecd6c..aadb4fc9e7180 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -275,8 +275,10 @@ fn visit_item(e: &Env, i: &ast::Item) { } } -fn register_native_lib(sess: &Session, span: Option, name: String, - kind: cstore::NativeLibaryKind) { +fn register_native_lib(sess: &Session, + span: Option, + name: String, + kind: cstore::NativeLibraryKind) { if name.as_slice().is_empty() { match span { Some(span) => { diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 20e3f27f2ae18..ecf560cf071b6 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -41,6 +41,8 @@ pub struct MethodInfo { pub vis: ast::Visibility, } +impl Copy for MethodInfo {} + pub fn get_symbol(cstore: &cstore::CStore, def: ast::DefId) -> String { let cdata = cstore.get_crate_data(def.krate); decoder::get_symbol(cdata.data(), def.node) @@ -274,9 +276,8 @@ pub fn get_impl_vtables<'tcx>(tcx: &ty::ctxt<'tcx>, decoder::get_impl_vtables(&*cdata, def.node, tcx) } -pub fn get_native_libraries(cstore: &cstore::CStore, - crate_num: ast::CrateNum) - -> Vec<(cstore::NativeLibaryKind, String)> { +pub fn get_native_libraries(cstore: &cstore::CStore, crate_num: ast::CrateNum) + -> Vec<(cstore::NativeLibraryKind, String)> { let cdata = cstore.get_crate_data(crate_num); decoder::get_native_libraries(&*cdata) } diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index c844c8940fe62..2f8bfd4d0b3d6 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -15,7 +15,7 @@ pub use self::MetadataBlob::*; pub use self::LinkagePreference::*; -pub use self::NativeLibaryKind::*; +pub use self::NativeLibraryKind::*; use back::svh::Svh; use metadata::decoder; @@ -54,13 +54,17 @@ pub enum LinkagePreference { RequireStatic, } -#[deriving(PartialEq, FromPrimitive, Clone)] -pub enum NativeLibaryKind { +impl Copy for LinkagePreference {} + +#[deriving(Clone, PartialEq, FromPrimitive)] +pub enum NativeLibraryKind { NativeStatic, // native static library (.a archive) NativeFramework, // OSX-specific NativeUnknown, // default way to specify a dynamic library } +impl Copy for NativeLibraryKind {} + // Where a crate came from on the local filesystem. One of these two options // must be non-None. #[deriving(PartialEq, Clone)] @@ -75,7 +79,7 @@ pub struct CStore { /// Map from NodeId's of local extern crate statements to crate numbers extern_mod_crate_map: RefCell>, used_crate_sources: RefCell>, - used_libraries: RefCell>, + used_libraries: RefCell>, used_link_args: RefCell>, pub intr: Rc, } @@ -187,13 +191,14 @@ impl CStore { libs } - pub fn add_used_library(&self, lib: String, kind: NativeLibaryKind) { + pub fn add_used_library(&self, lib: String, kind: NativeLibraryKind) { assert!(!lib.is_empty()); self.used_libraries.borrow_mut().push((lib, kind)); } pub fn get_used_libraries<'a>(&'a self) - -> &'a RefCell > { + -> &'a RefCell> { &self.used_libraries } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index ec812cea3728d..6e92ebc18484d 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -443,6 +443,8 @@ pub enum DefLike { DlField } +impl Copy for DefLike {} + /// Iterates over the language items in the given crate. pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool { let root = rbml::Doc::new(cdata.data()); @@ -1268,14 +1270,14 @@ pub fn get_trait_of_item(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt) pub fn get_native_libraries(cdata: Cmd) - -> Vec<(cstore::NativeLibaryKind, String)> { + -> Vec<(cstore::NativeLibraryKind, String)> { let libraries = reader::get_doc(rbml::Doc::new(cdata.data()), tag_native_libraries); let mut result = Vec::new(); reader::tagged_docs(libraries, tag_native_libraries_lib, |lib_doc| { let kind_doc = reader::get_doc(lib_doc, tag_native_libraries_kind); let name_doc = reader::get_doc(lib_doc, tag_native_libraries_name); - let kind: cstore::NativeLibaryKind = + let kind: cstore::NativeLibraryKind = FromPrimitive::from_u32(reader::doc_as_u32(kind_doc)).unwrap(); let name = name_doc.as_str().to_string(); result.push((kind, name)); diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 89f3343ef123a..ad08322ceaab1 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -20,7 +20,12 @@ use std::os; use util::fs as myfs; -pub enum FileMatch { FileMatches, FileDoesntMatch } +pub enum FileMatch { + FileMatches, + FileDoesntMatch, +} + +impl Copy for FileMatch {} // A module for searching for libraries // FIXME (#2658): I'm not happy how this module turned out. Should diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 00d12ad6a382d..e29741fb4a129 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -61,6 +61,8 @@ pub enum DefIdSource { // Identifies an unboxed closure UnboxedClosureSource } + +impl Copy for DefIdSource {} pub type conv_did<'a> = |source: DefIdSource, ast::DefId|: 'a -> ast::DefId; diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 72c6256dcb518..5f030324d421e 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -24,7 +24,9 @@ use middle::borrowck::LoanPathKind::*; use middle::expr_use_visitor as euv; use middle::mem_categorization as mc; use middle::region; +use middle::ty::ParameterEnvironment; use middle::ty; +use syntax::ast::NodeId; use syntax::ast; use syntax::codemap::Span; use util::ppaux::Repr; @@ -89,6 +91,7 @@ struct CheckLoanCtxt<'a, 'tcx: 'a> { dfcx_loans: &'a LoanDataFlow<'a, 'tcx>, move_data: move_data::FlowedMoveData<'a, 'tcx>, all_loans: &'a [Loan<'tcx>], + param_env: &'a ParameterEnvironment<'tcx>, } impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> { @@ -193,19 +196,25 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, dfcx_loans: &LoanDataFlow<'b, 'tcx>, move_data: move_data::FlowedMoveData<'c, 'tcx>, all_loans: &[Loan<'tcx>], + fn_id: NodeId, decl: &ast::FnDecl, body: &ast::Block) { debug!("check_loans(body id={})", body.id); + let param_env = ParameterEnvironment::for_item(bccx.tcx, fn_id); + let mut clcx = CheckLoanCtxt { bccx: bccx, dfcx_loans: dfcx_loans, move_data: move_data, all_loans: all_loans, + param_env: ¶m_env, }; { - let mut euv = euv::ExprUseVisitor::new(&mut clcx, bccx.tcx); + let mut euv = euv::ExprUseVisitor::new(&mut clcx, + bccx.tcx, + param_env.clone()); euv.walk_fn(decl, body); } } @@ -700,7 +709,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { use_kind, &**lp, the_move, - moved_lp); + moved_lp, + self.param_env); false }); } diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index edffe59fff59c..ca9d4b512b301 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -22,6 +22,7 @@ use middle::borrowck::move_data::MoveData; use middle::expr_use_visitor as euv; use middle::mem_categorization as mc; use middle::region; +use middle::ty::ParameterEnvironment; use middle::ty; use util::ppaux::{Repr}; @@ -37,10 +38,11 @@ mod gather_moves; mod move_error; pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + fn_id: NodeId, decl: &ast::FnDecl, body: &ast::Block) - -> (Vec>, move_data::MoveData<'tcx>) -{ + -> (Vec>, + move_data::MoveData<'tcx>) { let mut glcx = GatherLoanCtxt { bccx: bccx, all_loans: Vec::new(), @@ -49,8 +51,12 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, move_error_collector: move_error::MoveErrorCollector::new(), }; + let param_env = ParameterEnvironment::for_item(bccx.tcx, fn_id); + { - let mut euv = euv::ExprUseVisitor::new(&mut glcx, bccx.tcx); + let mut euv = euv::ExprUseVisitor::new(&mut glcx, + bccx.tcx, + param_env); euv.walk_fn(decl, body); } diff --git a/src/librustc/middle/borrowck/graphviz.rs b/src/librustc/middle/borrowck/graphviz.rs index a209b1a28f284..32fa5f8c3a9f2 100644 --- a/src/librustc/middle/borrowck/graphviz.rs +++ b/src/librustc/middle/borrowck/graphviz.rs @@ -34,6 +34,8 @@ pub enum Variant { Assigns, } +impl Copy for Variant {} + impl Variant { pub fn short_name(&self) -> &'static str { match *self { diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 0bbcdfe61bb46..e90de1b691204 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -25,7 +25,7 @@ use middle::dataflow::DataFlowOperator; use middle::expr_use_visitor as euv; use middle::mem_categorization as mc; use middle::region; -use middle::ty::{mod, Ty}; +use middle::ty::{mod, ParameterEnvironment, Ty}; use util::ppaux::{note_and_explain_region, Repr, UserString}; use std::rc::Rc; @@ -62,6 +62,8 @@ pub mod move_data; #[deriving(Clone)] pub struct LoanDataFlowOperator; +impl Copy for LoanDataFlowOperator {} + pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>; impl<'a, 'tcx, 'v> Visitor<'v> for BorrowckCtxt<'a, 'tcx> { @@ -146,8 +148,13 @@ fn borrowck_fn(this: &mut BorrowckCtxt, move_data::fragments::instrument_move_fragments(&flowed_moves.move_data, this.tcx, sp, id); - check_loans::check_loans(this, &loan_dfcx, flowed_moves, - all_loans.as_slice(), decl, body); + check_loans::check_loans(this, + &loan_dfcx, + flowed_moves, + all_loans.as_slice(), + id, + decl, + body); visit::walk_fn(this, fk, decl, body, sp); } @@ -162,7 +169,7 @@ fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>, // Check the body of fn items. let id_range = ast_util::compute_id_range_for_fn_body(fk, decl, body, sp, id); let (all_loans, move_data) = - gather_loans::gather_loans_in_fn(this, decl, body); + gather_loans::gather_loans_in_fn(this, id, decl, body); let mut loan_dfcx = DataFlowContext::new(this.tcx, @@ -339,6 +346,8 @@ pub enum LoanPathElem { LpInterior(mc::InteriorKind) // `LV.f` in doc.rs } +impl Copy for LoanPathElem {} + pub fn closure_to_block(closure_id: ast::NodeId, tcx: &ty::ctxt) -> ast::NodeId { match tcx.map.get(closure_id) { @@ -484,6 +493,7 @@ pub fn opt_loan_path<'tcx>(cmt: &mc::cmt<'tcx>) -> Option>> { // Errors that can occur #[deriving(PartialEq)] +#[allow(missing_copy_implementations)] pub enum bckerr_code { err_mutbl, err_out_of_scope(ty::Region, ty::Region), // superscope, subscope @@ -505,12 +515,16 @@ pub enum AliasableViolationKind { BorrowViolation(euv::LoanCause) } +impl Copy for AliasableViolationKind {} + #[deriving(Show)] pub enum MovedValueUseKind { MovedInUse, MovedInCapture, } +impl Copy for MovedValueUseKind {} + /////////////////////////////////////////////////////////////////////////// // Misc @@ -545,7 +559,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { use_kind: MovedValueUseKind, lp: &LoanPath<'tcx>, the_move: &move_data::Move, - moved_lp: &LoanPath<'tcx>) { + moved_lp: &LoanPath<'tcx>, + param_env: &ParameterEnvironment<'tcx>) { let verb = match use_kind { MovedInUse => "use", MovedInCapture => "capture", @@ -621,7 +636,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { r).as_slice()) } }; - let (suggestion, _) = move_suggestion(self.tcx, expr_ty, + let (suggestion, _) = move_suggestion(self.tcx, param_env, expr_ty, ("moved by default", "")); self.tcx.sess.span_note( expr_span, @@ -659,7 +674,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { r).as_slice()) } }; - let (suggestion, help) = move_suggestion(self.tcx, expr_ty, + let (suggestion, help) = move_suggestion(self.tcx, + param_env, + expr_ty, ("moved by default", "make a copy and \ capture that instead to override")); self.tcx.sess.span_note( @@ -674,7 +691,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } } - fn move_suggestion<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>, + fn move_suggestion<'tcx>(tcx: &ty::ctxt<'tcx>, + param_env: &ty::ParameterEnvironment<'tcx>, + ty: Ty<'tcx>, default_msgs: (&'static str, &'static str)) -> (&'static str, &'static str) { match ty.sty { @@ -684,7 +703,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { }) => ("a non-copyable stack closure", "capture it in a new closure, e.g. `|x| f(x)`, to override"), - _ if ty::type_moves_by_default(tcx, ty) => + _ if ty::type_moves_by_default(tcx, ty, param_env) => ("non-copyable", "perhaps you meant to use `clone()`?"), _ => default_msgs, diff --git a/src/librustc/middle/borrowck/move_data.rs b/src/librustc/middle/borrowck/move_data.rs index 7bf3458f0ae3d..3bb6145c5ca34 100644 --- a/src/librustc/middle/borrowck/move_data.rs +++ b/src/librustc/middle/borrowck/move_data.rs @@ -81,6 +81,8 @@ pub struct FlowedMoveData<'a, 'tcx: 'a> { #[deriving(PartialEq, Eq, PartialOrd, Ord, Show)] pub struct MovePathIndex(uint); +impl Copy for MovePathIndex {} + impl MovePathIndex { fn get(&self) -> uint { let MovePathIndex(v) = *self; v @@ -101,6 +103,8 @@ static InvalidMovePathIndex: MovePathIndex = #[deriving(PartialEq)] pub struct MoveIndex(uint); +impl Copy for MoveIndex {} + impl MoveIndex { fn get(&self) -> uint { let MoveIndex(v) = *self; v @@ -138,6 +142,8 @@ pub enum MoveKind { Captured // Closure creation that moves a value } +impl Copy for MoveKind {} + pub struct Move { /// Path being moved. pub path: MovePathIndex, @@ -152,6 +158,8 @@ pub struct Move { pub next_move: MoveIndex } +impl Copy for Move {} + pub struct Assignment { /// Path being assigned. pub path: MovePathIndex, @@ -163,6 +171,8 @@ pub struct Assignment { pub span: Span, } +impl Copy for Assignment {} + pub struct VariantMatch { /// downcast to the variant. pub path: MovePathIndex, @@ -177,14 +187,20 @@ pub struct VariantMatch { pub mode: euv::MatchMode } +impl Copy for VariantMatch {} + #[deriving(Clone)] pub struct MoveDataFlowOperator; +impl Copy for MoveDataFlowOperator {} + pub type MoveDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, MoveDataFlowOperator>; #[deriving(Clone)] pub struct AssignDataFlowOperator; +impl Copy for AssignDataFlowOperator {} + pub type AssignDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, AssignDataFlowOperator>; fn loan_path_is_precise(loan_path: &LoanPath) -> bool { diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index b42fb8ccc41f4..97047a3fea600 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -33,6 +33,8 @@ struct LoopScope { break_index: CFGIndex, // where to go on a `break } +impl Copy for LoopScope {} + pub fn construct(tcx: &ty::ctxt, blk: &ast::Block) -> CFG { let mut graph = graph::Graph::new(); diff --git a/src/librustc/middle/cfg/mod.rs b/src/librustc/middle/cfg/mod.rs index a2e8ba8d65c33..bc512a73a4bd8 100644 --- a/src/librustc/middle/cfg/mod.rs +++ b/src/librustc/middle/cfg/mod.rs @@ -30,6 +30,8 @@ pub struct CFGNodeData { pub id: ast::NodeId } +impl Copy for CFGNodeData {} + pub struct CFGEdgeData { pub exiting_scopes: Vec } diff --git a/src/librustc/middle/check_loop.rs b/src/librustc/middle/check_loop.rs index 36742df985031..eb073e07b02f1 100644 --- a/src/librustc/middle/check_loop.rs +++ b/src/librustc/middle/check_loop.rs @@ -21,11 +21,15 @@ enum Context { Normal, Loop, Closure } +impl Copy for Context {} + struct CheckLoopVisitor<'a> { sess: &'a Session, cx: Context } +impl<'a> Copy for CheckLoopVisitor<'a> {} + pub fn check_crate(sess: &Session, krate: &ast::Crate) { visit::walk_crate(&mut CheckLoopVisitor { sess: sess, cx: Normal }, krate) } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index ed119081f78c7..2c437ae046b46 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -99,7 +99,8 @@ impl<'a> FromIterator> for Matrix<'a> { } pub struct MatchCheckCtxt<'a, 'tcx: 'a> { - pub tcx: &'a ty::ctxt<'tcx> + pub tcx: &'a ty::ctxt<'tcx>, + pub param_env: ParameterEnvironment<'tcx>, } #[deriving(Clone, PartialEq)] @@ -131,6 +132,8 @@ enum WitnessPreference { LeaveOutWitness } +impl Copy for WitnessPreference {} + impl<'a, 'tcx, 'v> Visitor<'v> for MatchCheckCtxt<'a, 'tcx> { fn visit_expr(&mut self, ex: &ast::Expr) { check_expr(self, ex); @@ -145,7 +148,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MatchCheckCtxt<'a, 'tcx> { } pub fn check_crate(tcx: &ty::ctxt) { - visit::walk_crate(&mut MatchCheckCtxt { tcx: tcx }, tcx.map.krate()); + visit::walk_crate(&mut MatchCheckCtxt { + tcx: tcx, + param_env: ty::empty_parameter_environment(), + }, tcx.map.krate()); tcx.sess.abort_if_errors(); } @@ -954,8 +960,14 @@ fn check_fn(cx: &mut MatchCheckCtxt, decl: &ast::FnDecl, body: &ast::Block, sp: Span, - _: NodeId) { + fn_id: NodeId) { + match kind { + visit::FkFnBlock => {} + _ => cx.param_env = ParameterEnvironment::for_item(cx.tcx, fn_id), + } + visit::walk_fn(cx, kind, decl, body, sp); + for input in decl.inputs.iter() { is_refutable(cx, &*input.pat, |pat| { span_err!(cx.tcx.sess, input.pat.span, E0006, @@ -1020,7 +1032,9 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, match p.node { ast::PatIdent(ast::BindByValue(_), _, ref sub) => { let pat_ty = ty::node_id_to_type(tcx, p.id); - if ty::type_moves_by_default(tcx, pat_ty) { + if ty::type_moves_by_default(tcx, + pat_ty, + &cx.param_env) { check_move(p, sub.as_ref().map(|p| &**p)); } } @@ -1048,7 +1062,9 @@ fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>, let mut checker = MutationChecker { cx: cx, }; - let mut visitor = ExprUseVisitor::new(&mut checker, checker.cx.tcx); + let mut visitor = ExprUseVisitor::new(&mut checker, + checker.cx.tcx, + cx.param_env.clone()); visitor.walk_expr(guard); } diff --git a/src/librustc/middle/check_rvalues.rs b/src/librustc/middle/check_rvalues.rs index dae76ba125e60..a14307b90ee83 100644 --- a/src/librustc/middle/check_rvalues.rs +++ b/src/librustc/middle/check_rvalues.rs @@ -13,6 +13,7 @@ use middle::expr_use_visitor as euv; use middle::mem_categorization as mc; +use middle::ty::ParameterEnvironment; use middle::ty; use util::ppaux::ty_to_string; @@ -36,9 +37,10 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> { fd: &'v ast::FnDecl, b: &'v ast::Block, s: Span, - _: ast::NodeId) { + fn_id: ast::NodeId) { { - let mut euv = euv::ExprUseVisitor::new(self, self.tcx); + let param_env = ParameterEnvironment::for_item(self.tcx, fn_id); + let mut euv = euv::ExprUseVisitor::new(self, self.tcx, param_env); euv.walk_fn(fd, b); } visit::walk_fn(self, fk, fd, b, s) diff --git a/src/librustc/middle/check_static.rs b/src/librustc/middle/check_static.rs index d3c7ccf65dd72..7acc540c20a9a 100644 --- a/src/librustc/middle/check_static.rs +++ b/src/librustc/middle/check_static.rs @@ -47,13 +47,16 @@ enum Mode { InNothing, } +impl Copy for Mode {} + struct CheckStaticVisitor<'a, 'tcx: 'a> { tcx: &'a ty::ctxt<'tcx>, mode: Mode, checker: &'a mut GlobalChecker, } -struct GlobalVisitor<'a, 'b, 'tcx: 'b>(euv::ExprUseVisitor<'a, 'b, 'tcx, ty::ctxt<'tcx>>); +struct GlobalVisitor<'a,'b,'tcx:'a+'b>( + euv::ExprUseVisitor<'a,'b,'tcx,ty::ctxt<'tcx>>); struct GlobalChecker { static_consumptions: NodeSet, const_borrows: NodeSet, @@ -69,7 +72,8 @@ pub fn check_crate(tcx: &ty::ctxt) { static_local_borrows: NodeSet::new(), }; { - let visitor = euv::ExprUseVisitor::new(&mut checker, tcx); + let param_env = ty::empty_parameter_environment(); + let visitor = euv::ExprUseVisitor::new(&mut checker, tcx, param_env); visit::walk_crate(&mut GlobalVisitor(visitor), tcx.map.krate()); } visit::walk_crate(&mut CheckStaticVisitor { @@ -242,7 +246,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckStaticVisitor<'a, 'tcx> { } } -impl<'a, 'b, 't, 'v> Visitor<'v> for GlobalVisitor<'a, 'b, 't> { +impl<'a,'b,'t,'v> Visitor<'v> for GlobalVisitor<'a,'b,'t> { fn visit_item(&mut self, item: &ast::Item) { match item.node { ast::ItemConst(_, ref e) | diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index d5a292b9f09c6..d9bf8510f9f47 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -68,6 +68,8 @@ pub enum constness { non_const } +impl Copy for constness {} + type constness_cache = DefIdMap; pub fn join(a: constness, b: constness) -> constness { diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 53fea8ffc86c6..db8fd999f380b 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -28,7 +28,12 @@ use syntax::print::{pp, pprust}; use util::nodemap::NodeMap; #[deriving(Show)] -pub enum EntryOrExit { Entry, Exit } +pub enum EntryOrExit { + Entry, + Exit, +} + +impl Copy for EntryOrExit {} #[deriving(Clone)] pub struct DataFlowContext<'a, 'tcx: 'a, O> { diff --git a/src/librustc/middle/def.rs b/src/librustc/middle/def.rs index 4a4298f62f226..b3e4dd25adc7a 100644 --- a/src/librustc/middle/def.rs +++ b/src/librustc/middle/def.rs @@ -52,6 +52,8 @@ pub enum Def { DefMethod(ast::DefId /* method */, Option /* trait */, MethodProvenance), } +impl Copy for Def {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum MethodProvenance { FromTrait(ast::DefId), @@ -67,6 +69,8 @@ impl MethodProvenance { } } +impl Copy for MethodProvenance {} + impl Def { pub fn def_id(&self) -> ast::DefId { match *self { diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index e67df0332dce6..44f2e1d2667eb 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -30,6 +30,8 @@ enum UnsafeContext { UnsafeBlock(ast::NodeId), } +impl Copy for UnsafeContext {} + fn type_is_unsafe_function(ty: Ty) -> bool { match ty.sty { ty::ty_bare_fn(ref f) => f.fn_style == ast::UnsafeFn, diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index cbf36aeff512c..3cd71bc453956 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -23,13 +23,14 @@ use self::OverloadedCallType::*; use middle::{def, region, pat_util}; use middle::mem_categorization as mc; use middle::mem_categorization::Typer; -use middle::ty::{mod, Ty}; +use middle::ty::{mod, ParameterEnvironment, Ty}; use middle::typeck::{MethodCall, MethodObject, MethodTraitObject}; use middle::typeck::{MethodOrigin, MethodParam, MethodTypeParam}; use middle::typeck::{MethodStatic, MethodStaticUnboxedClosure}; use middle::typeck; use util::ppaux::Repr; +use std::kinds; use syntax::ast; use syntax::ptr::P; use syntax::codemap::Span; @@ -107,12 +108,16 @@ pub enum LoanCause { MatchDiscriminant } +impl kinds::Copy for LoanCause {} + #[deriving(PartialEq, Show)] pub enum ConsumeMode { Copy, // reference to x where x has a type that copies Move(MoveReason), // reference to x where x has a type that moves } +impl kinds::Copy for ConsumeMode {} + #[deriving(PartialEq,Show)] pub enum MoveReason { DirectRefMove, @@ -120,6 +125,8 @@ pub enum MoveReason { CaptureMove, } +impl kinds::Copy for MoveReason {} + #[deriving(PartialEq,Show)] pub enum MatchMode { NonBindingMatch, @@ -128,11 +135,17 @@ pub enum MatchMode { MovingMatch, } +impl kinds::Copy for MatchMode {} + #[deriving(PartialEq,Show)] enum TrackMatchMode { - Unknown, Definite(MatchMode), Conflicting, + Unknown, + Definite(MatchMode), + Conflicting, } +impl kinds::Copy for TrackMatchMode {} + impl TrackMatchMode { // Builds up the whole match mode for a pattern from its constituent // parts. The lattice looks like this: @@ -200,12 +213,16 @@ pub enum MutateMode { WriteAndRead, // x += y } +impl kinds::Copy for MutateMode {} + enum OverloadedCallType { FnOverloadedCall, FnMutOverloadedCall, FnOnceOverloadedCall, } +impl kinds::Copy for OverloadedCallType {} + impl OverloadedCallType { fn from_trait_id(tcx: &ty::ctxt, trait_id: ast::DefId) -> OverloadedCallType { @@ -294,6 +311,7 @@ pub struct ExprUseVisitor<'d,'t,'tcx,TYPER:'t> { typer: &'t TYPER, mc: mc::MemCategorizationContext<'t,TYPER>, delegate: &'d mut (Delegate<'tcx>+'d), + param_env: ParameterEnvironment<'tcx>, } // If the TYPER results in an error, it's because the type check @@ -314,11 +332,15 @@ macro_rules! return_if_err( impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { pub fn new(delegate: &'d mut Delegate<'tcx>, - typer: &'t TYPER) + typer: &'t TYPER, + param_env: ParameterEnvironment<'tcx>) -> ExprUseVisitor<'d,'t,'tcx,TYPER> { - ExprUseVisitor { typer: typer, - mc: mc::MemCategorizationContext::new(typer), - delegate: delegate } + ExprUseVisitor { + typer: typer, + mc: mc::MemCategorizationContext::new(typer), + delegate: delegate, + param_env: param_env, + } } pub fn walk_fn(&mut self, @@ -353,7 +375,10 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { consume_id: ast::NodeId, consume_span: Span, cmt: mc::cmt<'tcx>) { - let mode = copy_or_move(self.tcx(), cmt.ty, DirectRefMove); + let mode = copy_or_move(self.tcx(), + cmt.ty, + &self.param_env, + DirectRefMove); self.delegate.consume(consume_id, consume_span, cmt, mode); } @@ -955,7 +980,10 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { ast::PatIdent(ast::BindByRef(_), _, _) => mode.lub(BorrowingMatch), ast::PatIdent(ast::BindByValue(_), _, _) => { - match copy_or_move(tcx, cmt_pat.ty, PatBindingMove) { + match copy_or_move(tcx, + cmt_pat.ty, + &self.param_env, + PatBindingMove) { Copy => mode.lub(CopyingMatch), Move(_) => mode.lub(MovingMatch), } @@ -985,7 +1013,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { let tcx = typer.tcx(); let def_map = &self.typer.tcx().def_map; let delegate = &mut self.delegate; - + let param_env = &mut self.param_env; return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |mc, cmt_pat, pat| { if pat_util::pat_is_binding(def_map, pat) { let tcx = typer.tcx(); @@ -1019,7 +1047,10 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { r, bk, RefBinding); } ast::PatIdent(ast::BindByValue(_), _, _) => { - let mode = copy_or_move(typer.tcx(), cmt_pat.ty, PatBindingMove); + let mode = copy_or_move(typer.tcx(), + cmt_pat.ty, + param_env, + PatBindingMove); debug!("walk_pat binding consuming pat"); delegate.consume_pat(pat, cmt_pat, mode); } @@ -1212,7 +1243,10 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id, closure_expr.span, freevar.def)); - let mode = copy_or_move(self.tcx(), cmt_var.ty, CaptureMove); + let mode = copy_or_move(self.tcx(), + cmt_var.ty, + &self.param_env, + CaptureMove); self.delegate.consume(closure_expr.id, freevar.span, cmt_var, mode); } } @@ -1230,8 +1264,15 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { } } -fn copy_or_move<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>, - move_reason: MoveReason) -> ConsumeMode { - if ty::type_moves_by_default(tcx, ty) { Move(move_reason) } else { Copy } +fn copy_or_move<'tcx>(tcx: &ty::ctxt<'tcx>, + ty: Ty<'tcx>, + param_env: &ParameterEnvironment<'tcx>, + move_reason: MoveReason) + -> ConsumeMode { + if ty::type_moves_by_default(tcx, ty, param_env) { + Move(move_reason) + } else { + Copy + } } diff --git a/src/librustc/middle/fast_reject.rs b/src/librustc/middle/fast_reject.rs index 888f01f9118fa..6780177933fd1 100644 --- a/src/librustc/middle/fast_reject.rs +++ b/src/librustc/middle/fast_reject.rs @@ -33,6 +33,8 @@ pub enum SimplifiedType { ParameterSimplifiedType, } +impl Copy for SimplifiedType {} + /// Tries to simplify a type by dropping type parameters, deref'ing away any reference types, etc. /// The idea is to get something simple that we can use to quickly decide if two types could unify /// during method lookup. diff --git a/src/librustc/middle/graph.rs b/src/librustc/middle/graph.rs index 2f50a96402302..e45232a3c3038 100644 --- a/src/librustc/middle/graph.rs +++ b/src/librustc/middle/graph.rs @@ -65,11 +65,15 @@ pub struct NodeIndex(pub uint); #[allow(non_upper_case_globals)] pub const InvalidNodeIndex: NodeIndex = NodeIndex(uint::MAX); +impl Copy for NodeIndex {} + #[deriving(PartialEq, Show)] pub struct EdgeIndex(pub uint); #[allow(non_upper_case_globals)] pub const InvalidEdgeIndex: EdgeIndex = EdgeIndex(uint::MAX); +impl Copy for EdgeIndex {} + // Use a private field here to guarantee no more instances are created: #[deriving(Show)] pub struct Direction { repr: uint } @@ -78,6 +82,8 @@ pub const Outgoing: Direction = Direction { repr: 0 }; #[allow(non_upper_case_globals)] pub const Incoming: Direction = Direction { repr: 1 }; +impl Copy for Direction {} + impl NodeIndex { fn get(&self) -> uint { let NodeIndex(v) = *self; v } /// Returns unique id (unique with respect to the graph holding associated node). diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index da1c0bd649a16..4a20c92d8e21e 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -50,6 +50,8 @@ pub enum LangItem { $($variant),* } +impl Copy for LangItem {} + pub struct LanguageItems { pub items: Vec>, pub missing: Vec, diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index fcc23d8ac5548..dffd327ee834b 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -137,9 +137,14 @@ enum LoopKind<'a> { #[deriving(PartialEq)] struct Variable(uint); + +impl Copy for Variable {} + #[deriving(PartialEq)] struct LiveNode(uint); +impl Copy for LiveNode {} + impl Variable { fn get(&self) -> uint { let Variable(v) = *self; v } } @@ -162,6 +167,8 @@ enum LiveNodeKind { ExitNode } +impl Copy for LiveNodeKind {} + fn live_node_kind_to_string(lnk: LiveNodeKind, cx: &ty::ctxt) -> String { let cm = cx.sess.codemap(); match lnk { @@ -246,6 +253,8 @@ struct LocalInfo { ident: ast::Ident } +impl Copy for LocalInfo {} + #[deriving(Show)] enum VarKind { Arg(NodeId, ast::Ident), @@ -254,6 +263,8 @@ enum VarKind { CleanExit } +impl Copy for VarKind {} + struct IrMaps<'a, 'tcx: 'a> { tcx: &'a ty::ctxt<'tcx>, @@ -532,6 +543,8 @@ struct Users { used: bool } +impl Copy for Users {} + fn invalid_users() -> Users { Users { reader: invalid_node(), @@ -547,6 +560,8 @@ struct Specials { clean_exit_var: Variable } +impl Copy for Specials {} + static ACC_READ: uint = 1u; static ACC_WRITE: uint = 2u; static ACC_USE: uint = 4u; diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index ce166fc5de6bb..ba62be9eead6f 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -111,6 +111,8 @@ pub struct Upvar { pub is_unboxed: bool } +impl Copy for Upvar {} + // different kinds of pointers: #[deriving(Clone, PartialEq, Eq, Hash, Show)] pub enum PointerKind { @@ -120,6 +122,8 @@ pub enum PointerKind { UnsafePtr(ast::Mutability) } +impl Copy for PointerKind {} + // We use the term "interior" to mean "something reachable from the // base without a pointer dereference", e.g. a field #[deriving(Clone, PartialEq, Eq, Hash, Show)] @@ -128,18 +132,24 @@ pub enum InteriorKind { InteriorElement(ElementKind), } +impl Copy for InteriorKind {} + #[deriving(Clone, PartialEq, Eq, Hash, Show)] pub enum FieldName { NamedField(ast::Name), PositionalField(uint) } +impl Copy for FieldName {} + #[deriving(Clone, PartialEq, Eq, Hash, Show)] pub enum ElementKind { VecElement, OtherElement, } +impl Copy for ElementKind {} + #[deriving(Clone, PartialEq, Eq, Hash, Show)] pub enum MutabilityCategory { McImmutable, // Immutable. @@ -147,6 +157,8 @@ pub enum MutabilityCategory { McInherited, // Inherited from the fact that owner is mutable. } +impl Copy for MutabilityCategory {} + // A note about the provenance of a `cmt`. This is used for // special-case handling of upvars such as mutability inference. // Upvar categorization can generate a variable number of nested @@ -159,6 +171,8 @@ pub enum Note { NoteNone // Nothing special } +impl Copy for Note {} + // `cmt`: "Category, Mutability, and Type". // // a complete categorization of a value indicating where it originated @@ -192,6 +206,8 @@ pub enum deref_kind { deref_interior(InteriorKind), } +impl Copy for deref_kind {} + // Categorizes a derefable type. Note that we include vectors and strings as // derefable (we model an index as the combination of a deref and then a // pointer adjustment). @@ -262,6 +278,8 @@ pub struct MemCategorizationContext<'t,TYPER:'t> { typer: &'t TYPER } +impl<'t,TYPER:'t> Copy for MemCategorizationContext<'t,TYPER> {} + pub type McResult = Result; /// The `Typer` trait provides the interface for the mem-categorization @@ -1385,6 +1403,8 @@ pub enum InteriorSafety { InteriorSafe } +impl Copy for InteriorSafety {} + pub enum AliasableReason { AliasableBorrowed, AliasableClosure(ast::NodeId), // Aliasable due to capture Fn closure env @@ -1393,6 +1413,8 @@ pub enum AliasableReason { AliasableStaticMut(InteriorSafety), } +impl Copy for AliasableReason {} + impl<'tcx> cmt_<'tcx> { pub fn guarantor(&self) -> cmt<'tcx> { //! Returns `self` after stripping away any owned pointer derefs or diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 2b8dd8df24981..370097004e92c 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -41,6 +41,8 @@ pub enum CodeExtent { Misc(ast::NodeId) } +impl Copy for CodeExtent {} + impl CodeExtent { /// Creates a scope that represents the dynamic extent associated /// with `node_id`. @@ -120,6 +122,8 @@ pub struct Context { parent: Option, } +impl Copy for Context {} + struct RegionResolutionVisitor<'a> { sess: &'a Session, diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index b958bdce0a7e8..a97c1103f987c 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -94,6 +94,8 @@ struct binding_info { binding_mode: BindingMode, } +impl Copy for binding_info {} + // Map from the name in a pattern to its binding mode. type BindingMap = HashMap; @@ -130,12 +132,16 @@ pub enum LastPrivate { type_used: ImportUse}, } +impl Copy for LastPrivate {} + #[deriving(Show)] pub enum PrivateDep { AllPublic, DependsOn(DefId), } +impl Copy for PrivateDep {} + // How an import is used. #[deriving(PartialEq, Show)] pub enum ImportUse { @@ -143,6 +149,8 @@ pub enum ImportUse { Used, // The import is used. } +impl Copy for ImportUse {} + impl LastPrivate { fn or(self, other: LastPrivate) -> LastPrivate { match (self, other) { @@ -159,12 +167,16 @@ enum PatternBindingMode { ArgumentIrrefutableMode, } +impl Copy for PatternBindingMode {} + #[deriving(PartialEq, Eq, Hash, Show)] enum Namespace { TypeNS, ValueNS } +impl Copy for Namespace {} + #[deriving(PartialEq)] enum NamespaceError { NoError, @@ -173,6 +185,8 @@ enum NamespaceError { ValueError } +impl Copy for NamespaceError {} + /// A NamespaceResult represents the result of resolving an import in /// a particular namespace. The result is either definitely-resolved, /// definitely- unresolved, or unknown. @@ -238,6 +252,8 @@ enum ImportDirectiveSubclass { GlobImport } +impl Copy for ImportDirectiveSubclass {} + /// The context that we thread through while building the reduced graph. #[deriving(Clone)] enum ReducedGraphParent { @@ -294,6 +310,8 @@ enum TypeParameters<'a> { RibKind) } +impl<'a> Copy for TypeParameters<'a> {} + // The rib kind controls the translation of local // definitions (`DefLocal`) to upvars (`DefUpvar`). @@ -319,17 +337,23 @@ enum RibKind { ConstantItemRibKind } +impl Copy for RibKind {} + // Methods can be required or provided. RequiredMethod methods only occur in traits. enum MethodSort { RequiredMethod, ProvidedMethod(NodeId) } +impl Copy for MethodSort {} + enum UseLexicalScopeFlag { DontUseLexicalScope, UseLexicalScope } +impl Copy for UseLexicalScopeFlag {} + enum ModulePrefixResult { NoPrefixFound, PrefixFound(Rc, uint) @@ -342,6 +366,8 @@ pub enum TraitItemKind { TypeTraitItemKind, } +impl Copy for TraitItemKind {} + impl TraitItemKind { pub fn from_explicit_self_category(explicit_self_category: ExplicitSelfCategory) @@ -364,12 +390,16 @@ enum NameSearchType { PathSearch, } +impl Copy for NameSearchType {} + enum BareIdentifierPatternResolution { FoundStructOrEnumVariant(Def, LastPrivate), FoundConst(Def, LastPrivate), BareIdentifierPatternUnresolved } +impl Copy for BareIdentifierPatternResolution {} + // Specifies how duplicates should be handled when adding a child item if // another item exists with the same name in some namespace. #[deriving(PartialEq)] @@ -381,6 +411,8 @@ enum DuplicateCheckingMode { OverwriteDuplicates } +impl Copy for DuplicateCheckingMode {} + /// One local scope. struct Rib { bindings: HashMap, @@ -518,6 +550,8 @@ enum ModuleKind { AnonymousModuleKind, } +impl Copy for ModuleKind {} + /// One node in the tree of modules. struct Module { parent_link: ParentLink, @@ -599,6 +633,8 @@ bitflags! { } } +impl Copy for DefModifiers {} + // Records a possibly-private type definition. #[deriving(Clone)] struct TypeNsDef { @@ -616,6 +652,8 @@ struct ValueNsDef { value_span: Option, } +impl Copy for ValueNsDef {} + // Records the definitions (at most one for each namespace) that a name is // bound to. struct NameBindings { @@ -632,6 +670,8 @@ enum TraitReferenceType { TraitQPath, // :: } +impl Copy for TraitReferenceType {} + impl NameBindings { fn new() -> NameBindings { NameBindings { diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index bd8db1d51dfd5..2ba9ba5631d6a 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -46,6 +46,8 @@ pub enum DefRegion { /* lifetime decl */ ast::NodeId), } +impl Copy for DefRegion {} + // maps the id of each lifetime reference to the lifetime decl // that it corresponds to pub type NamedRegionMap = NodeMap; diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index 0a3e6c20316be..26efd0883c418 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -190,6 +190,8 @@ pub enum ParamSpace { FnSpace, // Type parameters attached to a method or fn } +impl Copy for ParamSpace {} + impl ParamSpace { pub fn all() -> [ParamSpace, ..4] { [TypeSpace, SelfSpace, AssocSpace, FnSpace] diff --git a/src/librustc/middle/traits/mod.rs b/src/librustc/middle/traits/mod.rs index b8d915c06e0b7..baada63088517 100644 --- a/src/librustc/middle/traits/mod.rs +++ b/src/librustc/middle/traits/mod.rs @@ -60,6 +60,8 @@ pub struct ObligationCause<'tcx> { pub code: ObligationCauseCode<'tcx> } +impl<'tcx> Copy for ObligationCause<'tcx> {} + #[deriving(Clone)] pub enum ObligationCauseCode<'tcx> { /// Not well classified or should be obvious from span. @@ -95,6 +97,8 @@ pub enum ObligationCauseCode<'tcx> { pub type Obligations<'tcx> = subst::VecPerParamSpace>; +impl<'tcx> Copy for ObligationCauseCode<'tcx> {} + pub type Selection<'tcx> = Vtable<'tcx, Obligation<'tcx>>; #[deriving(Clone,Show)] @@ -338,7 +342,7 @@ impl<'tcx, N> Vtable<'tcx, N> { VtableFnPointer(ref sig) => VtableFnPointer((*sig).clone()), VtableUnboxedClosure(d, ref s) => VtableUnboxedClosure(d, s.clone()), VtableParam(ref p) => VtableParam((*p).clone()), - VtableBuiltin(ref i) => VtableBuiltin(i.map_nested(op)), + VtableBuiltin(ref b) => VtableBuiltin(b.map_nested(op)), } } @@ -348,7 +352,7 @@ impl<'tcx, N> Vtable<'tcx, N> { VtableFnPointer(sig) => VtableFnPointer(sig), VtableUnboxedClosure(d, s) => VtableUnboxedClosure(d, s), VtableParam(p) => VtableParam(p), - VtableBuiltin(i) => VtableBuiltin(i.map_move_nested(op)), + VtableBuiltin(no) => VtableBuiltin(no.map_move_nested(op)), } } } diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 2604204d9e63f..e82f21fd26691 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -80,6 +80,7 @@ struct ObligationStack<'prev, 'tcx: 'prev> { previous: Option<&'prev ObligationStack<'prev, 'tcx>> } +#[deriving(Clone)] pub struct SelectionCache<'tcx> { hashmap: RefCell>, SelectionResult<'tcx, Candidate<'tcx>>>>, @@ -102,6 +103,8 @@ pub enum MethodMatchedData { CoerciveMethodMatch(/* impl we matched */ ast::DefId) } +impl Copy for MethodMatchedData {} + /// The selection process begins by considering all impls, where /// clauses, and so forth that might resolve an obligation. Sometimes /// we'll be able to say definitively that (e.g.) an impl does not @@ -918,20 +921,31 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // and applicable impls. There is a certain set of precedence rules here. match self.tcx().lang_items.to_builtin_kind(obligation.trait_ref.def_id) { - Some(bound) => { - try!(self.assemble_builtin_bound_candidates(bound, stack, &mut candidates)); + Some(ty::BoundCopy) => { + debug!("obligation self ty is {}", + obligation.self_ty().repr(self.tcx())); + try!(self.assemble_candidates_from_impls(obligation, &mut candidates)); + try!(self.assemble_builtin_bound_candidates(ty::BoundCopy, + stack, + &mut candidates)); } None => { - // For the time being, we ignore user-defined impls for builtin-bounds. + // For the time being, we ignore user-defined impls for builtin-bounds, other than + // `Copy`. // (And unboxed candidates only apply to the Fn/FnMut/etc traits.) try!(self.assemble_unboxed_closure_candidates(obligation, &mut candidates)); try!(self.assemble_fn_pointer_candidates(obligation, &mut candidates)); try!(self.assemble_candidates_from_impls(obligation, &mut candidates)); } + + Some(bound) => { + try!(self.assemble_builtin_bound_candidates(bound, stack, &mut candidates)); + } } try!(self.assemble_candidates_from_caller_bounds(obligation, &mut candidates)); + debug!("candidate list size: {}", candidates.vec.len()); Ok(candidates) } @@ -1519,13 +1533,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } ty::BoundCopy => { - 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); - } + // This is an Opt-In Built-In Trait. + return Ok(ParameterBuiltin) } ty::BoundSync => { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 35aed356303d8..1a90e70bbd544 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -35,6 +35,7 @@ pub use self::ImplOrTraitItem::*; pub use self::BoundRegion::*; pub use self::sty::*; pub use self::IntVarValue::*; +pub use self::CopyImplementationError::*; use back::svh::Svh; use session::Session; @@ -51,6 +52,7 @@ use middle::resolve; use middle::resolve_lifetime; use middle::stability; use middle::subst::{mod, Subst, Substs, VecPerParamSpace}; +use middle::traits::ObligationCause; use middle::traits; use middle::ty; use middle::typeck; @@ -70,7 +72,7 @@ use std::hash::{Hash, sip, Writer}; use std::mem; use std::ops; use std::rc::Rc; -use std::collections::hash_map::{Occupied, Vacant}; +use std::collections::hash_map::{HashMap, Occupied, Vacant}; use arena::TypedArena; use syntax::abi; use syntax::ast::{CrateNum, DefId, FnStyle, Ident, ItemTrait, LOCAL_CRATE}; @@ -79,7 +81,7 @@ use syntax::ast::{Onceness, StmtExpr, StmtSemi, StructField, UnnamedField}; use syntax::ast::{Visibility}; use syntax::ast_util::{mod, is_local, lit_is_str, local_def, PostExpansionMethod}; use syntax::attr::{mod, AttrMetaMethods}; -use syntax::codemap::Span; +use syntax::codemap::{DUMMY_SP, Span}; use syntax::parse::token::{mod, InternedString}; use syntax::{ast, ast_map}; use std::collections::enum_set::{EnumSet, CLike}; @@ -96,12 +98,16 @@ pub struct field<'tcx> { pub mt: mt<'tcx> } +impl<'tcx> Copy for field<'tcx> {} + #[deriving(Clone, Show)] pub enum ImplOrTraitItemContainer { TraitContainer(ast::DefId), ImplContainer(ast::DefId), } +impl Copy for ImplOrTraitItemContainer {} + impl ImplOrTraitItemContainer { pub fn id(&self) -> ast::DefId { match *self { @@ -162,6 +168,8 @@ pub enum ImplOrTraitItemId { TypeTraitItemId(ast::DefId), } +impl Copy for ImplOrTraitItemId {} + impl ImplOrTraitItemId { pub fn def_id(&self) -> ast::DefId { match *self { @@ -223,12 +231,16 @@ pub struct AssociatedType { pub container: ImplOrTraitItemContainer, } +impl Copy for AssociatedType {} + #[deriving(Clone, PartialEq, Eq, Hash, Show)] pub struct mt<'tcx> { pub ty: Ty<'tcx>, pub mutbl: ast::Mutability, } +impl<'tcx> Copy for mt<'tcx> {} + #[deriving(Clone, PartialEq, Eq, Hash, Encodable, Decodable, Show)] pub enum TraitStore { /// Box @@ -237,6 +249,8 @@ pub enum TraitStore { RegionTraitStore(Region, ast::Mutability), } +impl Copy for TraitStore {} + #[deriving(Clone, Show)] pub struct field_ty { pub name: Name, @@ -245,6 +259,8 @@ pub struct field_ty { pub origin: ast::DefId, // The DefId of the struct in which the field is declared. } +impl Copy for field_ty {} + // Contains information needed to resolve types and (in the future) look up // the types of AST nodes. #[deriving(PartialEq, Eq, Hash)] @@ -254,11 +270,15 @@ pub struct creader_cache_key { pub len: uint } +impl Copy for creader_cache_key {} + pub enum ast_ty_to_ty_cache_entry<'tcx> { atttce_unresolved, /* not resolved yet */ atttce_resolved(Ty<'tcx>) /* resolved to a type, irrespective of region */ } +impl<'tcx> Copy for ast_ty_to_ty_cache_entry<'tcx> {} + #[deriving(Clone, PartialEq, Decodable, Encodable)] pub struct ItemVariances { pub types: VecPerParamSpace, @@ -273,6 +293,8 @@ pub enum Variance { Bivariant, // T <: T -- e.g., unused type parameter } +impl Copy for Variance {} + #[deriving(Clone, Show)] pub enum AutoAdjustment<'tcx> { AdjustAddEnv(ty::TraitStore), @@ -427,6 +449,8 @@ pub struct TransmuteRestriction<'tcx> { pub id: ast::NodeId, } +impl<'tcx> Copy for TransmuteRestriction<'tcx> {} + /// The data structure to keep track of all the information that typechecker /// generates so that so that it can be reused and doesn't have to be redone /// later on. @@ -579,6 +603,9 @@ pub struct ctxt<'tcx> { /// Caches the representation hints for struct definitions. pub repr_hint_cache: RefCell>>>, + + /// Caches whether types move by default. + pub type_moves_by_default_cache: RefCell,bool>>, } // Flags that we track on types. These flags are propagated upwards @@ -599,6 +626,8 @@ bitflags! { } } +impl Copy for TypeFlags {} + #[deriving(Show)] pub struct TyS<'tcx> { pub sty: sty<'tcx>, @@ -640,6 +669,7 @@ impl<'tcx> PartialEq for InternedTy<'tcx> { self.ty.sty == other.ty.sty } } + impl<'tcx> Eq for InternedTy<'tcx> {} impl<'tcx, S: Writer> Hash for InternedTy<'tcx> { @@ -733,6 +763,8 @@ impl<'tcx> FnOutput<'tcx> { } } +impl<'tcx> Copy for FnOutput<'tcx> {} + /// Signature of a function type, which I have arbitrarily /// decided to use to refer to the input/output types. /// @@ -757,6 +789,8 @@ pub struct ParamTy { pub def_id: DefId } +impl Copy for ParamTy {} + /// A [De Bruijn index][dbi] is a standard means of representing /// regions (and perhaps later types) in a higher-ranked setting. In /// particular, imagine a type like this: @@ -851,6 +885,8 @@ pub struct UpvarId { pub closure_expr_id: ast::NodeId, } +impl Copy for UpvarId {} + #[deriving(Clone, PartialEq, Eq, Hash, Show, Encodable, Decodable)] pub enum BorrowKind { /// Data must be immutable and is aliasable. @@ -897,6 +933,8 @@ pub enum BorrowKind { MutBorrow } +impl Copy for BorrowKind {} + /// Information describing the borrowing of an upvar. This is computed /// during `typeck`, specifically by `regionck`. The general idea is /// that the compiler analyses treat closures like: @@ -952,6 +990,8 @@ pub struct UpvarBorrow { pub type UpvarBorrowMap = FnvHashMap; +impl Copy for UpvarBorrow {} + impl Region { pub fn is_bound(&self) -> bool { match *self { @@ -969,6 +1009,8 @@ impl Region { } } +impl Copy for Region {} + #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)] /// A "free" region `fr` can be interpreted as "some region /// at least as big as the scope `fr.scope`". @@ -977,6 +1019,8 @@ pub struct FreeRegion { pub bound_region: BoundRegion } +impl Copy for FreeRegion {} + #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)] pub enum BoundRegion { /// An anonymous region parameter for a given fn (&T) @@ -996,6 +1040,8 @@ pub enum BoundRegion { BrEnv } +impl Copy for BoundRegion {} + #[inline] pub fn mk_prim_t<'tcx>(primitive: &'tcx TyS<'static>) -> Ty<'tcx> { // FIXME(#17596) Ty<'tcx> is incorrectly invariant w.r.t 'tcx. @@ -1135,6 +1181,8 @@ pub enum IntVarValue { UintType(ast::UintTy), } +impl Copy for IntVarValue {} + #[deriving(Clone, Show)] pub enum terr_vstore_kind { terr_vec, @@ -1143,12 +1191,16 @@ pub enum terr_vstore_kind { terr_trait } +impl Copy for terr_vstore_kind {} + #[deriving(Clone, Show)] pub struct expected_found { pub expected: T, pub found: T } +impl Copy for expected_found {} + // Data structures used in type unification #[deriving(Clone, Show)] pub enum type_err<'tcx> { @@ -1183,6 +1235,8 @@ pub enum type_err<'tcx> { terr_convergence_mismatch(expected_found) } +impl<'tcx> Copy for type_err<'tcx> {} + /// Bounds suitable for a named type parameter like `A` in `fn foo` /// as well as the existential type parameter in an object type. #[deriving(PartialEq, Eq, Hash, Clone, Show)] @@ -1203,6 +1257,8 @@ pub struct ExistentialBounds { pub builtin_bounds: BuiltinBounds } +impl Copy for ExistentialBounds {} + pub type BuiltinBounds = EnumSet; #[deriving(Clone, Encodable, PartialEq, Eq, Decodable, Hash, Show)] @@ -1214,6 +1270,8 @@ pub enum BuiltinBound { BoundSync, } +impl Copy for BuiltinBound {} + pub fn empty_builtin_bounds() -> BuiltinBounds { EnumSet::new() } @@ -1246,21 +1304,29 @@ pub struct TyVid { pub index: uint } +impl Copy for TyVid {} + #[deriving(Clone, PartialEq, Eq, Hash)] pub struct IntVid { pub index: uint } +impl Copy for IntVid {} + #[deriving(Clone, PartialEq, Eq, Hash)] pub struct FloatVid { pub index: uint } +impl Copy for FloatVid {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)] pub struct RegionVid { pub index: uint } +impl Copy for RegionVid {} + #[deriving(Clone, PartialEq, Eq, Hash)] pub enum InferTy { TyVar(TyVid), @@ -1274,12 +1340,16 @@ pub enum InferTy { SkolemizedIntTy(uint), } +impl Copy for InferTy {} + #[deriving(Clone, Encodable, Decodable, Eq, Hash, Show)] pub enum InferRegion { ReVar(RegionVid), ReSkolemized(uint, BoundRegion) } +impl Copy for InferRegion {} + impl cmp::PartialEq for InferRegion { fn eq(&self, other: &InferRegion) -> bool { match ((*self), *other) { @@ -1475,6 +1545,7 @@ impl<'tcx> TraitRef<'tcx> { /// bound lifetime parameters are replaced with free ones, but in the /// future I hope to refine the representation of types so as to make /// more distinctions clearer. +#[deriving(Clone)] pub struct ParameterEnvironment<'tcx> { /// A substitution that can be applied to move from /// the "outer" view of a type or method to the "inner" view. @@ -1523,14 +1594,14 @@ impl<'tcx> ParameterEnvironment<'tcx> { } TypeTraitItem(_) => { cx.sess - .bug("ParameterEnvironment::from_item(): \ + .bug("ParameterEnvironment::for_item(): \ can't create a parameter environment \ for type trait items") } } } ast::TypeImplItem(_) => { - cx.sess.bug("ParameterEnvironment::from_item(): \ + cx.sess.bug("ParameterEnvironment::for_item(): \ can't create a parameter environment \ for type impl items") } @@ -1540,7 +1611,7 @@ impl<'tcx> ParameterEnvironment<'tcx> { match *trait_method { ast::RequiredMethod(ref required) => { cx.sess.span_bug(required.span, - "ParameterEnvironment::from_item(): + "ParameterEnvironment::for_item(): can't create a parameter \ environment for required trait \ methods") @@ -1558,7 +1629,7 @@ impl<'tcx> ParameterEnvironment<'tcx> { } TypeTraitItem(_) => { cx.sess - .bug("ParameterEnvironment::from_item(): \ + .bug("ParameterEnvironment::for_item(): \ can't create a parameter environment \ for type trait items") } @@ -1601,6 +1672,10 @@ impl<'tcx> ParameterEnvironment<'tcx> { } } } + Some(ast_map::NodeExpr(..)) => { + // This is a convenience to allow closures to work. + ParameterEnvironment::for_item(cx, cx.map.get_parent(id)) + } _ => { cx.sess.bug(format!("ParameterEnvironment::from_item(): \ `{}` is not an item", @@ -1658,6 +1733,8 @@ pub enum UnboxedClosureKind { FnOnceUnboxedClosureKind, } +impl Copy for UnboxedClosureKind {} + impl UnboxedClosureKind { pub fn trait_did(&self, cx: &ctxt) -> ast::DefId { let result = match *self { @@ -1742,6 +1819,7 @@ pub fn mk_ctxt<'tcx>(s: Session, associated_types: RefCell::new(DefIdMap::new()), selection_cache: traits::SelectionCache::new(), repr_hint_cache: RefCell::new(DefIdMap::new()), + type_moves_by_default_cache: RefCell::new(HashMap::new()), } } @@ -2437,6 +2515,8 @@ pub struct TypeContents { pub bits: u64 } +impl Copy for TypeContents {} + macro_rules! def_type_content_sets( (mod $mname:ident { $($name:ident = $bits:expr),+ }) => { #[allow(non_snake_case)] @@ -2463,7 +2543,6 @@ def_type_content_sets!( OwnsOwned = 0b0000_0000__0000_0001__0000, OwnsDtor = 0b0000_0000__0000_0010__0000, OwnsManaged /* see [1] below */ = 0b0000_0000__0000_0100__0000, - OwnsAffine = 0b0000_0000__0000_1000__0000, OwnsAll = 0b0000_0000__1111_1111__0000, // Things that are reachable by the value in any way (fourth nibble): @@ -2473,24 +2552,12 @@ def_type_content_sets!( ReachesFfiUnsafe = 0b0010_0000__0000_0000__0000, ReachesAll = 0b0011_1111__0000_0000__0000, - // Things that cause values to *move* rather than *copy*. This - // is almost the same as the `Copy` trait, but for managed - // data -- atm, we consider managed data to copy, not move, - // but it does not impl Copy as a pure memcpy is not good - // enough. Yuck. - Moves = 0b0000_0000__0000_1011__0000, - // Things that mean drop glue is necessary NeedsDrop = 0b0000_0000__0000_0111__0000, // Things that prevent values from being considered sized Nonsized = 0b0000_0000__0000_0000__0001, - // Things that make values considered not POD (would be same - // as `Moves`, but for the fact that managed data `@` is - // not considered POD) - Noncopy = 0b0000_0000__0000_1111__0000, - // Bits to set when a managed value is encountered // // [1] Do not set the bits TC::OwnsManaged or @@ -2532,10 +2599,6 @@ impl TypeContents { self.intersects(TC::InteriorUnsized) } - pub fn moves_by_default(&self, _: &ctxt) -> bool { - self.intersects(TC::Moves) - } - pub fn needs_drop(&self, _: &ctxt) -> bool { self.intersects(TC::NeedsDrop) } @@ -2820,15 +2883,10 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { mc | tc_ty(cx, mt.ty, cache) } - fn apply_lang_items(cx: &ctxt, - did: ast::DefId, - tc: TypeContents) - -> TypeContents - { + fn apply_lang_items(cx: &ctxt, did: ast::DefId, tc: TypeContents) + -> TypeContents { if Some(did) == cx.lang_items.managed_bound() { tc | TC::Managed - } else if Some(did) == cx.lang_items.no_copy_bound() { - tc | TC::OwnsAffine } else if Some(did) == cx.lang_items.unsafe_type() { tc | TC::InteriorUnsafe } else { @@ -2841,7 +2899,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { mutbl: ast::Mutability) -> TypeContents { let b = match mutbl { - ast::MutMutable => TC::ReachesMutable | TC::OwnsAffine, + ast::MutMutable => TC::ReachesMutable, ast::MutImmutable => TC::None, }; b | (TC::ReachesBorrowed).when(region != ty::ReStatic) @@ -2861,14 +2919,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { } }; - // This also prohibits "@once fn" from being copied, which allows it to - // be called. Neither way really makes much sense. - let ot = match cty.onceness { - ast::Once => TC::OwnsAffine, - ast::Many => TC::None, - }; - - st | ot + st } fn object_contents(cx: &ctxt, @@ -2886,9 +2937,8 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { let mut tc = TC::All; each_inherited_builtin_bound(cx, bounds, traits, |bound| { tc = tc - match bound { - BoundSync | BoundSend => TC::None, + BoundSync | BoundSend | BoundCopy => TC::None, BoundSized => TC::Nonsized, - BoundCopy => TC::Noncopy, }; }); return tc; @@ -2914,8 +2964,38 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { } } -pub fn type_moves_by_default<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { - type_contents(cx, ty).moves_by_default(cx) +pub fn type_moves_by_default<'tcx>(cx: &ctxt<'tcx>, + ty: Ty<'tcx>, + param_env: &ParameterEnvironment<'tcx>) + -> bool { + if !type_has_params(ty) && !type_has_self(ty) { + match cx.type_moves_by_default_cache.borrow().get(&ty) { + None => {} + Some(&result) => { + debug!("determined whether {} moves by default (cached): {}", + ty_to_string(cx, ty), + result); + return result + } + } + } + + let infcx = typeck::infer::new_infer_ctxt(cx); + let mut fulfill_cx = traits::FulfillmentContext::new(); + let obligation = traits::obligation_for_builtin_bound( + cx, + ObligationCause::misc(DUMMY_SP), + ty, + ty::BoundCopy).unwrap(); + fulfill_cx.register_obligation(cx, obligation); + let result = !fulfill_cx.select_all_or_error(&infcx, + param_env, + cx).is_ok(); + cx.type_moves_by_default_cache.borrow_mut().insert(ty, result); + debug!("determined whether {} moves by default: {}", + ty_to_string(cx, ty), + result); + result } pub fn is_ffi_safe<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { @@ -3047,6 +3127,8 @@ pub enum Representability { SelfRecursive, } +impl Copy for Representability {} + /// Check whether a type is representable. This means it cannot contain unboxed /// structural recursion. This check is needed for structs and enums. pub fn is_type_representable<'tcx>(cx: &ctxt<'tcx>, sp: Span, ty: Ty<'tcx>) @@ -3829,6 +3911,8 @@ pub enum ExprKind { RvalueStmtExpr } +impl Copy for ExprKind {} + pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { if tcx.method_map.borrow().contains_key(&typeck::MethodCall::expr(expr.id)) { // Overloaded operations are generally calls, and hence they are @@ -4388,6 +4472,8 @@ pub struct AssociatedTypeInfo { pub name: ast::Name, } +impl Copy for AssociatedTypeInfo {} + impl PartialOrd for AssociatedTypeInfo { fn partial_cmp(&self, other: &AssociatedTypeInfo) -> Option { Some(self.index.cmp(&other.index)) @@ -4571,6 +4657,8 @@ pub enum DtorKind { TraitDtor(DefId, bool) } +impl Copy for DtorKind {} + impl DtorKind { pub fn is_present(&self) -> bool { match *self { @@ -4958,6 +5046,8 @@ pub struct UnboxedClosureUpvar<'tcx> { pub ty: Ty<'tcx>, } +impl<'tcx> Copy for UnboxedClosureUpvar<'tcx> {} + // Returns a list of `UnboxedClosureUpvar`s for each upvar. pub fn unboxed_closure_upvars<'tcx>(tcx: &ctxt<'tcx>, closure_id: ast::DefId, substs: &Substs<'tcx>) -> Vec> { @@ -5787,6 +5877,8 @@ pub enum ExplicitSelfCategory { ByBoxExplicitSelfCategory, } +impl Copy for ExplicitSelfCategory {} + /// Pushes all the lifetimes in the given type onto the given list. A /// "lifetime in a type" is a lifetime specified by a reference or a lifetime /// in a list of type substitutions. This does *not* traverse into nominal @@ -5856,6 +5948,8 @@ pub struct Freevar { pub span: Span } +impl Copy for Freevar {} + pub type FreevarMap = NodeMap>; pub type CaptureModeMap = NodeMap; @@ -5955,6 +6049,8 @@ impl DebruijnIndex { } } +impl Copy for DebruijnIndex {} + impl<'tcx> Repr<'tcx> for AutoAdjustment<'tcx> { fn repr(&self, tcx: &ctxt<'tcx>) -> String { match *self { @@ -6010,3 +6106,45 @@ impl<'tcx> Repr<'tcx> for TyTrait<'tcx> { self.bounds.repr(tcx)) } } + +pub enum CopyImplementationError { + FieldDoesNotImplementCopy(ast::Name), + VariantDoesNotImplementCopy(ast::Name), + TypeIsStructural, +} + +impl Copy for CopyImplementationError {} + +pub fn can_type_implement_copy<'tcx>(tcx: &ctxt<'tcx>, + self_type: Ty<'tcx>, + param_env: &ParameterEnvironment<'tcx>) + -> Result<(),CopyImplementationError> { + match self_type.sty { + ty::ty_struct(struct_did, ref substs) => { + let fields = ty::struct_fields(tcx, struct_did, substs); + for field in fields.iter() { + if type_moves_by_default(tcx, field.mt.ty, param_env) { + return Err(FieldDoesNotImplementCopy(field.name)) + } + } + } + ty::ty_enum(enum_did, ref substs) => { + let enum_variants = ty::enum_variants(tcx, enum_did); + for variant in enum_variants.iter() { + for variant_arg_type in variant.args.iter() { + let substd_arg_type = + variant_arg_type.subst(tcx, substs); + if type_moves_by_default(tcx, + substd_arg_type, + param_env) { + return Err(VariantDoesNotImplementCopy(variant.name)) + } + } + } + } + _ => return Err(TypeIsStructural), + } + + Ok(()) +} + diff --git a/src/librustc/middle/typeck/check/method/mod.rs b/src/librustc/middle/typeck/check/method/mod.rs index 34c3292f8cd69..7ccef2ab1b275 100644 --- a/src/librustc/middle/typeck/check/method/mod.rs +++ b/src/librustc/middle/typeck/check/method/mod.rs @@ -54,6 +54,8 @@ pub enum CandidateSource { TraitSource(/* trait id */ ast::DefId), } +impl Copy for CandidateSource {} + type MethodIndex = uint; // just for doc purposes /// Determines whether the type `self_ty` supports a method name `method_name` or not. diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 641cbd11d64e0..873e4da27ce1b 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -207,6 +207,8 @@ enum Expectation<'tcx> { ExpectCastableToType(Ty<'tcx>), } +impl<'tcx> Copy for Expectation<'tcx> {} + #[deriving(Clone)] pub struct FnStyleState { pub def: ast::NodeId, @@ -214,6 +216,8 @@ pub struct FnStyleState { from_fn: bool } +impl Copy for FnStyleState {} + impl FnStyleState { pub fn function(fn_style: ast::FnStyle, def: ast::NodeId) -> FnStyleState { FnStyleState { def: def, fn_style: fn_style, from_fn: true } @@ -2122,6 +2126,8 @@ pub enum LvaluePreference { NoPreference } +impl Copy for LvaluePreference {} + /// Executes an autoderef loop for the type `t`. At each step, invokes `should_stop` to decide /// whether to terminate the loop. Returns the final type and number of derefs that it performed. /// @@ -2998,6 +3004,8 @@ pub enum DerefArgs { DoDerefArgs } +impl Copy for DerefArgs {} + /// Controls whether the arguments are tupled. This is used for the call /// operator. /// diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 84cb74b4de248..59df7517b5851 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -15,8 +15,7 @@ use middle::traits::{Obligation, obligation_for_builtin_bound}; use middle::traits::{FulfillmentError, CodeSelectionError, CodeAmbiguity}; use middle::traits::{ObligationCause}; use middle::ty::{mod, Ty}; -use middle::typeck::check::{FnCtxt, - structurally_resolved_type}; +use middle::typeck::check::{FnCtxt, structurally_resolved_type}; use middle::typeck::infer; use std::rc::Rc; use syntax::ast; diff --git a/src/librustc/middle/typeck/check/wf.rs b/src/librustc/middle/typeck/check/wf.rs index 8535ec4fa6e80..40e4858f14383 100644 --- a/src/librustc/middle/typeck/check/wf.rs +++ b/src/librustc/middle/typeck/check/wf.rs @@ -203,6 +203,11 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { } } + if fcx.tcx().lang_items.copy_trait() == Some(trait_ref.def_id) { + // This is checked in coherence. + return + } + // We are stricter on the trait-ref in an impl than the // self-type. In particular, we enforce region // relationships. The reason for this is that (at least diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 23af30b44d935..5a7eaee73f71e 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -355,6 +355,8 @@ enum ResolveReason { ResolvingUnboxedClosure(ast::DefId), } +impl Copy for ResolveReason {} + impl ResolveReason { fn span(&self, tcx: &ty::ctxt) -> Span { match *self { diff --git a/src/librustc/middle/typeck/coherence/mod.rs b/src/librustc/middle/typeck/coherence/mod.rs index 758608b79c2cb..38477e0601629 100644 --- a/src/librustc/middle/typeck/coherence/mod.rs +++ b/src/librustc/middle/typeck/coherence/mod.rs @@ -18,24 +18,21 @@ use metadata::csearch::{each_impl, get_impl_trait}; use metadata::csearch; -use middle::subst; -use middle::subst::{Substs}; +use middle::subst::{mod, Subst, Substs}; use middle::ty::{ImplContainer, ImplOrTraitItemId, MethodTraitItemId}; -use middle::ty::{TypeTraitItemId, lookup_item_type}; -use middle::ty::{Ty, ty_bool, ty_char, ty_enum, ty_err}; -use middle::ty::{ty_str, ty_vec, ty_float, ty_infer, ty_int, ty_open}; +use middle::ty::{ParameterEnvironment, TypeTraitItemId, lookup_item_type}; +use middle::ty::{Ty, ty_bool, ty_char, ty_closure, ty_enum, ty_err}; use middle::ty::{ty_param, Polytype, ty_ptr}; use middle::ty::{ty_rptr, ty_struct, ty_trait, ty_tup}; +use middle::ty::{ty_str, ty_vec, ty_float, ty_infer, ty_int, ty_open}; use middle::ty::{ty_uint, ty_unboxed_closure, ty_uniq, ty_bare_fn}; -use middle::ty::{ty_closure}; -use middle::ty::type_is_ty_var; -use middle::subst::Subst; +use middle::ty::{type_is_ty_var}; use middle::ty; use middle::typeck::CrateCtxt; use middle::typeck::infer::combine::Combine; -use middle::typeck::infer::InferCtxt; -use middle::typeck::infer::{new_infer_ctxt, resolve_ivar, resolve_type}; -use std::collections::{HashSet}; +use middle::typeck::infer::{InferCtxt, new_infer_ctxt, resolve_ivar}; +use middle::typeck::infer::{resolve_type}; +use std::collections::HashSet; use std::cell::RefCell; use std::rc::Rc; use syntax::ast::{Crate, DefId}; @@ -191,6 +188,9 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { // do this here, but it's actually the most convenient place, since // the coherence tables contain the trait -> type mappings. self.populate_destructor_table(); + + // Check to make sure implementations of `Copy` are legal. + self.check_implementations_of_copy(); } fn check_implementation(&self, @@ -475,6 +475,71 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { } } } + + /// Ensures that implementations of the built-in trait `Copy` are legal. + fn check_implementations_of_copy(&self) { + let tcx = self.crate_context.tcx; + let copy_trait = match tcx.lang_items.copy_trait() { + Some(id) => id, + None => return, + }; + + let trait_impls = match tcx.trait_impls + .borrow() + .get(©_trait) + .cloned() { + None => { + debug!("check_implementations_of_copy(): no types with \ + implementations of `Copy` found"); + return + } + Some(found_impls) => found_impls + }; + + // Clone first to avoid a double borrow error. + let trait_impls = trait_impls.borrow().clone(); + + for &impl_did in trait_impls.iter() { + if impl_did.krate != ast::LOCAL_CRATE { + debug!("check_implementations_of_copy(): impl not in this \ + crate"); + continue + } + + let self_type = self.get_self_type_for_implementation(impl_did); + let span = tcx.map.span(impl_did.node); + let param_env = ParameterEnvironment::for_item(tcx, + impl_did.node); + let self_type = self_type.ty.subst(tcx, ¶m_env.free_substs); + + match ty::can_type_implement_copy(tcx, self_type, ¶m_env) { + Ok(()) => {} + Err(ty::FieldDoesNotImplementCopy(name)) => { + tcx.sess + .span_err(span, + format!("the trait `Copy` may not be \ + implemented for this type; field \ + `{}` does not implement `Copy`", + token::get_name(name)).as_slice()) + } + Err(ty::VariantDoesNotImplementCopy(name)) => { + tcx.sess + .span_err(span, + format!("the trait `Copy` may not be \ + implemented for this type; variant \ + `{}` does not implement `Copy`", + token::get_name(name)).as_slice()) + } + Err(ty::TypeIsStructural) => { + tcx.sess + .span_err(span, + "the trait `Copy` may not be implemented \ + for this type; type is not a structure or \ + enumeration") + } + } + } + } } /// Substitutes the values for the receiver's type parameters that are found in method, leaving the diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 6e989dd73dbef..8941e83cf46e8 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -500,6 +500,8 @@ enum ConvertMethodContext<'a> { TraitConvertMethodContext(ast::DefId, &'a [ast::TraitItem]), } +impl<'a> Copy for ConvertMethodContext<'a> {} + fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>, convert_method_context: ConvertMethodContext, container: ImplOrTraitItemContainer, diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index c5845b143af89..81cd8dd20d20c 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -132,6 +132,8 @@ pub enum TypeOrigin { IfExpressionWithNoElse(Span) } +impl Copy for TypeOrigin {} + /// See `error_reporting.rs` for more details #[deriving(Clone, Show)] pub enum ValuePairs<'tcx> { @@ -237,6 +239,8 @@ pub enum LateBoundRegionConversionTime { HigherRankedType, } +impl Copy for LateBoundRegionConversionTime {} + /// Reasons to create a region inference variable /// /// See `error_reporting.rs` for more details @@ -280,6 +284,8 @@ pub enum fixup_err { unresolved_ty(TyVid) } +impl Copy for fixup_err {} + pub fn fixup_err_to_string(f: fixup_err) -> String { match f { unresolved_int_ty(_) => { diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index e39fbe105dcfc..d1d853ad33742 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -51,6 +51,8 @@ pub enum Constraint { ConstrainVarSubReg(RegionVid, Region), } +impl Copy for Constraint {} + // Something we have to verify after region inference is done, but // which does not directly influence the inference process pub enum Verify<'tcx> { @@ -72,6 +74,8 @@ pub struct TwoRegions { b: Region, } +impl Copy for TwoRegions {} + #[deriving(PartialEq)] pub enum UndoLogEntry { OpenSnapshot, @@ -84,11 +88,15 @@ pub enum UndoLogEntry { AddCombination(CombineMapType, TwoRegions) } +impl Copy for UndoLogEntry {} + #[deriving(PartialEq)] pub enum CombineMapType { Lub, Glb } +impl Copy for CombineMapType {} + #[deriving(Clone, Show)] pub enum RegionResolutionError<'tcx> { /// `ConcreteFailure(o, a, b)`: @@ -220,11 +228,15 @@ pub struct RegionSnapshot { length: uint } +impl Copy for RegionSnapshot {} + #[deriving(Show)] pub struct RegionMark { length: uint } +impl Copy for RegionMark {} + impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { pub fn new(tcx: &'a ty::ctxt<'tcx>) -> RegionVarBindings<'a, 'tcx> { RegionVarBindings { @@ -926,8 +938,12 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { #[deriving(PartialEq, Show)] enum Classification { Expanding, Contracting } +impl Copy for Classification {} + pub enum VarValue { NoValue, Value(Region), ErrorValue } +impl Copy for VarValue {} + struct VarData { classification: Classification, value: VarValue, diff --git a/src/librustc/middle/typeck/infer/type_variable.rs b/src/librustc/middle/typeck/infer/type_variable.rs index 3058f09a83a85..766e930486ca2 100644 --- a/src/librustc/middle/typeck/infer/type_variable.rs +++ b/src/librustc/middle/typeck/infer/type_variable.rs @@ -49,6 +49,8 @@ pub enum RelationDir { SubtypeOf, SupertypeOf, EqTo } +impl Copy for RelationDir {} + impl RelationDir { fn opposite(self) -> RelationDir { match self { diff --git a/src/librustc/middle/typeck/infer/unify.rs b/src/librustc/middle/typeck/infer/unify.rs index 1b3413bfb0104..0c5474d7c7e5e 100644 --- a/src/librustc/middle/typeck/infer/unify.rs +++ b/src/librustc/middle/typeck/infer/unify.rs @@ -92,6 +92,8 @@ pub struct Node { pub struct Delegate; +impl Copy for Delegate {} + // We can't use V:LatticeValue, much as I would like to, // because frequently the pattern is that V=Option for some // other type parameter U, and we have no way to say diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 501dfcb2e2d9e..6b1a3435b83b8 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -96,6 +96,8 @@ pub struct param_index { pub index: uint } +impl Copy for param_index {} + #[deriving(Clone, Show)] pub enum MethodOrigin<'tcx> { // fully statically resolved method @@ -168,6 +170,8 @@ pub struct MethodCall { pub adjustment: ExprAdjustment } +impl Copy for MethodCall {} + #[deriving(Clone, PartialEq, Eq, Hash, Show, Encodable, Decodable)] pub enum ExprAdjustment { NoAdjustment, @@ -175,6 +179,8 @@ pub enum ExprAdjustment { AutoObject } +impl Copy for ExprAdjustment {} + pub struct TypeAndSubsts<'tcx> { pub substs: subst::Substs<'tcx>, pub ty: Ty<'tcx>, diff --git a/src/librustc/middle/typeck/rscope.rs b/src/librustc/middle/typeck/rscope.rs index 3bca24f479f70..39c7a87837ca1 100644 --- a/src/librustc/middle/typeck/rscope.rs +++ b/src/librustc/middle/typeck/rscope.rs @@ -38,6 +38,8 @@ pub trait RegionScope { // for types that appear in structs and so on. pub struct ExplicitRscope; +impl Copy for ExplicitRscope {} + impl RegionScope for ExplicitRscope { fn default_region_bound(&self, _span: Span) -> Option { None @@ -77,6 +79,7 @@ impl RegionScope for UnelidableRscope { // A scope in which any omitted region defaults to `default`. This is // used after the `->` in function signatures, but also for backwards // compatibility with object types. The latter use may go away. +#[allow(missing_copy_implementations)] pub struct SpecificRscope { default: ty::Region } diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index ade3144ce414e..56f974ad665c6 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -232,12 +232,16 @@ type VarianceTermPtr<'a> = &'a VarianceTerm<'a>; #[deriving(Show)] struct InferredIndex(uint); +impl Copy for InferredIndex {} + enum VarianceTerm<'a> { ConstantTerm(ty::Variance), TransformTerm(VarianceTermPtr<'a>, VarianceTermPtr<'a>), InferredTerm(InferredIndex), } +impl<'a> Copy for VarianceTerm<'a> {} + impl<'a> fmt::Show for VarianceTerm<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { @@ -270,6 +274,8 @@ enum ParamKind { RegionParam } +impl Copy for ParamKind {} + struct InferredInfo<'a> { item_id: ast::NodeId, kind: ParamKind, @@ -426,6 +432,8 @@ struct Constraint<'a> { variance: &'a VarianceTerm<'a>, } +impl<'a> Copy for Constraint<'a> {} + fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>, krate: &ast::Crate) -> ConstraintContext<'a, 'tcx> { @@ -1015,7 +1023,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> { while index < num_inferred && inferred_infos[index].item_id == item_id { - let info = inferred_infos[index]; + let info = &inferred_infos[index]; let variance = solutions[index]; debug!("Index {} Info {} / {} / {} Variance {}", index, info.index, info.kind, info.space, variance); diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 33de2c9abe928..f0d6ee6f2901d 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -55,6 +55,8 @@ pub enum OptLevel { Aggressive // -O3 } +impl Copy for OptLevel {} + #[deriving(Clone, PartialEq)] pub enum DebugInfoLevel { NoDebugInfo, @@ -62,6 +64,8 @@ pub enum DebugInfoLevel { FullDebugInfo, } +impl Copy for DebugInfoLevel {} + #[deriving(Clone, PartialEq, PartialOrd, Ord, Eq)] pub enum OutputType { OutputTypeBitcode, @@ -71,6 +75,8 @@ pub enum OutputType { OutputTypeExe, } +impl Copy for OutputType {} + #[deriving(Clone)] pub struct Options { // The crate config requested for the session, which may be combined @@ -87,7 +93,7 @@ pub struct Options { // parsed code. It remains mutable in case its replacements wants to use // this. pub addl_lib_search_paths: RefCell>, - pub libs: Vec<(String, cstore::NativeLibaryKind)>, + pub libs: Vec<(String, cstore::NativeLibraryKind)>, pub maybe_sysroot: Option, pub target_triple: String, // User-specified cfg meta items. The compiler itself will add additional @@ -168,6 +174,8 @@ pub enum EntryFnType { EntryNone, } +impl Copy for EntryFnType {} + #[deriving(PartialEq, PartialOrd, Clone, Ord, Eq, Hash)] pub enum CrateType { CrateTypeExecutable, @@ -176,6 +184,8 @@ pub enum CrateType { CrateTypeStaticlib, } +impl Copy for CrateType {} + macro_rules! debugging_opts( ([ $opt:ident ] $cnt:expr ) => ( pub const $opt: u64 = 1 << $cnt; diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index ea252d9fd205c..30318cc129cac 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -25,6 +25,8 @@ use syntax::visit::Visitor; #[deriving(Clone,Show)] pub struct ErrorReported; +impl Copy for ErrorReported {} + pub fn time(do_it: bool, what: &str, u: U, f: |U| -> T) -> T { thread_local!(static DEPTH: Cell = Cell::new(0)); if !do_it { return f(u); } diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs index 4dd6306c3c096..d1816c655fa5f 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -71,6 +71,9 @@ pub mod DefIdSet { #[deriving(Clone, Default)] pub struct FnvHasher; +impl Copy for FnvHasher {} + +#[allow(missing_copy_implementations)] pub struct FnvState(u64); impl Hasher for FnvHasher { diff --git a/src/librustc_llvm/diagnostic.rs b/src/librustc_llvm/diagnostic.rs index d705c82dd9a47..04196feafd22b 100644 --- a/src/librustc_llvm/diagnostic.rs +++ b/src/librustc_llvm/diagnostic.rs @@ -24,6 +24,8 @@ pub enum OptimizationDiagnosticKind { OptimizationFailure, } +impl Copy for OptimizationDiagnosticKind {} + impl OptimizationDiagnosticKind { pub fn describe(self) -> &'static str { match self { @@ -43,6 +45,8 @@ pub struct OptimizationDiagnostic { pub message: TwineRef, } +impl Copy for OptimizationDiagnostic {} + impl OptimizationDiagnostic { unsafe fn unpack(kind: OptimizationDiagnosticKind, di: DiagnosticInfoRef) -> OptimizationDiagnostic { @@ -72,6 +76,8 @@ pub enum Diagnostic { UnknownDiagnostic(DiagnosticInfoRef), } +impl Copy for Diagnostic {} + impl Diagnostic { pub unsafe fn unpack(di: DiagnosticInfoRef) -> Diagnostic { let kind = super::LLVMGetDiagInfoKind(di); diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index a8211c0c9eae1..23dad21e5303f 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -77,12 +77,16 @@ pub enum CallConv { X86_64_Win64 = 79, } +impl Copy for CallConv {} + pub enum Visibility { LLVMDefaultVisibility = 0, HiddenVisibility = 1, ProtectedVisibility = 2, } +impl Copy for Visibility {} + // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage, // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage. // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either; @@ -101,6 +105,8 @@ pub enum Linkage { CommonLinkage = 14, } +impl Copy for Linkage {} + #[repr(C)] #[deriving(Show)] pub enum DiagnosticSeverity { @@ -110,6 +116,8 @@ pub enum DiagnosticSeverity { Note, } +impl Copy for DiagnosticSeverity {} + bitflags! { flags Attribute : u32 { const ZExtAttribute = 1 << 0, @@ -141,6 +149,8 @@ bitflags! { } } +impl Copy for Attribute {} + #[repr(u64)] pub enum OtherAttribute { // The following are not really exposed in @@ -162,16 +172,22 @@ pub enum OtherAttribute { NonNullAttribute = 1 << 44, } +impl Copy for OtherAttribute {} + pub enum SpecialAttribute { DereferenceableAttribute(u64) } +impl Copy for SpecialAttribute {} + #[repr(C)] pub enum AttributeSet { ReturnIndex = 0, FunctionIndex = !0 } +impl Copy for AttributeSet {} + pub trait AttrHelper { fn apply_llfn(&self, idx: c_uint, llfn: ValueRef); fn apply_callsite(&self, idx: c_uint, callsite: ValueRef); @@ -271,6 +287,8 @@ pub enum IntPredicate { IntSLE = 41, } +impl Copy for IntPredicate {} + // enum for the LLVM RealPredicate type pub enum RealPredicate { RealPredicateFalse = 0, @@ -291,6 +309,8 @@ pub enum RealPredicate { RealPredicateTrue = 15, } +impl Copy for RealPredicate {} + // The LLVM TypeKind type - must stay in sync with the def of // LLVMTypeKind in llvm/include/llvm-c/Core.h #[deriving(PartialEq)] @@ -314,6 +334,8 @@ pub enum TypeKind { X86_MMX = 15, } +impl Copy for TypeKind {} + #[repr(C)] pub enum AtomicBinOp { AtomicXchg = 0, @@ -329,6 +351,8 @@ pub enum AtomicBinOp { AtomicUMin = 10, } +impl Copy for AtomicBinOp {} + #[repr(C)] pub enum AtomicOrdering { NotAtomic = 0, @@ -341,6 +365,8 @@ pub enum AtomicOrdering { SequentiallyConsistent = 7 } +impl Copy for AtomicOrdering {} + // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h) #[repr(C)] pub enum FileType { @@ -348,6 +374,8 @@ pub enum FileType { ObjectFileType = 1 } +impl Copy for FileType {} + pub enum MetadataType { MD_dbg = 0, MD_tbaa = 1, @@ -357,12 +385,16 @@ pub enum MetadataType { MD_tbaa_struct = 5 } +impl Copy for MetadataType {} + // Inline Asm Dialect pub enum AsmDialect { AD_ATT = 0, AD_Intel = 1 } +impl Copy for AsmDialect {} + #[deriving(PartialEq, Clone)] #[repr(C)] pub enum CodeGenOptLevel { @@ -372,6 +404,8 @@ pub enum CodeGenOptLevel { CodeGenLevelAggressive = 3, } +impl Copy for CodeGenOptLevel {} + #[deriving(PartialEq)] #[repr(C)] pub enum RelocMode { @@ -381,6 +415,8 @@ pub enum RelocMode { RelocDynamicNoPic = 3, } +impl Copy for RelocMode {} + #[repr(C)] pub enum CodeGenModel { CodeModelDefault = 0, @@ -391,6 +427,8 @@ pub enum CodeGenModel { CodeModelLarge = 5, } +impl Copy for CodeGenModel {} + #[repr(C)] pub enum DiagnosticKind { DK_InlineAsm = 0, @@ -403,47 +441,70 @@ pub enum DiagnosticKind { DK_OptimizationFailure, } +impl Copy for DiagnosticKind {} + // Opaque pointer types +#[allow(missing_copy_implementations)] pub enum Module_opaque {} pub type ModuleRef = *mut Module_opaque; +#[allow(missing_copy_implementations)] pub enum Context_opaque {} pub type ContextRef = *mut Context_opaque; +#[allow(missing_copy_implementations)] pub enum Type_opaque {} pub type TypeRef = *mut Type_opaque; +#[allow(missing_copy_implementations)] pub enum Value_opaque {} pub type ValueRef = *mut Value_opaque; +#[allow(missing_copy_implementations)] pub enum BasicBlock_opaque {} pub type BasicBlockRef = *mut BasicBlock_opaque; +#[allow(missing_copy_implementations)] pub enum Builder_opaque {} pub type BuilderRef = *mut Builder_opaque; +#[allow(missing_copy_implementations)] pub enum ExecutionEngine_opaque {} pub type ExecutionEngineRef = *mut ExecutionEngine_opaque; +#[allow(missing_copy_implementations)] pub enum MemoryBuffer_opaque {} pub type MemoryBufferRef = *mut MemoryBuffer_opaque; +#[allow(missing_copy_implementations)] pub enum PassManager_opaque {} pub type PassManagerRef = *mut PassManager_opaque; +#[allow(missing_copy_implementations)] pub enum PassManagerBuilder_opaque {} pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque; +#[allow(missing_copy_implementations)] pub enum Use_opaque {} pub type UseRef = *mut Use_opaque; +#[allow(missing_copy_implementations)] pub enum TargetData_opaque {} pub type TargetDataRef = *mut TargetData_opaque; +#[allow(missing_copy_implementations)] pub enum ObjectFile_opaque {} pub type ObjectFileRef = *mut ObjectFile_opaque; +#[allow(missing_copy_implementations)] pub enum SectionIterator_opaque {} pub type SectionIteratorRef = *mut SectionIterator_opaque; +#[allow(missing_copy_implementations)] pub enum Pass_opaque {} pub type PassRef = *mut Pass_opaque; +#[allow(missing_copy_implementations)] pub enum TargetMachine_opaque {} pub type TargetMachineRef = *mut TargetMachine_opaque; +#[allow(missing_copy_implementations)] pub enum Archive_opaque {} pub type ArchiveRef = *mut Archive_opaque; +#[allow(missing_copy_implementations)] pub enum Twine_opaque {} pub type TwineRef = *mut Twine_opaque; +#[allow(missing_copy_implementations)] pub enum DiagnosticInfo_opaque {} pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque; +#[allow(missing_copy_implementations)] pub enum DebugLoc_opaque {} pub type DebugLocRef = *mut DebugLoc_opaque; +#[allow(missing_copy_implementations)] pub enum SMDiagnostic_opaque {} pub type SMDiagnosticRef = *mut SMDiagnostic_opaque; @@ -454,6 +515,7 @@ pub mod debuginfo { pub use self::DIDescriptorFlags::*; use super::{ValueRef}; + #[allow(missing_copy_implementations)] pub enum DIBuilder_opaque {} pub type DIBuilderRef = *mut DIBuilder_opaque; @@ -490,6 +552,8 @@ pub mod debuginfo { FlagLValueReference = 1 << 14, FlagRValueReference = 1 << 15 } + + impl Copy for DIDescriptorFlags {} } @@ -2123,6 +2187,7 @@ pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef { } } +#[allow(missing_copy_implementations)] pub enum RustString_opaque {} pub type RustStringRef = *mut RustString_opaque; type RustStringRepr = *mut RefCell>; diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index b923bb076c301..dfed52d1951d8 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -33,6 +33,17 @@ use std::sync::{Arc, Mutex}; use std::task::TaskBuilder; use libc::{c_uint, c_int, c_void}; +#[deriving(Clone, PartialEq, PartialOrd, Ord, Eq)] +pub enum OutputType { + OutputTypeBitcode, + OutputTypeAssembly, + OutputTypeLlvmAssembly, + OutputTypeObject, + OutputTypeExe, +} + +impl Copy for OutputType {} + pub fn llvm_err(handler: &diagnostic::Handler, msg: String) -> ! { unsafe { let cstr = llvm::LLVMRustGetLastError(); diff --git a/src/librustc_trans/driver/driver.rs b/src/librustc_trans/driver/driver.rs index d3281ae1c19fc..ec560a92d26cd 100644 --- a/src/librustc_trans/driver/driver.rs +++ b/src/librustc_trans/driver/driver.rs @@ -499,6 +499,8 @@ pub struct ModuleTranslation { pub llmod: ModuleRef, } +impl Copy for ModuleTranslation {} + pub struct CrateTranslation { pub modules: Vec, pub metadata_module: ModuleTranslation, diff --git a/src/librustc_trans/driver/pretty.rs b/src/librustc_trans/driver/pretty.rs index 7bb83d7c2a819..53c76ad21526c 100644 --- a/src/librustc_trans/driver/pretty.rs +++ b/src/librustc_trans/driver/pretty.rs @@ -49,12 +49,16 @@ pub enum PpSourceMode { PpmExpandedHygiene, } +impl Copy for PpSourceMode {} + #[deriving(PartialEq, Show)] pub enum PpMode { PpmSource(PpSourceMode), PpmFlowGraph, } +impl Copy for PpMode {} + pub fn parse_pretty(sess: &Session, name: &str) -> (PpMode, Option) { let mut split = name.splitn(1, '='); let first = split.next().unwrap(); diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 7a41be1dbe46f..70866d27a903d 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -250,7 +250,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { self.collecting = true; self.visit_pat(&*arg.pat); self.collecting = false; - let span_utils = self.span; + let span_utils = self.span.clone(); for &(id, ref p, _, _) in self.collected_paths.iter() { let typ = ppaux::ty_to_string(&self.analysis.ty_cx, (*self.analysis.ty_cx.node_types.borrow())[id]); diff --git a/src/librustc_trans/save/recorder.rs b/src/librustc_trans/save/recorder.rs index 2102133f97d3d..796929b837fa6 100644 --- a/src/librustc_trans/save/recorder.rs +++ b/src/librustc_trans/save/recorder.rs @@ -87,6 +87,8 @@ pub enum Row { FnRef, } +impl Copy for Row {} + impl<'a> FmtStrs<'a> { pub fn new(rec: Box, span: SpanUtils<'a>, krate: String) -> FmtStrs<'a> { FmtStrs { @@ -223,7 +225,10 @@ impl<'a> FmtStrs<'a> { if self.recorder.dump_spans { if dump_spans { - self.recorder.dump_span(self.span, label, span, Some(sub_span)); + self.recorder.dump_span(self.span.clone(), + label, + span, + Some(sub_span)); } return; } diff --git a/src/librustc_trans/save/span_utils.rs b/src/librustc_trans/save/span_utils.rs index f76f2bea5668f..49e8e0fd34714 100644 --- a/src/librustc_trans/save/span_utils.rs +++ b/src/librustc_trans/save/span_utils.rs @@ -21,6 +21,7 @@ use syntax::parse::lexer::{Reader,StringReader}; use syntax::parse::token; use syntax::parse::token::{keywords, Token}; +#[deriving(Clone)] pub struct SpanUtils<'a> { pub sess: &'a Session, pub err_count: Cell, diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index ada46ab7db719..2a876a12eac46 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -231,6 +231,8 @@ use syntax::ptr::P; #[deriving(Show)] struct ConstantExpr<'a>(&'a ast::Expr); +impl<'a> Copy for ConstantExpr<'a> {} + impl<'a> ConstantExpr<'a> { fn eq(self, other: ConstantExpr<'a>, tcx: &ty::ctxt) -> bool { let ConstantExpr(expr) = self; @@ -308,6 +310,8 @@ pub enum BranchKind { CompareSliceLength } +impl Copy for BranchKind {} + pub enum OptResult<'blk, 'tcx: 'blk> { SingleResult(Result<'blk, 'tcx>), RangeResult(Result<'blk, 'tcx>, Result<'blk, 'tcx>), @@ -321,6 +325,8 @@ pub enum TransBindingMode { TrByRef, } +impl Copy for TransBindingMode {} + /// Information about a pattern binding: /// - `llmatch` is a pointer to a stack slot. The stack slot contains a /// pointer into the value being matched. Hence, llmatch has type `T**` @@ -337,6 +343,8 @@ pub struct BindingInfo<'tcx> { pub ty: Ty<'tcx>, } +impl<'tcx> Copy for BindingInfo<'tcx> {} + type BindingsMap<'tcx> = FnvHashMap>; struct ArmData<'p, 'blk, 'tcx: 'blk> { @@ -543,7 +551,11 @@ fn enter_opt<'a, 'p, 'blk, 'tcx>( check_match::Constructor::Variant(def_id) }; - let mcx = check_match::MatchCheckCtxt { tcx: bcx.tcx() }; + let param_env = ty::empty_parameter_environment(); + let mcx = check_match::MatchCheckCtxt { + tcx: bcx.tcx(), + param_env: param_env, + }; enter_match(bcx, dm, m, col, val, |pats| check_match::specialize(&mcx, pats.as_slice(), &ctor, col, variant_size) ) @@ -1001,7 +1013,10 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, node_id_type(bcx, pat_id) }; - let mcx = check_match::MatchCheckCtxt { tcx: bcx.tcx() }; + let mcx = check_match::MatchCheckCtxt { + tcx: bcx.tcx(), + param_env: ty::empty_parameter_environment(), + }; let adt_vals = if any_irrefutable_adt_pat(bcx.tcx(), m, col) { let repr = adt::represent_type(bcx.ccx(), left_ty); let arg_count = adt::num_args(&*repr, 0); @@ -1233,8 +1248,11 @@ fn is_discr_reassigned(bcx: Block, discr: &ast::Expr, body: &ast::Expr) -> bool node: vid, reassigned: false }; + let param_env = ty::empty_parameter_environment(); { - let mut visitor = euv::ExprUseVisitor::new(&mut rc, bcx); + let mut visitor = euv::ExprUseVisitor::new(&mut rc, + bcx, + param_env); visitor.walk_expr(body); } rc.reassigned @@ -1283,12 +1301,15 @@ fn create_bindings_map<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pat: &ast::Pat, let variable_ty = node_id_type(bcx, p_id); let llvariable_ty = type_of::type_of(ccx, variable_ty); let tcx = bcx.tcx(); + let param_env = ty::empty_parameter_environment(); let llmatch; let trmode; match bm { ast::BindByValue(_) - if !ty::type_moves_by_default(tcx, variable_ty) || reassigned => { + if !ty::type_moves_by_default(tcx, + variable_ty, + ¶m_env) || reassigned => { llmatch = alloca_no_lifetime(bcx, llvariable_ty.ptr_to(), "__llmatch"); diff --git a/src/librustc_trans/trans/adt.rs b/src/librustc_trans/trans/adt.rs index 2f0f373325a01..e273a56ce025b 100644 --- a/src/librustc_trans/trans/adt.rs +++ b/src/librustc_trans/trans/adt.rs @@ -287,8 +287,11 @@ pub enum PointerField { FatPointer(uint) } +impl Copy for PointerField {} + impl<'tcx> Case<'tcx> { - fn is_zerolen<'a>(&self, cx: &CrateContext<'a, 'tcx>, scapegoat: Ty<'tcx>) -> bool { + fn is_zerolen<'a>(&self, cx: &CrateContext<'a, 'tcx>, scapegoat: Ty<'tcx>) + -> bool { mk_struct(cx, self.tys.as_slice(), false, scapegoat).size == 0 } diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 84a6b59934f6e..7284eb972cabc 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -88,6 +88,7 @@ use libc::{c_uint, uint64_t}; use std::c_str::ToCStr; use std::cell::{Cell, RefCell}; use std::collections::HashSet; +use std::mem; use std::rc::Rc; use std::{i8, i16, i32, i64}; use syntax::abi::{Rust, RustCall, RustIntrinsic, Abi}; @@ -560,6 +561,8 @@ pub fn maybe_name_value(cx: &CrateContext, v: ValueRef, s: &str) { // Used only for creating scalar comparison glue. pub enum scalar_type { nil_type, signed_int, unsigned_int, floating_point, } +impl Copy for scalar_type {} + pub fn compare_scalar_types<'blk, 'tcx>(cx: Block<'blk, 'tcx>, lhs: ValueRef, rhs: ValueRef, @@ -811,7 +814,10 @@ pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, in iter_structural_ty") } } - _ => cx.sess().unimpl("type in iter_structural_ty") + _ => { + cx.sess().unimpl(format!("type in iter_structural_ty: {}", + ty_to_string(cx.tcx(), t)).as_slice()) + } } return cx; } @@ -1782,6 +1788,14 @@ pub fn build_return_block<'blk, 'tcx>(fcx: &FunctionContext<'blk, 'tcx>, } } +#[deriving(Clone, Eq, PartialEq)] +pub enum IsUnboxedClosureFlag { + NotUnboxedClosure, + IsUnboxedClosure, +} + +impl Copy for IsUnboxedClosureFlag {} + // trans_closure: Builds an LLVM function out of a source function. // If the function closes over its environment a closure will be // returned. @@ -2186,6 +2200,8 @@ pub enum ValueOrigin { InlinedCopy, } +impl Copy for ValueOrigin {} + /// Set the appropriate linkage for an LLVM `ValueRef` (function or global). /// If the `llval` is the direct translation of a specific Rust item, `id` /// should be set to the `NodeId` of that item. (This mapping should be @@ -3046,7 +3062,11 @@ fn internalize_symbols(cx: &SharedCrateContext, reachable: &HashSet) { fn next(&mut self) -> Option { let old = self.cur; if !old.is_null() { - self.cur = unsafe { (self.step)(old) }; + self.cur = unsafe { + let step: unsafe extern "C" fn(ValueRef) -> ValueRef = + mem::transmute_copy(&self.step); + step(old) + }; Some(old) } else { None diff --git a/src/librustc_trans/trans/basic_block.rs b/src/librustc_trans/trans/basic_block.rs index 328c8e616c40b..b55c268d9a909 100644 --- a/src/librustc_trans/trans/basic_block.rs +++ b/src/librustc_trans/trans/basic_block.rs @@ -15,6 +15,8 @@ use std::iter::{Filter, Map}; pub struct BasicBlock(pub BasicBlockRef); +impl Copy for BasicBlock {} + pub type Preds<'a> = Map<'a, Value, BasicBlock, Filter<'a, Value, Users>>; /// Wrapper for LLVM BasicBlockRef diff --git a/src/librustc_trans/trans/cabi.rs b/src/librustc_trans/trans/cabi.rs index 0214bf29eeeb9..b849767c38807 100644 --- a/src/librustc_trans/trans/cabi.rs +++ b/src/librustc_trans/trans/cabi.rs @@ -31,6 +31,8 @@ pub enum ArgKind { Ignore, } +impl Copy for ArgKind {} + /// Information about how a specific C type /// should be passed to or returned from a function /// @@ -48,6 +50,8 @@ pub struct ArgType { pub attr: option::Option } +impl Copy for ArgType {} + impl ArgType { pub fn direct(ty: Type, cast: option::Option, pad: option::Option, diff --git a/src/librustc_trans/trans/cabi_x86_64.rs b/src/librustc_trans/trans/cabi_x86_64.rs index 69ee5301d18bf..00c91ddebb38e 100644 --- a/src/librustc_trans/trans/cabi_x86_64.rs +++ b/src/librustc_trans/trans/cabi_x86_64.rs @@ -40,6 +40,8 @@ enum RegClass { Memory } +impl Copy for RegClass {} + trait TypeMethods { fn is_reg_ty(&self) -> bool; } diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index 176fe7096e751..24c1b55554ce2 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -64,6 +64,8 @@ pub struct MethodData { pub llself: ValueRef, } +impl Copy for MethodData {} + pub enum CalleeData<'tcx> { Closure(Datum<'tcx, Lvalue>), @@ -1201,6 +1203,8 @@ pub enum AutorefArg { DoAutorefArg(ast::NodeId) } +impl Copy for AutorefArg {} + pub fn trans_arg_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, formal_arg_ty: Ty<'tcx>, arg_datum: Datum<'tcx, Expr>, diff --git a/src/librustc_trans/trans/cleanup.rs b/src/librustc_trans/trans/cleanup.rs index 33393ba76c580..ba3e70fe036fc 100644 --- a/src/librustc_trans/trans/cleanup.rs +++ b/src/librustc_trans/trans/cleanup.rs @@ -55,6 +55,8 @@ pub struct CustomScopeIndex { index: uint } +impl Copy for CustomScopeIndex {} + pub const EXIT_BREAK: uint = 0; pub const EXIT_LOOP: uint = 1; pub const EXIT_MAX: uint = 2; @@ -88,11 +90,15 @@ pub enum EarlyExitLabel { LoopExit(ast::NodeId, uint) } +impl Copy for EarlyExitLabel {} + pub struct CachedEarlyExit { label: EarlyExitLabel, cleanup_block: BasicBlockRef, } +impl Copy for CachedEarlyExit {} + pub trait Cleanup<'tcx> { fn must_unwind(&self) -> bool; fn clean_on_unwind(&self) -> bool; @@ -111,6 +117,8 @@ pub enum ScopeId { CustomScope(CustomScopeIndex) } +impl Copy for ScopeId {} + impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { /// Invoked when we start to trans the code contained within a new cleanup scope. fn push_ast_cleanup_scope(&self, debug_loc: NodeInfo) { @@ -876,6 +884,8 @@ pub struct DropValue<'tcx> { zero: bool } +impl<'tcx> Copy for DropValue<'tcx> {} + impl<'tcx> Cleanup<'tcx> for DropValue<'tcx> { fn must_unwind(&self) -> bool { self.must_unwind @@ -910,12 +920,16 @@ pub enum Heap { HeapExchange } +impl Copy for Heap {} + pub struct FreeValue<'tcx> { ptr: ValueRef, heap: Heap, content_ty: Ty<'tcx> } +impl<'tcx> Copy for FreeValue<'tcx> {} + impl<'tcx> Cleanup<'tcx> for FreeValue<'tcx> { fn must_unwind(&self) -> bool { true @@ -950,6 +964,8 @@ pub struct FreeSlice { heap: Heap, } +impl Copy for FreeSlice {} + impl<'tcx> Cleanup<'tcx> for FreeSlice { fn must_unwind(&self) -> bool { true @@ -981,6 +997,8 @@ pub struct LifetimeEnd { ptr: ValueRef, } +impl Copy for LifetimeEnd {} + impl<'tcx> Cleanup<'tcx> for LifetimeEnd { fn must_unwind(&self) -> bool { false diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs index bb4df00bd944a..b03f5ff8ecc9c 100644 --- a/src/librustc_trans/trans/closure.rs +++ b/src/librustc_trans/trans/closure.rs @@ -107,6 +107,8 @@ pub struct EnvValue<'tcx> { datum: Datum<'tcx, Lvalue> } +impl<'tcx> Copy for EnvValue<'tcx> {} + impl<'tcx> EnvValue<'tcx> { pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String { format!("{}({})", self.action, self.datum.to_string(ccx)) diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index febb33f6c54af..7c46f920299ec 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -128,6 +128,8 @@ pub struct tydesc_info<'tcx> { pub name: ValueRef, } +impl<'tcx> Copy for tydesc_info<'tcx> {} + /* * A note on nomenclature of linking: "extern", "foreign", and "upcall". * @@ -159,6 +161,8 @@ pub struct NodeInfo { pub span: Span, } +impl Copy for NodeInfo {} + pub fn expr_info(expr: &ast::Expr) -> NodeInfo { NodeInfo { id: expr.id, span: expr.span } } @@ -873,10 +877,11 @@ pub enum ExprOrMethodCall { MethodCall(typeck::MethodCall) } +impl Copy for ExprOrMethodCall {} + pub fn node_id_substs<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, node: ExprOrMethodCall) - -> subst::Substs<'tcx> -{ + -> subst::Substs<'tcx> { let tcx = bcx.tcx(); let substs = match node { diff --git a/src/librustc_trans/trans/datum.rs b/src/librustc_trans/trans/datum.rs index f0fd94958ee97..908edbb412d4a 100644 --- a/src/librustc_trans/trans/datum.rs +++ b/src/librustc_trans/trans/datum.rs @@ -46,6 +46,8 @@ pub struct Datum<'tcx, K> { pub kind: K, } +impl<'tcx,K:Copy> Copy for Datum<'tcx,K> {} + pub struct DatumBlock<'blk, 'tcx: 'blk, K> { pub bcx: Block<'blk, 'tcx>, pub datum: Datum<'tcx, K>, @@ -66,6 +68,8 @@ pub enum Expr { #[deriving(Clone, Show)] pub struct Lvalue; +impl Copy for Lvalue {} + #[deriving(Show)] pub struct Rvalue { pub mode: RvalueMode @@ -91,6 +95,8 @@ pub enum RvalueMode { ByValue, } +impl Copy for RvalueMode {} + pub fn immediate_rvalue<'tcx>(val: ValueRef, ty: Ty<'tcx>) -> Datum<'tcx, Rvalue> { return Datum::new(val, ty, Rvalue::new(ByValue)); } @@ -536,11 +542,19 @@ impl<'tcx, K: KindOps + fmt::Show> Datum<'tcx, K> { /// Copies the value into a new location. This function always preserves the existing datum as /// a valid value. Therefore, it does not consume `self` and, also, cannot be applied to affine /// values (since they must never be duplicated). - pub fn shallow_copy<'blk>(&self, - bcx: Block<'blk, 'tcx>, - dst: ValueRef) - -> Block<'blk, 'tcx> { - assert!(!ty::type_moves_by_default(bcx.tcx(), self.ty)); + pub fn shallow_copy<'blk, 'tcx>(&self, + bcx: Block<'blk, 'tcx>, + dst: ValueRef) + -> Block<'blk, 'tcx> { + /*! + * Copies the value into a new location. This function always + * preserves the existing datum as a valid value. Therefore, + * it does not consume `self` and, also, cannot be applied to + * affine values (since they must never be duplicated). + */ + + let param_env = ty::empty_parameter_environment(); + assert!(!ty::type_moves_by_default(bcx.tcx(), self.ty, ¶m_env)); self.shallow_copy_raw(bcx, dst) } diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 555cb0004892f..72ba5a445ee82 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -251,6 +251,8 @@ static FLAGS_NONE: c_uint = 0; #[deriving(Show, Hash, Eq, PartialEq, Clone)] struct UniqueTypeId(ast::Name); +impl Copy for UniqueTypeId {} + // The TypeMap is where the CrateDebugContext holds the type metadata nodes // created so far. The metadata nodes are indexed by UniqueTypeId, and, for // faster lookup, also by Ty. The TypeMap is responsible for creating @@ -2323,6 +2325,8 @@ enum EnumDiscriminantInfo { NoDiscriminant } +impl Copy for EnumDiscriminantInfo {} + // Returns a tuple of (1) type_metadata_stub of the variant, (2) the llvm_type // of the variant, and (3) a MemberDescriptionFactory for producing the // descriptions of the fields of the variant. This is a rudimentary version of a @@ -3048,6 +3052,8 @@ enum DebugLocation { UnknownLocation } +impl Copy for DebugLocation {} + impl DebugLocation { fn new(scope: DIScope, line: uint, col: uint) -> DebugLocation { KnownLocation { diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 646ee601a4ca4..58301cc1450d2 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -71,6 +71,8 @@ pub enum Dest { Ignore, } +impl Copy for Dest {} + impl Dest { pub fn to_string(&self, ccx: &CrateContext) -> String { match *self { @@ -1874,6 +1876,8 @@ pub enum cast_kind { cast_other, } +impl Copy for cast_kind {} + pub fn cast_type_kind<'tcx>(tcx: &ty::ctxt<'tcx>, t: Ty<'tcx>) -> cast_kind { match t.sty { ty::ty_char => cast_integral, diff --git a/src/librustc_trans/trans/tvec.rs b/src/librustc_trans/trans/tvec.rs index 00f938191f8d9..18ea8055a4eb5 100644 --- a/src/librustc_trans/trans/tvec.rs +++ b/src/librustc_trans/trans/tvec.rs @@ -96,6 +96,8 @@ pub struct VecTypes<'tcx> { pub llunit_alloc_size: u64 } +impl<'tcx> Copy for VecTypes<'tcx> {} + impl<'tcx> VecTypes<'tcx> { pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String { format!("VecTypes {{unit_ty={}, llunit_ty={}, \ @@ -301,8 +303,6 @@ pub fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, 1 => expr::trans_into(bcx, &**element, SaveIn(lldest)), count => { let elem = unpack_datum!(bcx, expr::trans(bcx, &**element)); - assert!(!ty::type_moves_by_default(bcx.tcx(), elem.ty)); - let bcx = iter_vec_loop(bcx, lldest, vt, C_uint(bcx.ccx(), count), |set_bcx, lleltptr, _| { diff --git a/src/librustc_trans/trans/type_.rs b/src/librustc_trans/trans/type_.rs index 8bff7602ddcea..387af7390b209 100644 --- a/src/librustc_trans/trans/type_.rs +++ b/src/librustc_trans/trans/type_.rs @@ -31,6 +31,8 @@ pub struct Type { rf: TypeRef } +impl Copy for Type {} + macro_rules! ty ( ($e:expr) => ( Type::from_ref(unsafe { $e })) ) diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs index 005f6ca4c7086..adc919c91bf36 100644 --- a/src/librustc_trans/trans/type_of.rs +++ b/src/librustc_trans/trans/type_of.rs @@ -449,12 +449,13 @@ pub enum named_ty { an_unboxed_closure, } +impl Copy for named_ty {} + pub fn llvm_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, what: named_ty, did: ast::DefId, tps: &[Ty<'tcx>]) - -> String -{ + -> String { let name = match what { a_struct => "struct", an_enum => "enum", diff --git a/src/librustc_trans/trans/value.rs b/src/librustc_trans/trans/value.rs index 33ea239412af6..fa06e039023e1 100644 --- a/src/librustc_trans/trans/value.rs +++ b/src/librustc_trans/trans/value.rs @@ -16,6 +16,8 @@ use libc::c_uint; pub struct Value(pub ValueRef); +impl Copy for Value {} + macro_rules! opt_val ( ($e:expr) => ( unsafe { match $e { @@ -123,9 +125,14 @@ impl Value { } } +/// Wrapper for LLVM UseRef pub struct Use(UseRef); -/// Wrapper for LLVM UseRef +impl Copy for Use {} + +/** + * Wrapper for LLVM UseRef + */ impl Use { pub fn get(&self) -> UseRef { let Use(v) = *self; v @@ -148,6 +155,7 @@ impl Use { } /// Iterator for the users of a value +#[allow(missing_copy_implementations)] pub struct Users { next: Option } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6f1ddaff3605f..dd1067b0d242a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1178,6 +1178,8 @@ pub enum PrimitiveType { PrimitiveTuple, } +impl Copy for PrimitiveType {} + #[deriving(Clone, Encodable, Decodable)] pub enum TypeKind { TypeEnum, @@ -1190,6 +1192,8 @@ pub enum TypeKind { TypeTypedef, } +impl Copy for TypeKind {} + impl PrimitiveType { fn from_str(s: &str) -> Option { match s.as_slice() { @@ -1843,6 +1847,8 @@ pub enum Mutability { Immutable, } +impl Copy for Mutability {} + impl Clean for ast::Mutability { fn clean(&self, _: &DocContext) -> Mutability { match self { diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index adfd9aa821328..1aac91c4a5c7a 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -82,6 +82,8 @@ pub enum StructType { Unit } +impl Copy for StructType {} + pub enum TypeBound { RegionBound, TraitBound(ast::TraitRef) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 6e0b76d441b93..003818d4fa6b8 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -49,6 +49,11 @@ pub struct WhereClause<'a>(pub &'a clean::Generics); /// Wrapper struct for emitting type parameter bounds. pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]); +impl Copy for VisSpace {} +impl Copy for FnStyleSpace {} +impl Copy for MutableSpace {} +impl Copy for RawMutableSpace {} + impl VisSpace { pub fn get(&self) -> Option { let VisSpace(v) = *self; v diff --git a/src/librustdoc/html/item_type.rs b/src/librustdoc/html/item_type.rs index cb3ad9d063f3a..9e69071234116 100644 --- a/src/librustdoc/html/item_type.rs +++ b/src/librustdoc/html/item_type.rs @@ -43,6 +43,8 @@ pub enum ItemType { Constant = 18, } +impl Copy for ItemType {} + impl ItemType { pub fn to_static_str(&self) -> &'static str { match *self { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 2be703e2458bb..1bb275bab5e62 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -226,7 +226,13 @@ struct Source<'a>(&'a str); // Helper structs for rendering items/sidebars and carrying along contextual // information -struct Item<'a> { cx: &'a Context, item: &'a clean::Item, } +struct Item<'a> { + cx: &'a Context, + item: &'a clean::Item, +} + +impl<'a> Copy for Item<'a> {} + struct Sidebar<'a> { cx: &'a Context, item: &'a clean::Item, } /// Struct representing one entry in the JS search index. These are all emitted diff --git a/src/librustdoc/stability_summary.rs b/src/librustdoc/stability_summary.rs index 42f4c2a0ca63a..881270afe140c 100644 --- a/src/librustdoc/stability_summary.rs +++ b/src/librustdoc/stability_summary.rs @@ -39,6 +39,8 @@ pub struct Counts { pub unmarked: uint, } +impl Copy for Counts {} + impl Add for Counts { fn add(&self, other: &Counts) -> Counts { Counts { diff --git a/src/librustrt/bookkeeping.rs b/src/librustrt/bookkeeping.rs index 714bbd569bdbc..e918a496d5531 100644 --- a/src/librustrt/bookkeeping.rs +++ b/src/librustrt/bookkeeping.rs @@ -26,6 +26,7 @@ use mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; static TASK_COUNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; static TASK_LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; +#[allow(missing_copy_implementations)] pub struct Token { _private: () } impl Drop for Token { diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index 261bd1b9f8cb8..07094f08c5de9 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -85,6 +85,7 @@ use libc; /// /// This structure wraps a `*libc::c_char`, and will automatically free the /// memory it is pointing to when it goes out of scope. +#[allow(missing_copy_implementations)] pub struct CString { buf: *const libc::c_char, owns_buffer_: bool, diff --git a/src/librustrt/mutex.rs b/src/librustrt/mutex.rs index 2f0daf8f6e242..5b58ec8fd3a8b 100644 --- a/src/librustrt/mutex.rs +++ b/src/librustrt/mutex.rs @@ -361,6 +361,7 @@ mod imp { #[cfg(any(target_os = "macos", target_os = "ios"))] mod os { + use core::kinds::Copy; use libc; #[cfg(target_arch = "x86_64")] @@ -384,12 +385,17 @@ mod imp { __sig: libc::c_long, __opaque: [u8, ..__PTHREAD_MUTEX_SIZE__], } + + impl Copy for pthread_mutex_t {} + #[repr(C)] pub struct pthread_cond_t { __sig: libc::c_long, __opaque: [u8, ..__PTHREAD_COND_SIZE__], } + impl Copy for pthread_cond_t {} + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { __sig: _PTHREAD_MUTEX_SIG_INIT, __opaque: [0, ..__PTHREAD_MUTEX_SIZE__], @@ -402,6 +408,7 @@ mod imp { #[cfg(target_os = "linux")] mod os { + use core::kinds::Copy; use libc; // minus 8 because we have an 'align' field @@ -431,12 +438,17 @@ mod imp { __align: libc::c_longlong, size: [u8, ..__SIZEOF_PTHREAD_MUTEX_T], } + + impl Copy for pthread_mutex_t {} + #[repr(C)] pub struct pthread_cond_t { __align: libc::c_longlong, size: [u8, ..__SIZEOF_PTHREAD_COND_T], } + impl Copy for pthread_cond_t {} + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { __align: 0, size: [0, ..__SIZEOF_PTHREAD_MUTEX_T], diff --git a/src/librustrt/unwind.rs b/src/librustrt/unwind.rs index 697ee95df4c0f..714d30ae4b13e 100644 --- a/src/librustrt/unwind.rs +++ b/src/librustrt/unwind.rs @@ -77,6 +77,7 @@ use task::Task; use libunwind as uw; +#[allow(missing_copy_implementations)] pub struct Unwinder { unwinding: bool, } diff --git a/src/librustrt/util.rs b/src/librustrt/util.rs index c77fbd4aee067..fd30c3a48d2d5 100644 --- a/src/librustrt/util.rs +++ b/src/librustrt/util.rs @@ -29,6 +29,9 @@ pub const ENFORCE_SANITY: bool = true || !cfg!(rtopt) || cfg!(rtdebug) || pub struct Stdio(libc::c_int); #[allow(non_upper_case_globals)] +impl Copy for Stdio {} + +#[allow(non_uppercase_statics)] pub const Stdout: Stdio = Stdio(libc::STDOUT_FILENO); #[allow(non_upper_case_globals)] pub const Stderr: Stdio = Stdio(libc::STDERR_FILENO); diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index b7d8885a5f993..1def3d7bfb030 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -26,6 +26,8 @@ pub enum CharacterSet { UrlSafe } +impl Copy for CharacterSet {} + /// Contains configuration parameters for `to_base64`. pub struct Config { /// Character set to use @@ -36,6 +38,8 @@ pub struct Config { pub line_length: Option } +impl Copy for Config {} + /// Configuration for RFC 4648 standard base64 encoding pub static STANDARD: Config = Config {char_set: Standard, pad: true, line_length: None}; @@ -168,6 +172,8 @@ pub enum FromBase64Error { InvalidBase64Length, } +impl Copy for FromBase64Error {} + impl fmt::Show for FromBase64Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 2a3c410ba7c58..5fbf1d32ef557 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -68,6 +68,8 @@ pub enum FromHexError { InvalidHexLength, } +impl Copy for FromHexError {} + impl fmt::Show for FromHexError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index fa82eb93faeec..86b978042e133 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -247,6 +247,8 @@ pub enum ErrorCode { NotUtf8, } +impl Copy for ErrorCode {} + #[deriving(Clone, PartialEq, Show)] pub enum ParserError { /// msg, line, col @@ -254,6 +256,8 @@ pub enum ParserError { IoError(io::IoErrorKind, &'static str), } +impl Copy for ParserError {} + // Builder and Parser have the same errors. pub type BuilderError = ParserError; diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 403ca9d14321a..cad539aaf8ada 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -18,6 +18,7 @@ use core::kinds::Sized; use fmt; use iter::IteratorExt; +use kinds::Copy; use mem; use option::{Option, Some, None}; use slice::{SlicePrelude, AsSlice}; @@ -29,6 +30,8 @@ use vec::Vec; #[deriving(Clone, PartialEq, PartialOrd, Ord, Eq, Hash)] pub struct Ascii { chr: u8 } +impl Copy for Ascii {} + impl Ascii { /// Converts an ascii character into a `u8`. #[inline] diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index d8023dd3e4e3b..731a8296941d9 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -33,6 +33,8 @@ /// } /// } /// +/// impl Copy for Flags {} +/// /// fn main() { /// let e1 = FLAG_A | FLAG_C; /// let e2 = FLAG_B | FLAG_C; @@ -55,6 +57,8 @@ /// } /// } /// +/// impl Copy for Flags {} +/// /// impl Flags { /// pub fn clear(&mut self) { /// self.bits = 0; // The `bits` field can be accessed from within the @@ -260,6 +264,7 @@ macro_rules! bitflags { #[cfg(test)] #[allow(non_upper_case_globals)] mod tests { + use kinds::Copy; use hash; use option::{Some, None}; use ops::{BitOr, BitAnd, BitXor, Sub, Not}; @@ -283,12 +288,16 @@ mod tests { } } + impl Copy for Flags {} + bitflags! { flags AnotherSetOfFlags: i8 { const AnotherFlag = -1_i8, } } + impl Copy for AnotherSetOfFlags {} + #[test] fn test_bits(){ assert_eq!(Flags::empty().bits(), 0x00000000); diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index f41ccea0aaf03..b46d0e21dc258 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -16,7 +16,7 @@ use clone::Clone; use cmp; use hash::{Hash, Hasher}; use iter::{Iterator, count}; -use kinds::{Sized, marker}; +use kinds::{Copy, Sized, marker}; use mem::{min_align_of, size_of}; use mem; use num::{Int, UnsignedInt}; @@ -80,12 +80,16 @@ struct RawBucket { val: *mut V } +impl Copy for RawBucket {} + pub struct Bucket { raw: RawBucket, idx: uint, table: M } +impl Copy for Bucket {} + pub struct EmptyBucket { raw: RawBucket, idx: uint, diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs index 2b66e91c00db0..b55cc4581671e 100644 --- a/src/libstd/comm/mod.rs +++ b/src/libstd/comm/mod.rs @@ -403,6 +403,8 @@ pub enum TryRecvError { Disconnected, } +impl Copy for TryRecvError {} + /// This enumeration is the list of the possible error outcomes for the /// `SyncSender::try_send` method. #[deriving(PartialEq, Clone, Show)] diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 3cd0c0eeaf290..3b36d2fde4472 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -29,7 +29,10 @@ use str; use string::String; use vec::Vec; -pub struct DynamicLibrary { handle: *mut u8 } +#[allow(missing_copy_implementations)] +pub struct DynamicLibrary { + handle: *mut u8 +} impl Drop for DynamicLibrary { fn drop(&mut self) { @@ -210,6 +213,7 @@ pub mod dl { use c_str::{CString, ToCStr}; use libc; + use kinds::Copy; use ptr; use result::*; use string::String; @@ -262,6 +266,8 @@ pub mod dl { Local = 0, } + impl Copy for Rtld {} + #[link_name = "dl"] extern { fn dlopen(filename: *const libc::c_char, diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 5ed10eab15b80..18f20f8ea8710 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -231,6 +231,7 @@ use error::{FromError, Error}; use fmt; use int; use iter::{Iterator, IteratorExt}; +use kinds::Copy; use mem::transmute; use ops::{BitOr, BitXor, BitAnd, Sub, Not}; use option::{Option, Some, None}; @@ -418,6 +419,8 @@ pub enum IoErrorKind { NoProgress, } +impl Copy for IoErrorKind {} + /// A trait that lets you add a `detail` to an IoError easily trait UpdateIoError { /// Returns an IoError with updated description and detail @@ -1558,6 +1561,8 @@ pub enum SeekStyle { SeekCur, } +impl Copy for SeekStyle {} + /// An object implementing `Seek` internally has some form of cursor which can /// be moved within a stream of bytes. The stream typically has a fixed size, /// allowing seeking relative to either end. @@ -1680,6 +1685,8 @@ pub enum FileMode { Truncate, } +impl Copy for FileMode {} + /// Access permissions with which the file should be opened. `File`s /// opened with `Read` will return an error if written to. pub enum FileAccess { @@ -1691,6 +1698,8 @@ pub enum FileAccess { ReadWrite, } +impl Copy for FileAccess {} + /// Different kinds of files which can be identified by a call to stat #[deriving(PartialEq, Show, Hash, Clone)] pub enum FileType { @@ -1713,6 +1722,8 @@ pub enum FileType { Unknown, } +impl Copy for FileType {} + /// A structure used to describe metadata information about a file. This /// structure is created through the `stat` method on a `Path`. /// @@ -1764,6 +1775,8 @@ pub struct FileStat { pub unstable: UnstableFileStat, } +impl Copy for FileStat {} + /// This structure represents all of the possible information which can be /// returned from a `stat` syscall which is not contained in the `FileStat` /// structure. This information is not necessarily platform independent, and may @@ -1793,6 +1806,8 @@ pub struct UnstableFileStat { pub gen: u64, } +impl Copy for UnstableFileStat {} + bitflags! { #[doc = "A set of permissions for a file or directory is represented"] #[doc = "by a set of flags which are or'd together."] @@ -1887,6 +1902,8 @@ bitflags! { } } +impl Copy for FilePermission {} + impl Default for FilePermission { #[inline] fn default() -> FilePermission { FilePermission::empty() } diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs index 7de7869213091..7ca43722a43f5 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/io/net/addrinfo.rs @@ -22,6 +22,7 @@ pub use self::Protocol::*; use iter::IteratorExt; use io::{IoResult}; use io::net::ip::{SocketAddr, IpAddr}; +use kinds::Copy; use option::{Option, Some, None}; use sys; use vec::Vec; @@ -31,6 +32,8 @@ pub enum SocketType { Stream, Datagram, Raw } +impl Copy for SocketType {} + /// Flags which can be or'd into the `flags` field of a `Hint`. These are used /// to manipulate how a query is performed. /// @@ -45,12 +48,16 @@ pub enum Flag { V4Mapped, } +impl Copy for Flag {} + /// A transport protocol associated with either a hint or a return value of /// `lookup` pub enum Protocol { TCP, UDP } +impl Copy for Protocol {} + /// This structure is used to provide hints when fetching addresses for a /// remote host to control how the lookup is performed. /// @@ -63,6 +70,8 @@ pub struct Hint { pub flags: uint, } +impl Copy for Hint {} + pub struct Info { pub address: SocketAddr, pub family: uint, @@ -71,6 +80,8 @@ pub struct Info { pub flags: uint, } +impl Copy for Info {} + /// Easy name resolution. Given a hostname, returns the list of IP addresses for /// that hostname. pub fn get_host_addresses(host: &str) -> IoResult> { diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 4812e911cc481..c187c80e87d78 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -18,6 +18,7 @@ pub use self::IpAddr::*; use fmt; +use kinds::Copy; use io::{mod, IoResult, IoError}; use io::net; use iter::{Iterator, IteratorExt}; @@ -35,6 +36,8 @@ pub enum IpAddr { Ipv6Addr(u16, u16, u16, u16, u16, u16, u16, u16) } +impl Copy for IpAddr {} + impl fmt::Show for IpAddr { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match *self { @@ -66,6 +69,8 @@ pub struct SocketAddr { pub port: Port, } +impl Copy for SocketAddr {} + impl fmt::Show for SocketAddr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.ip { diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index d4d24c1e12fc8..3678800108cbc 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -480,6 +480,8 @@ pub enum StdioContainer { CreatePipe(bool /* readable */, bool /* writable */), } +impl Copy for StdioContainer {} + /// Describes the result of a process after it has terminated. /// Note that Windows have no signals, so the result is usually ExitStatus. #[deriving(PartialEq, Eq, Clone)] @@ -491,6 +493,8 @@ pub enum ProcessExit { ExitSignal(int), } +impl Copy for ProcessExit {} + impl fmt::Show for ProcessExit { /// Format a ProcessExit enum, to nicely present the information. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index e78bd1dd33f32..faa52226a03b7 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -83,6 +83,8 @@ impl Buffer for LimitReader { /// A `Writer` which ignores bytes written to it, like /dev/null. pub struct NullWriter; +impl Copy for NullWriter {} + impl Writer for NullWriter { #[inline] fn write(&mut self, _buf: &[u8]) -> io::IoResult<()> { Ok(()) } @@ -91,6 +93,8 @@ impl Writer for NullWriter { /// A `Reader` which returns an infinite stream of 0 bytes, like /dev/zero. pub struct ZeroReader; +impl Copy for ZeroReader {} + impl Reader for ZeroReader { #[inline] fn read(&mut self, buf: &mut [u8]) -> io::IoResult { @@ -111,6 +115,8 @@ impl Buffer for ZeroReader { /// A `Reader` which is always at EOF, like /dev/null. pub struct NullReader; +impl Copy for NullReader {} + impl Reader for NullReader { #[inline] fn read(&mut self, _buf: &mut [u8]) -> io::IoResult { diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index b42286c0308ce..3f9c7dc427cea 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -18,6 +18,7 @@ pub use self::SignFormat::*; use char; use char::Char; +use kinds::Copy; use num; use num::{Int, Float, FPNaN, FPInfinite, ToPrimitive}; use slice::{SlicePrelude, CloneSliceAllocPrelude}; @@ -38,6 +39,8 @@ pub enum ExponentFormat { ExpBin, } +impl Copy for ExponentFormat {} + /// The number of digits used for emitting the fractional part of a number, if /// any. pub enum SignificantDigits { @@ -55,6 +58,8 @@ pub enum SignificantDigits { DigExact(uint) } +impl Copy for SignificantDigits {} + /// How to emit the sign of a number. pub enum SignFormat { /// No sign will be printed. The exponent sign will also be emitted. @@ -67,25 +72,33 @@ pub enum SignFormat { SignAll, } -/// Converts an integral number to its string representation as a byte vector. -/// This is meant to be a common base implementation for all integral string -/// conversion functions like `to_string()` or `to_str_radix()`. -/// -/// # Arguments -/// -/// - `num` - The number to convert. Accepts any number that -/// implements the numeric traits. -/// - `radix` - Base to use. Accepts only the values 2-36. -/// - `sign` - How to emit the sign. Options are: -/// - `SignNone`: No sign at all. Basically emits `abs(num)`. -/// - `SignNeg`: Only `-` on negative values. -/// - `SignAll`: Both `+` on positive, and `-` on negative numbers. -/// - `f` - a callback which will be invoked for each ascii character -/// which composes the string representation of this integer -/// -/// # Panics -/// -/// - Panics if `radix` < 2 or `radix` > 36. +impl Copy for SignFormat {} + +/** + * Converts an integral number to its string representation as a byte vector. + * This is meant to be a common base implementation for all integral string + * conversion functions like `to_string()` or `to_str_radix()`. + * + * # Arguments + * - `num` - The number to convert. Accepts any number that + * implements the numeric traits. + * - `radix` - Base to use. Accepts only the values 2-36. + * - `sign` - How to emit the sign. Options are: + * - `SignNone`: No sign at all. Basically emits `abs(num)`. + * - `SignNeg`: Only `-` on negative values. + * - `SignAll`: Both `+` on positive, and `-` on negative numbers. + * - `f` - a callback which will be invoked for each ascii character + * which composes the string representation of this integer + * + * # Return value + * A tuple containing the byte vector, and a boolean flag indicating + * whether it represents a special value like `inf`, `-inf`, `NaN` or not. + * It returns a tuple because there can be ambiguity between a special value + * and a number representation at higher bases. + * + * # Failure + * - Fails if `radix` < 2 or `radix` > 36. + */ fn int_to_str_bytes_common(num: T, radix: uint, sign: SignFormat, f: |u8|) { assert!(2 <= radix && radix <= 36); diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 0abd030a16347..e327d60afc568 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -36,6 +36,7 @@ use error::{FromError, Error}; use fmt; use io::{IoResult, IoError}; use iter::{Iterator, IteratorExt}; +use kinds::Copy; use libc::{c_void, c_int}; use libc; use boxed::Box; @@ -618,6 +619,8 @@ pub struct Pipe { pub writer: c_int, } +impl Copy for Pipe {} + /// Creates a new low-level OS in-memory pipe. /// /// This function can fail to succeed if there are no more resources available @@ -1184,6 +1187,9 @@ pub struct MemoryMap { kind: MemoryMapKind, } +#[cfg(not(stage0))] +impl Copy for MemoryMap {} + /// Type of memory map pub enum MemoryMapKind { /// Virtual memory map. Usually used to change the permissions of a given @@ -1195,6 +1201,8 @@ pub enum MemoryMapKind { MapVirtual } +impl Copy for MemoryMapKind {} + /// Options the memory map is created with pub enum MapOption { /// The memory should be readable @@ -1218,6 +1226,8 @@ pub enum MapOption { MapNonStandardFlags(c_int), } +impl Copy for MapOption {} + /// Possible errors when creating a map. pub enum MapError { /// ## The following are POSIX-specific @@ -1263,6 +1273,8 @@ pub enum MapError { ErrMapViewOfFile(uint) } +impl Copy for MapError {} + impl fmt::Show for MapError { fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result { let str = match *self { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 13891a6333014..d135f27122807 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -22,6 +22,7 @@ use hash; use io::Writer; use iter::{AdditiveIterator, DoubleEndedIteratorExt, Extend}; use iter::{Iterator, IteratorExt, Map}; +use kinds::Copy; use mem; use option::{Option, Some, None}; use slice::{AsSlice, SlicePrelude}; @@ -984,6 +985,8 @@ pub enum PathPrefix { DiskPrefix } +impl Copy for PathPrefix {} + fn parse_prefix<'a>(mut path: &'a str) -> Option { if path.starts_with("\\\\") { // \\ diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index da690f5d154df..a02c2325f194c 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -225,6 +225,7 @@ use cell::RefCell; use clone::Clone; use io::IoResult; use iter::{Iterator, IteratorExt}; +use kinds::Copy; use mem; use rc::Rc; use result::{Ok, Err}; @@ -245,7 +246,11 @@ pub mod reader; /// The standard RNG. This is designed to be efficient on the current /// platform. -pub struct StdRng { rng: IsaacWordRng } +pub struct StdRng { + rng: IsaacWordRng, +} + +impl Copy for StdRng {} impl StdRng { /// Create a randomly seeded instance of `StdRng`. diff --git a/src/libstd/sync/raw.rs b/src/libstd/sync/raw.rs index 47580a115131b..5b844d52de967 100644 --- a/src/libstd/sync/raw.rs +++ b/src/libstd/sync/raw.rs @@ -876,6 +876,8 @@ mod tests { #[cfg(test)] pub enum RWLockMode { Read, Write, Downgrade, DowngradeRead } + impl Copy for RWLockMode {} + #[cfg(test)] fn lock_rwlock_in_mode(x: &Arc, mode: RWLockMode, blk: ||) { match mode { diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index ec2d62ff85cb1..9b29e412bda99 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -13,6 +13,7 @@ #![experimental] use {fmt, i64}; +use kinds::Copy; use ops::{Add, Sub, Mul, Div, Neg}; use option::{Option, Some, None}; use num::Int; @@ -62,6 +63,8 @@ pub const MAX: Duration = Duration { nanos: (i64::MAX % MILLIS_PER_SEC) as i32 * NANOS_PER_MILLI }; +impl Copy for Duration {} + impl Duration { /// Makes a new `Duration` with given number of weeks. /// Equivalent to `Duration::seconds(weeks * 7 * 24 * 60 * 60), with overflow checks. diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 87693f39bbdb1..90724828c7041 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -16,8 +16,17 @@ pub use self::AbiArchitecture::*; use std::fmt; #[deriving(PartialEq)] -pub enum Os { OsWindows, OsMacos, OsLinux, OsAndroid, OsFreebsd, OsiOS, - OsDragonfly } +pub enum Os { + OsWindows, + OsMacos, + OsLinux, + OsAndroid, + OsFreebsd, + OsiOS, + OsDragonfly, +} + +impl Copy for Os {} #[deriving(PartialEq, Eq, Hash, Encodable, Decodable, Clone)] pub enum Abi { @@ -39,6 +48,8 @@ pub enum Abi { RustCall, } +impl Copy for Abi {} + #[allow(non_camel_case_types)] #[deriving(PartialEq)] pub enum Architecture { @@ -49,6 +60,8 @@ pub enum Architecture { Mipsel } +impl Copy for Architecture {} + pub struct AbiData { abi: Abi, @@ -56,6 +69,8 @@ pub struct AbiData { name: &'static str, } +impl Copy for AbiData {} + pub enum AbiArchitecture { /// Not a real ABI (e.g., intrinsic) RustArch, @@ -66,6 +81,9 @@ pub enum AbiArchitecture { } #[allow(non_upper_case_globals)] +impl Copy for AbiArchitecture {} + +#[allow(non_uppercase_statics)] static AbiDatas: &'static [AbiData] = &[ // Platform-specific ABIs AbiData {abi: Cdecl, name: "cdecl" }, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 7e421df505d6c..0a04a953b314f 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -86,6 +86,8 @@ pub struct Ident { pub ctxt: SyntaxContext } +impl Copy for Ident {} + impl Ident { /// Construct an identifier with the given name and an empty context: pub fn new(name: Name) -> Ident { Ident {name: name, ctxt: EMPTY_CTXT}} @@ -161,6 +163,8 @@ pub const ILLEGAL_CTXT : SyntaxContext = 1; #[deriving(Eq, Ord, PartialEq, PartialOrd, Hash, Encodable, Decodable, Clone)] pub struct Name(pub u32); +impl Copy for Name {} + impl Name { pub fn as_str<'a>(&'a self) -> &'a str { unsafe { @@ -204,6 +208,8 @@ pub struct Lifetime { pub name: Name } +impl Copy for Lifetime {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct LifetimeDef { pub lifetime: Lifetime, @@ -338,6 +344,8 @@ pub struct DefId { pub node: NodeId, } +impl Copy for DefId {} + /// Item definitions in the currently-compiled crate would have the CrateNum /// LOCAL_CRATE in their DefId. pub const LOCAL_CRATE: CrateNum = 0; @@ -482,6 +490,8 @@ pub enum BindingMode { BindByValue(Mutability), } +impl Copy for BindingMode {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum PatWildKind { /// Represents the wildcard pattern `_` @@ -491,6 +501,8 @@ pub enum PatWildKind { PatWildMulti, } +impl Copy for PatWildKind {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum Pat_ { /// Represents a wildcard pattern (either `_` or `..`) @@ -526,6 +538,8 @@ pub enum Mutability { MutImmutable, } +impl Copy for Mutability {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum BinOp { BiAdd, @@ -548,6 +562,9 @@ pub enum BinOp { BiGt, } +#[cfg(not(stage0))] +impl Copy for BinOp {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum UnOp { UnUniq, @@ -556,6 +573,8 @@ pub enum UnOp { UnNeg } +impl Copy for UnOp {} + pub type Stmt = Spanned; #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] @@ -581,6 +600,8 @@ pub enum LocalSource { LocalFor, } +impl Copy for LocalSource {} + // FIXME (pending discussion of #1697, #2178...): local should really be // a refinement on pat. /// Local represents a `let` statement, e.g., `let : = ;` @@ -628,12 +649,16 @@ pub enum BlockCheckMode { UnsafeBlock(UnsafeSource), } +impl Copy for BlockCheckMode {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum UnsafeSource { CompilerGenerated, UserProvided, } +impl Copy for UnsafeSource {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct Expr { pub id: NodeId, @@ -718,12 +743,16 @@ pub enum MatchSource { MatchWhileLetDesugar, } +impl Copy for MatchSource {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum CaptureClause { CaptureByValue, CaptureByRef, } +impl Copy for CaptureClause {} + /// A delimited sequence of token trees #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct Delimited { @@ -780,6 +809,8 @@ pub enum KleeneOp { OneOrMore, } +impl Copy for KleeneOp {} + /// When the main rust parser encounters a syntax-extension invocation, it /// parses the arguments to the invocation as a token-tree. This is a very /// loose structure, such that all sorts of different AST-fragments can @@ -895,6 +926,8 @@ pub enum StrStyle { RawStr(uint) } +impl Copy for StrStyle {} + pub type Lit = Spanned; #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] @@ -903,7 +936,9 @@ pub enum Sign { Plus } -impl Sign { +impl Copy for Sign {} + +impl Sign where T: Int { pub fn new(n: T) -> Sign { if n < Int::zero() { Minus @@ -920,6 +955,8 @@ pub enum LitIntType { UnsuffixedIntLit(Sign) } +impl Copy for LitIntType {} + impl LitIntType { pub fn suffix_len(&self) -> uint { match *self { @@ -1015,6 +1052,8 @@ pub enum IntTy { TyI64, } +impl Copy for IntTy {} + impl fmt::Show for IntTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", ast_util::int_ty_to_string(*self, None)) @@ -1040,6 +1079,8 @@ pub enum UintTy { TyU64, } +impl Copy for UintTy {} + impl UintTy { pub fn suffix_len(&self) -> uint { match *self { @@ -1062,6 +1103,8 @@ pub enum FloatTy { TyF64, } +impl Copy for FloatTy {} + impl fmt::Show for FloatTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", ast_util::float_ty_to_string(*self)) @@ -1095,12 +1138,16 @@ pub enum PrimTy { TyChar } +impl Copy for PrimTy {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)] pub enum Onceness { Once, Many } +impl Copy for Onceness {} + impl fmt::Show for Onceness { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { @@ -1171,6 +1218,8 @@ pub enum AsmDialect { AsmIntel } +impl Copy for AsmDialect {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct InlineAsm { pub asm: InternedString, @@ -1228,6 +1277,8 @@ pub enum FnStyle { NormalFn, } +impl Copy for FnStyle {} + impl fmt::Show for FnStyle { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { @@ -1345,6 +1396,8 @@ pub enum PathListItem_ { PathListMod { id: NodeId } } +impl Copy for PathListItem_ {} + impl PathListItem_ { pub fn id(&self) -> NodeId { match *self { @@ -1404,9 +1457,13 @@ pub enum AttrStyle { AttrInner, } +impl Copy for AttrStyle {} + #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct AttrId(pub uint); +impl Copy for AttrId {} + /// Doc-comments are promoted to attributes that have is_sugared_doc = true #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct Attribute_ { @@ -1442,6 +1499,8 @@ pub enum Visibility { Inherited, } +impl Copy for Visibility {} + impl Visibility { pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility { match self { @@ -1477,6 +1536,8 @@ pub enum StructFieldKind { UnnamedField(Visibility), } +impl Copy for StructFieldKind {} + impl StructFieldKind { pub fn is_unnamed(&self) -> bool { match *self { @@ -1583,6 +1644,8 @@ pub enum UnboxedClosureKind { FnOnceUnboxedClosureKind, } +impl Copy for UnboxedClosureKind {} + /// The data we save and restore about an inlined item or method. This is not /// part of the AST that we parse from a file, but it becomes part of the tree /// that we trans. diff --git a/src/libsyntax/ast_map/blocks.rs b/src/libsyntax/ast_map/blocks.rs index 8db12fbd8355f..639a33a806395 100644 --- a/src/libsyntax/ast_map/blocks.rs +++ b/src/libsyntax/ast_map/blocks.rs @@ -43,6 +43,8 @@ use visit; /// To construct one, use the `Code::from_node` function. pub struct FnLikeNode<'a> { node: ast_map::Node<'a> } +impl<'a> Copy for FnLikeNode<'a> {} + /// MaybeFnLike wraps a method that indicates if an object /// corresponds to some FnLikeNode. pub trait MaybeFnLike { fn is_fn_like(&self) -> bool; } @@ -85,6 +87,8 @@ pub enum Code<'a> { BlockCode(&'a Block), } +impl<'a> Copy for Code<'a> {} + impl<'a> Code<'a> { pub fn id(&self) -> ast::NodeId { match *self { diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index 2913666a31535..072969ff120e9 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -38,6 +38,8 @@ pub enum PathElem { PathName(Name) } +impl Copy for PathElem {} + impl PathElem { pub fn name(&self) -> Name { match *self { @@ -120,6 +122,8 @@ pub enum Node<'ast> { NodeLifetime(&'ast Lifetime), } +impl<'ast> Copy for Node<'ast> {} + /// Represents an entry and its parent Node ID /// The odd layout is to bring down the total size. #[deriving(Show)] @@ -147,6 +151,8 @@ enum MapEntry<'ast> { RootInlinedParent(&'ast InlinedParent) } +impl<'ast> Copy for MapEntry<'ast> {} + impl<'ast> Clone for MapEntry<'ast> { fn clone(&self) -> MapEntry<'ast> { *self diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 68bb7ecfb8526..7dba6a57fc4c9 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -315,6 +315,8 @@ pub struct IdRange { pub max: NodeId, } +impl Copy for IdRange {} + impl IdRange { pub fn max() -> IdRange { IdRange { diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index a2811681efd37..5894a88ece65a 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -282,6 +282,8 @@ pub enum InlineAttr { InlineNever, } +impl Copy for InlineAttr {} + /// Determine what `#[inline]` attribute is present in `attrs`, if any. pub fn find_inline_attr(attrs: &[Attribute]) -> InlineAttr { // FIXME (#2809)---validate the usage of #[inline] and #[inline] @@ -354,6 +356,8 @@ pub enum StabilityLevel { Locked } +impl Copy for StabilityLevel {} + pub fn find_stability_generic<'a, AM: AttrMetaMethods, I: Iterator<&'a AM>> @@ -469,6 +473,8 @@ pub enum ReprAttr { ReprPacked, } +impl Copy for ReprAttr {} + impl ReprAttr { pub fn is_ffi_safe(&self) -> bool { match *self { @@ -486,6 +492,8 @@ pub enum IntType { UnsignedInt(ast::UintTy) } +impl Copy for IntType {} + impl IntType { #[inline] pub fn is_signed(self) -> bool { diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 27e8c265e5c34..344e01ad4f116 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -34,12 +34,16 @@ pub trait Pos { #[deriving(Clone, PartialEq, Eq, Hash, PartialOrd, Show)] pub struct BytePos(pub u32); +impl Copy for BytePos {} + /// A character offset. Because of multibyte utf8 characters, a byte offset /// is not equivalent to a character offset. The CodeMap will convert BytePos /// values to CharPos values as necessary. #[deriving(PartialEq, Hash, PartialOrd, Show)] pub struct CharPos(pub uint); +impl Copy for CharPos {} + // FIXME: Lots of boilerplate in these impls, but so far my attempts to fix // have been unsuccessful @@ -90,6 +94,8 @@ pub struct Span { pub expn_id: ExpnId } +impl Copy for Span {} + pub const DUMMY_SP: Span = Span { lo: BytePos(0), hi: BytePos(0), expn_id: NO_EXPANSION }; #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] @@ -98,6 +104,8 @@ pub struct Spanned { pub span: Span, } +impl Copy for Spanned {} + impl PartialEq for Span { fn eq(&self, other: &Span) -> bool { return (*self).lo == (*other).lo && (*self).hi == (*other).hi; @@ -183,6 +191,8 @@ pub enum MacroFormat { MacroBang } +impl Copy for MacroFormat {} + #[deriving(Clone, Hash, Show)] pub struct NameAndSpan { /// The name of the macro that was invoked to create the thing @@ -221,6 +231,8 @@ pub struct ExpnInfo { #[deriving(PartialEq, Eq, Clone, Show, Hash, Encodable, Decodable)] pub struct ExpnId(u32); +impl Copy for ExpnId {} + pub const NO_EXPANSION: ExpnId = ExpnId(-1); impl ExpnId { @@ -249,6 +261,8 @@ pub struct MultiByteChar { pub bytes: uint, } +impl Copy for MultiByteChar {} + /// A single source in the CodeMap pub struct FileMap { /// The name of the file that the source came from, source that doesn't diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 293c1b3a9530f..bbda80bd96c33 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -40,6 +40,8 @@ pub enum RenderSpan { FileLine(Span), } +impl Copy for RenderSpan {} + impl RenderSpan { fn span(self) -> Span { match self { @@ -61,6 +63,8 @@ pub enum ColorConfig { Never } +impl Copy for ColorConfig {} + pub trait Emitter { fn emit(&mut self, cmsp: Option<(&codemap::CodeMap, Span)>, msg: &str, code: Option<&str>, lvl: Level); @@ -73,10 +77,14 @@ pub trait Emitter { /// how a rustc task died (if so desired). pub struct FatalError; +impl Copy for FatalError {} + /// Signifies that the compiler died with an explicit call to `.bug` /// or `.span_bug` rather than a failed assertion, etc. pub struct ExplicitBug; +impl Copy for ExplicitBug {} + /// A span-handler is like a handler but also /// accepts span information for source-location /// reporting. @@ -230,6 +238,8 @@ pub enum Level { Help, } +impl Copy for Level {} + impl fmt::Show for Level { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use std::fmt::Show; diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 8d0d399fa3153..fd72ee7597e5d 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -57,7 +57,7 @@ impl ItemDecorator for fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, |P|) { - (*self)(ecx, sp, meta_item, item, push) + self.clone()(ecx, sp, meta_item, item, push) } } @@ -77,7 +77,7 @@ impl ItemModifier for fn(&mut ExtCtxt, Span, &ast::MetaItem, P) -> P< meta_item: &ast::MetaItem, item: P) -> P { - (*self)(ecx, span, meta_item, item) + self.clone()(ecx, span, meta_item, item) } } @@ -99,7 +99,7 @@ impl TTMacroExpander for MacroExpanderFn { span: Span, token_tree: &[ast::TokenTree]) -> Box { - (*self)(ecx, span, token_tree) + self.clone()(ecx, span, token_tree) } } @@ -122,7 +122,7 @@ impl IdentMacroExpander for IdentMacroExpanderFn { ident: ast::Ident, token_tree: Vec ) -> Box { - (*self)(cx, sp, ident, token_tree) + self.clone()(cx, sp, ident, token_tree) } } @@ -228,6 +228,8 @@ pub struct DummyResult { span: Span } +impl Copy for DummyResult {} + impl DummyResult { /// Create a default MacResult that can be anything. /// diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index 98345e1dd6724..c878709f842df 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -85,6 +85,8 @@ pub enum OrderingOp { PartialCmpOp, LtOp, LeOp, GtOp, GeOp, } +impl Copy for OrderingOp {} + pub fn some_ordering_collapsed(cx: &mut ExtCtxt, span: Span, op: OrderingOp, diff --git a/src/libsyntax/ext/mtwt.rs b/src/libsyntax/ext/mtwt.rs index 6ba90bbebed01..48120b575acd2 100644 --- a/src/libsyntax/ext/mtwt.rs +++ b/src/libsyntax/ext/mtwt.rs @@ -56,6 +56,8 @@ pub enum SyntaxContext_ { IllegalCtxt } +impl Copy for SyntaxContext_ {} + /// A list of ident->name renamings pub type RenameList = Vec<(Ident, Name)>; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index c7aef0020b2c4..f257eb613f145 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -107,6 +107,8 @@ pub struct Features { pub quote: bool, } +impl Copy for Features {} + impl Features { pub fn new() -> Features { Features { diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index b62d2d744c9e0..b880b89c2d318 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -36,6 +36,8 @@ pub enum CommentStyle { BlankLine, } +impl Copy for CommentStyle {} + #[deriving(Clone)] pub struct Comment { pub style: CommentStyle, diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 650f8295d01a6..2a2bb42cef012 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -34,6 +34,8 @@ pub enum ObsoleteSyntax { ObsoleteExternCrateRenaming, } +impl Copy for ObsoleteSyntax {} + pub trait ParserObsoleteMethods { /// Reports an obsolete syntax non-fatal error. fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 920bcc3a951ae..2e11070d3b2f6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -97,6 +97,8 @@ bitflags! { } } +impl Copy for Restrictions {} + type ItemInfo = (Ident, Item_, Option >); /// How to parse a path. There are four different kinds of paths, all of which @@ -113,6 +115,8 @@ pub enum PathParsingMode { LifetimeAndTypesWithColons, } +impl Copy for PathParsingMode {} + enum ItemOrViewItem { /// Indicates a failure to parse any kind of item. The attributes are /// returned. diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 52b54bc7f2d6d..4b1e9482a7d49 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -42,6 +42,8 @@ pub enum BinOpToken { Shr, } +impl Copy for BinOpToken {} + /// A delimeter token #[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] pub enum DelimToken { @@ -53,6 +55,8 @@ pub enum DelimToken { Brace, } +impl Copy for DelimToken {} + #[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] pub enum IdentStyle { /// `::` follows the identifier with no whitespace in-between. @@ -85,6 +89,12 @@ impl Lit { } } +#[cfg(not(stage0))] +impl Copy for Lit {} + +#[cfg(not(stage0))] +impl Copy for IdentStyle {} + #[allow(non_camel_case_types)] #[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] pub enum Token { @@ -435,6 +445,8 @@ macro_rules! declare_special_idents_and_keywords {( $( $rk_variant, )* } + impl Copy for Keyword {} + impl Keyword { pub fn to_name(&self) -> ast::Name { match *self { diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 7ab3d5dbcd1b5..c4e040a0f7c1a 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -72,18 +72,24 @@ pub enum Breaks { Inconsistent, } +impl Copy for Breaks {} + #[deriving(Clone)] pub struct BreakToken { offset: int, blank_space: int } +impl Copy for BreakToken {} + #[deriving(Clone)] pub struct BeginToken { offset: int, breaks: Breaks } +impl Copy for BeginToken {} + #[deriving(Clone)] pub enum Token { String(string::String, int), @@ -152,11 +158,15 @@ pub enum PrintStackBreak { Broken(Breaks), } +impl Copy for PrintStackBreak {} + pub struct PrintStackElem { offset: int, pbreak: PrintStackBreak } +impl Copy for PrintStackElem {} + static SIZE_INFINITY: int = 0xffff; pub fn mk_printer(out: Box, linewidth: uint) -> Printer { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index e9937dc9b6045..64217ea091a33 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -47,6 +47,8 @@ pub trait PpAnn { pub struct NoAnn; +impl Copy for NoAnn {} + impl PpAnn for NoAnn {} pub struct CurrentCommentAndLiteral { @@ -54,6 +56,8 @@ pub struct CurrentCommentAndLiteral { cur_lit: uint, } +impl Copy for CurrentCommentAndLiteral {} + pub struct State<'a> { pub s: pp::Printer, cm: Option<&'a CodeMap>, diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 18623ca2a81e2..f5e89dd61ff7e 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -44,6 +44,8 @@ pub enum FnKind<'a> { FkFnBlock, } +impl<'a> Copy for FnKind<'a> {} + /// Each method of the Visitor trait is a hook to be potentially /// overridden. Each method's default implementation recursively visits /// the substructure of the input via the corresponding `walk` method; diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 0e4ecb8f73e48..575ec860f973e 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -165,6 +165,7 @@ pub mod color { /// Terminal attributes pub mod attr { pub use self::Attr::*; + use std::kinds::Copy; /// Terminal attributes for use with term.attr(). /// @@ -193,6 +194,8 @@ pub mod attr { /// Convenience attribute to set the background color BackgroundColor(super::color::Color) } + + impl Copy for Attr {} } /// A terminal with similar capabilities to an ANSI Terminal diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index d644542db0732..bbaa36701eb30 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -33,6 +33,8 @@ enum States { SeekIfEndPercent(int) } +impl Copy for States {} + #[deriving(PartialEq)] enum FormatState { FormatStateFlags, @@ -40,6 +42,8 @@ enum FormatState { FormatStatePrecision } +impl Copy for FormatState {} + /// Types of parameters a capability can use #[allow(missing_docs)] #[deriving(Clone)] @@ -452,6 +456,8 @@ struct Flags { space: bool } +impl Copy for Flags {} + impl Flags { fn new() -> Flags { Flags{ width: 0, precision: 0, alternate: false, @@ -467,6 +473,8 @@ enum FormatOp { FormatString } +impl Copy for FormatOp {} + impl FormatOp { fn from_char(c: char) -> FormatOp { match c { diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index fbc60c9b34257..61c57514aa9c3 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -109,7 +109,13 @@ impl Show for TestName { } #[deriving(Clone)] -enum NamePadding { PadNone, PadOnLeft, PadOnRight } +enum NamePadding { + PadNone, + PadOnLeft, + PadOnRight, +} + +impl Copy for NamePadding {} impl TestDesc { fn padded_name(&self, column_count: uint, align: NamePadding) -> String { @@ -185,6 +191,8 @@ pub struct Bencher { pub bytes: u64, } +impl Copy for Bencher {} + // The definition of a single test. A test runner will run a list of // these. #[deriving(Clone, Show, PartialEq, Eq, Hash)] @@ -206,6 +214,8 @@ pub struct Metric { noise: f64 } +impl Copy for Metric {} + impl Metric { pub fn new(value: f64, noise: f64) -> Metric { Metric {value: value, noise: noise} @@ -232,6 +242,8 @@ pub enum MetricChange { Regression(f64) } +impl Copy for MetricChange {} + pub type MetricDiff = TreeMap; // The default console test runner. It accepts the command line @@ -274,6 +286,8 @@ pub enum ColorConfig { NeverColor, } +impl Copy for ColorConfig {} + pub struct TestOpts { pub filter: Option, pub run_ignored: bool, @@ -1068,7 +1082,7 @@ pub fn run_test(opts: &TestOpts, return; } StaticBenchFn(benchfn) => { - let bs = ::bench::benchmark(|harness| benchfn(harness)); + let bs = ::bench::benchmark(|harness| (benchfn.clone())(harness)); monitor_ch.send((desc, TrBench(bs), Vec::new())); return; } diff --git a/src/libtime/lib.rs b/src/libtime/lib.rs index a77a6276a8b4e..fa3bd7c5fc75d 100644 --- a/src/libtime/lib.rs +++ b/src/libtime/lib.rs @@ -77,7 +77,13 @@ mod imp { /// A record specifying a time value in seconds and nanoseconds. #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable, Show)] -pub struct Timespec { pub sec: i64, pub nsec: i32 } +pub struct Timespec { + pub sec: i64, + pub nsec: i32, +} + +impl Copy for Timespec {} + /* * Timespec assumes that pre-epoch Timespecs have negative sec and positive * nsec fields. Darwin's and Linux's struct timespec functions handle pre- @@ -269,6 +275,8 @@ pub struct Tm { pub tm_nsec: i32, } +impl Copy for Tm {} + pub fn empty_tm() -> Tm { Tm { tm_sec: 0_i32, @@ -428,6 +436,8 @@ pub enum ParseError { UnexpectedCharacter(char, char), } +impl Copy for ParseError {} + impl Show for ParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { diff --git a/src/libunicode/tables.rs b/src/libunicode/tables.rs index 7cece6701dc85..9fa924eb2590d 100644 --- a/src/libunicode/tables.rs +++ b/src/libunicode/tables.rs @@ -7136,6 +7136,7 @@ pub mod charwidth { pub mod grapheme { pub use self::GraphemeCat::*; use core::slice::SlicePrelude; + use core::kinds::Copy; use core::slice; #[allow(non_camel_case_types)] @@ -7153,6 +7154,8 @@ pub mod grapheme { GC_Any, } + impl Copy for GraphemeCat {} + fn bsearch_range_value_table(c: char, r: &'static [(char, char, GraphemeCat)]) -> GraphemeCat { use core::cmp::{Equal, Less, Greater}; match r.binary_search(|&(lo, hi, _)| { diff --git a/src/test/auxiliary/issue-14422.rs b/src/test/auxiliary/issue-14422.rs index 04e1d99301108..9ecb1195de00a 100644 --- a/src/test/auxiliary/issue-14422.rs +++ b/src/test/auxiliary/issue-14422.rs @@ -25,6 +25,8 @@ mod src { pub struct A; + impl Copy for A {} + pub fn make() -> B { A } impl A { diff --git a/src/test/auxiliary/issue13213aux.rs b/src/test/auxiliary/issue13213aux.rs index 5bd52ef501068..cf8d0c167a1ce 100644 --- a/src/test/auxiliary/issue13213aux.rs +++ b/src/test/auxiliary/issue13213aux.rs @@ -22,6 +22,10 @@ mod private { p: i32, } pub const THREE: P = P { p: 3 }; + impl Copy for P {} } pub static A: S = S { p: private::THREE }; + +impl Copy for S {} + diff --git a/src/test/auxiliary/lang-item-public.rs b/src/test/auxiliary/lang-item-public.rs index ea2461ccfa8ef..e6bae4628874c 100644 --- a/src/test/auxiliary/lang-item-public.rs +++ b/src/test/auxiliary/lang-item-public.rs @@ -22,3 +22,8 @@ extern fn stack_exhausted() {} #[lang = "eh_personality"] extern fn eh_personality() {} + +#[lang="copy"] +pub trait Copy {} + + diff --git a/src/test/auxiliary/method_self_arg1.rs b/src/test/auxiliary/method_self_arg1.rs index d02222931e5de..37022131c3d94 100644 --- a/src/test/auxiliary/method_self_arg1.rs +++ b/src/test/auxiliary/method_self_arg1.rs @@ -16,6 +16,8 @@ pub fn get_count() -> u64 { unsafe { COUNT } } pub struct Foo; +impl Copy for Foo {} + impl Foo { pub fn foo(self, x: &Foo) { unsafe { COUNT *= 2; } diff --git a/src/test/auxiliary/method_self_arg2.rs b/src/test/auxiliary/method_self_arg2.rs index 99eb665388b26..e1e79b59e3e44 100644 --- a/src/test/auxiliary/method_self_arg2.rs +++ b/src/test/auxiliary/method_self_arg2.rs @@ -16,6 +16,8 @@ pub fn get_count() -> u64 { unsafe { COUNT } } pub struct Foo; +impl Copy for Foo {} + impl Foo { pub fn run_trait(self) { unsafe { COUNT *= 17; } diff --git a/src/test/auxiliary/xcrate_unit_struct.rs b/src/test/auxiliary/xcrate_unit_struct.rs index d56d7a70edfc8..5a918db1cfa20 100644 --- a/src/test/auxiliary/xcrate_unit_struct.rs +++ b/src/test/auxiliary/xcrate_unit_struct.rs @@ -14,20 +14,31 @@ pub struct Struct; +impl Copy for Struct {} + pub enum Unit { UnitVariant, Argument(Struct) } +impl Copy for Unit {} + pub struct TupleStruct(pub uint, pub &'static str); +impl Copy for TupleStruct {} + // used by the cfail test pub struct StructWithFields { foo: int, } +impl Copy for StructWithFields {} + pub enum EnumWithVariants { EnumVariant, EnumVariantArg(int) } + +impl Copy for EnumWithVariants {} + diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 419e39b53cf81..025f8467d2067 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -21,6 +21,8 @@ struct Vec2 { y: f32, } +impl Copy for Vec2 {} + fn lerp(a: f32, b: f32, v: f32) -> f32 { a * (1.0 - v) + b * v } fn smooth(v: f32) -> f32 { v * v * (3.0 - 2.0 * v) } diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 3059a014528ad..e954d0fed5e59 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -53,7 +53,14 @@ fn print_complements() { } } -enum Color { Red, Yellow, Blue } +enum Color { + Red, + Yellow, + Blue, +} + +impl Copy for Color {} + impl fmt::Show for Color { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let str = match *self { @@ -70,6 +77,8 @@ struct CreatureInfo { color: Color } +impl Copy for CreatureInfo {} + fn show_color_list(set: Vec) -> String { let mut out = String::new(); for col in set.iter() { diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index b38b8e66d7dbd..4b890bbd8d30e 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -67,6 +67,8 @@ struct P { p: [i32, .. 16], } +impl Copy for P {} + struct Perm { cnt: [i32, .. 16], fact: [u32, .. 16], @@ -75,6 +77,8 @@ struct Perm { perm: P, } +impl Copy for Perm {} + impl Perm { fn new(n: u32) -> Perm { let mut fact = [1, .. 16]; diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index 0b4a1d91968d2..afffbe5bed4e4 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -109,6 +109,8 @@ struct AminoAcid { p: f32, } +impl Copy for AminoAcid {} + struct RepeatFasta<'a, W:'a> { alu: &'static str, out: &'a mut W diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index b030e7bb93e87..3c5f0b63ce933 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -62,6 +62,8 @@ static OCCURRENCES: [&'static str, ..5] = [ #[deriving(PartialEq, PartialOrd, Ord, Eq)] struct Code(u64); +impl Copy for Code {} + impl Code { fn hash(&self) -> u64 { let Code(ret) = *self; diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index b62504d7ba85d..3f36c16aff63f 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -100,6 +100,8 @@ struct Planet { mass: f64, } +impl Copy for Planet {} + fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: int) { for _ in range(0, steps) { let mut b_slice = bodies.as_mut_slice(); diff --git a/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs b/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs index c071691c94707..d5998c8ca9935 100644 --- a/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs +++ b/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs @@ -14,11 +14,15 @@ struct Foo { bar2: Bar } +impl Copy for Foo {} + struct Bar { int1: int, int2: int, } +impl Copy for Bar {} + fn make_foo() -> Box { panic!() } fn borrow_same_field_twice_mut_mut() { diff --git a/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs b/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs index 3a85b45ad126d..d252d44229792 100644 --- a/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs +++ b/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs @@ -13,11 +13,15 @@ struct Foo { bar2: Bar } +impl Copy for Foo {} + struct Bar { int1: int, int2: int, } +impl Copy for Bar {} + fn make_foo() -> Foo { panic!() } fn borrow_same_field_twice_mut_mut() { diff --git a/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs b/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs deleted file mode 100644 index 2063d7388a9dd..0000000000000 --- a/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2012 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. - -enum Either { Left(T), Right(U) } - - fn f(x: &mut Either, y: &Either) -> int { - match *y { - Either::Left(ref z) => { - *x = Either::Right(1.0); - *z - } - _ => panic!() - } - } - - fn g() { - let mut x: Either = Either::Left(3); - println!("{}", f(&mut x, &x)); //~ ERROR cannot borrow - } - - fn h() { - let mut x: Either = Either::Left(3); - let y: &Either = &x; - let z: &mut Either = &mut x; //~ ERROR cannot borrow - *z = *y; - } - - fn main() {} diff --git a/src/test/compile-fail/borrowck-use-mut-borrow.rs b/src/test/compile-fail/borrowck-use-mut-borrow.rs index 7414bb930d4d6..0d27473cb2d02 100644 --- a/src/test/compile-fail/borrowck-use-mut-borrow.rs +++ b/src/test/compile-fail/borrowck-use-mut-borrow.rs @@ -9,6 +9,9 @@ // except according to those terms. struct A { a: int, b: int } + +impl Copy for A {} + struct B { a: int, b: Box } fn var_copy_after_var_borrow() { diff --git a/src/test/compile-fail/dst-index.rs b/src/test/compile-fail/dst-index.rs index f6511d68662ee..af97c864dc81a 100644 --- a/src/test/compile-fail/dst-index.rs +++ b/src/test/compile-fail/dst-index.rs @@ -16,6 +16,8 @@ use std::fmt::Show; struct S; +impl Copy for S {} + impl Index for S { fn index<'a>(&'a self, _: &uint) -> &'a str { "hello" @@ -24,6 +26,8 @@ impl Index for S { struct T; +impl Copy for T {} + impl Index for T { fn index<'a>(&'a self, idx: &uint) -> &'a (Show + 'static) { static x: uint = 42; @@ -33,7 +37,8 @@ impl Index for T { fn main() { S[0]; - //~^ ERROR E0161 + //~^ ERROR cannot move out of dereference + //~^^ ERROR E0161 T[0]; //~^ ERROR cannot move out of dereference //~^^ ERROR E0161 diff --git a/src/test/compile-fail/dst-rvalue.rs b/src/test/compile-fail/dst-rvalue.rs index 52b7ea9efa5ed..4c1dafd8c1a49 100644 --- a/src/test/compile-fail/dst-rvalue.rs +++ b/src/test/compile-fail/dst-rvalue.rs @@ -13,8 +13,10 @@ pub fn main() { let _x: Box = box *"hello world"; //~^ ERROR E0161 + //~^^ ERROR cannot move out of dereference let array: &[int] = &[1, 2, 3]; let _x: Box<[int]> = box *array; //~^ ERROR E0161 + //~^^ ERROR cannot move out of dereference } diff --git a/src/test/compile-fail/issue-17651.rs b/src/test/compile-fail/issue-17651.rs index ef8174a26aa82..ab396edddf49c 100644 --- a/src/test/compile-fail/issue-17651.rs +++ b/src/test/compile-fail/issue-17651.rs @@ -13,5 +13,6 @@ fn main() { (|| box *[0u].as_slice())(); - //~^ ERROR cannot move a value of type [uint] + //~^ ERROR cannot move out of dereference + //~^^ ERROR cannot move a value of type [uint] } diff --git a/src/test/compile-fail/kindck-copy.rs b/src/test/compile-fail/kindck-copy.rs index f0c4a4243acc9..8868c7f8256da 100644 --- a/src/test/compile-fail/kindck-copy.rs +++ b/src/test/compile-fail/kindck-copy.rs @@ -14,6 +14,7 @@ use std::rc::Rc; fn assert_copy() { } + trait Dummy { } struct MyStruct { @@ -21,6 +22,8 @@ struct MyStruct { y: int, } +impl Copy for MyStruct {} + struct MyNoncopyStruct { x: Box, } diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs index 1a4a87e608b6f..9e5f15c272196 100644 --- a/src/test/compile-fail/lint-dead-code-1.rs +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -12,6 +12,7 @@ #![allow(unused_variables)] #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] +#![allow(missing_copy_implementations)] #![deny(dead_code)] #![crate_type="lib"] diff --git a/src/test/compile-fail/lint-missing-doc.rs b/src/test/compile-fail/lint-missing-doc.rs index 365081aee1ab5..dbcd7644c8f3a 100644 --- a/src/test/compile-fail/lint-missing-doc.rs +++ b/src/test/compile-fail/lint-missing-doc.rs @@ -13,6 +13,7 @@ #![feature(globs)] #![deny(missing_docs)] #![allow(dead_code)] +#![allow(missing_copy_implementations)] //! Some garbage docs for the crate here #![doc="More garbage"] diff --git a/src/test/compile-fail/opt-in-copy.rs b/src/test/compile-fail/opt-in-copy.rs new file mode 100644 index 0000000000000..56f71c844ac29 --- /dev/null +++ b/src/test/compile-fail/opt-in-copy.rs @@ -0,0 +1,33 @@ +// 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. + +struct CantCopyThis; + +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, +} + +enum IWantToCopyThisToo { + ButICant(CantCopyThisEither), +} + +impl Copy for IWantToCopyThisToo {} +//~^ ERROR the trait `Copy` may not be implemented for this type + +fn main() {} + diff --git a/src/test/compile-fail/stage0-clone-contravariant-lifetime.rs b/src/test/compile-fail/stage0-clone-contravariant-lifetime.rs deleted file mode 100644 index 1d1b244ab5aeb..0000000000000 --- a/src/test/compile-fail/stage0-clone-contravariant-lifetime.rs +++ /dev/null @@ -1,43 +0,0 @@ -// 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. - -// A zero-dependency test that covers some basic traits, default -// methods, etc. When mucking about with basic type system stuff I -// often encounter problems in the iterator trait, so it's useful to -// have hanging around. -nmatsakis - -// error-pattern: requires `start` lang_item - -#![no_std] -#![feature(lang_items)] - -#[lang = "sized"] -pub trait Sized for Sized? { - // Empty. -} - -pub mod std { - pub mod clone { - pub trait Clone { - fn clone(&self) -> Self; - } - } -} - -pub struct ContravariantLifetime<'a>; - -impl <'a> ::std::clone::Clone for ContravariantLifetime<'a> { - #[inline] - fn clone(&self) -> ContravariantLifetime<'a> { - match *self { ContravariantLifetime => ContravariantLifetime, } - } -} - -fn main() { } diff --git a/src/test/compile-fail/stage0-cmp.rs b/src/test/compile-fail/stage0-cmp.rs deleted file mode 100644 index f68eb6400fa8d..0000000000000 --- a/src/test/compile-fail/stage0-cmp.rs +++ /dev/null @@ -1,39 +0,0 @@ -// 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. - - -// A zero-dependency test that covers some basic traits, default -// methods, etc. When mucking about with basic type system stuff I -// often encounter problems in the iterator trait, so it's useful to -// have hanging around. -nmatsakis - -// error-pattern: requires `start` lang_item - -#![no_std] -#![feature(lang_items)] - -#[lang = "sized"] -pub trait Sized for Sized? { - // Empty. -} - -#[unstable = "Definition may change slightly after trait reform"] -pub trait PartialEq for Sized? { - /// This method tests for `self` and `other` values to be equal, and is used by `==`. - fn eq(&self, other: &Self) -> bool; -} - -#[unstable = "Trait is unstable."] -impl<'a, Sized? T: PartialEq> PartialEq for &'a T { - #[inline] - fn eq(&self, other: & &'a T) -> bool { PartialEq::eq(*self, *other) } -} - -fn main() { } diff --git a/src/test/debuginfo/generic-method-on-generic-struct.rs b/src/test/debuginfo/generic-method-on-generic-struct.rs index 7ceac0e7ceac6..4c0c82efea35d 100644 --- a/src/test/debuginfo/generic-method-on-generic-struct.rs +++ b/src/test/debuginfo/generic-method-on-generic-struct.rs @@ -147,3 +147,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Struct {} + diff --git a/src/test/debuginfo/method-on-enum.rs b/src/test/debuginfo/method-on-enum.rs index d86aa54f451ee..8cb8fae75cf06 100644 --- a/src/test/debuginfo/method-on-enum.rs +++ b/src/test/debuginfo/method-on-enum.rs @@ -148,3 +148,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Enum {} + diff --git a/src/test/debuginfo/method-on-generic-struct.rs b/src/test/debuginfo/method-on-generic-struct.rs index 2455c7aa51983..d4244ee27d4c2 100644 --- a/src/test/debuginfo/method-on-generic-struct.rs +++ b/src/test/debuginfo/method-on-generic-struct.rs @@ -147,3 +147,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Struct {} + diff --git a/src/test/debuginfo/method-on-struct.rs b/src/test/debuginfo/method-on-struct.rs index 5e47d32e37673..ca00587ba445d 100644 --- a/src/test/debuginfo/method-on-struct.rs +++ b/src/test/debuginfo/method-on-struct.rs @@ -146,3 +146,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Struct {} + diff --git a/src/test/debuginfo/method-on-trait.rs b/src/test/debuginfo/method-on-trait.rs index 4d5f53fc120db..e70f86a53679e 100644 --- a/src/test/debuginfo/method-on-trait.rs +++ b/src/test/debuginfo/method-on-trait.rs @@ -152,3 +152,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Struct {} + diff --git a/src/test/debuginfo/method-on-tuple-struct.rs b/src/test/debuginfo/method-on-tuple-struct.rs index fb3bede37fd4c..31bdd20e409db 100644 --- a/src/test/debuginfo/method-on-tuple-struct.rs +++ b/src/test/debuginfo/method-on-tuple-struct.rs @@ -144,3 +144,6 @@ fn main() { } fn zzz() {()} + +impl Copy for TupleStruct {} + diff --git a/src/test/debuginfo/self-in-default-method.rs b/src/test/debuginfo/self-in-default-method.rs index 287813a959fd0..87fdb2c42c8f8 100644 --- a/src/test/debuginfo/self-in-default-method.rs +++ b/src/test/debuginfo/self-in-default-method.rs @@ -148,3 +148,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Struct {} + diff --git a/src/test/debuginfo/self-in-generic-default-method.rs b/src/test/debuginfo/self-in-generic-default-method.rs index bfb8abc9f6652..6f488230521eb 100644 --- a/src/test/debuginfo/self-in-generic-default-method.rs +++ b/src/test/debuginfo/self-in-generic-default-method.rs @@ -149,3 +149,6 @@ fn main() { } fn zzz() {()} + +impl Copy for Struct {} + diff --git a/src/test/pretty/block-disambig.rs b/src/test/pretty/block-disambig.rs index 1b1765475f338..db01bc94e32b8 100644 --- a/src/test/pretty/block-disambig.rs +++ b/src/test/pretty/block-disambig.rs @@ -21,6 +21,8 @@ fn test2() -> int { let val = &0i; { } *val } struct S { eax: int } +impl Copy for S {} + fn test3() { let regs = &Cell::new(S {eax: 0}); match true { true => { } _ => { } } diff --git a/src/test/run-make/extern-fn-with-packed-struct/test.rs b/src/test/run-make/extern-fn-with-packed-struct/test.rs index 8d8daed1393c7..12d961bd59ebf 100644 --- a/src/test/run-make/extern-fn-with-packed-struct/test.rs +++ b/src/test/run-make/extern-fn-with-packed-struct/test.rs @@ -16,6 +16,8 @@ struct Foo { c: i8 } +impl Copy for Foo {} + #[link(name = "test", kind = "static")] extern { fn foo(f: Foo) -> Foo; diff --git a/src/test/run-make/target-specs/foo.rs b/src/test/run-make/target-specs/foo.rs index eeddd5e19a841..cab98204b17d7 100644 --- a/src/test/run-make/target-specs/foo.rs +++ b/src/test/run-make/target-specs/foo.rs @@ -11,6 +11,9 @@ #![feature(lang_items)] #![no_std] +#[lang="copy"] +trait Copy { } + #[lang="sized"] trait Sized { } diff --git a/src/test/run-pass/borrowck-univariant-enum.rs b/src/test/run-pass/borrowck-univariant-enum.rs index 3d191f6c4b469..df4106c98446c 100644 --- a/src/test/run-pass/borrowck-univariant-enum.rs +++ b/src/test/run-pass/borrowck-univariant-enum.rs @@ -15,6 +15,8 @@ enum newtype { newvar(int) } +impl Copy for newtype {} + pub fn main() { // Test that borrowck treats enums with a single variant diff --git a/src/test/run-pass/builtin-superkinds-in-metadata.rs b/src/test/run-pass/builtin-superkinds-in-metadata.rs index 683e7ece8717d..382caa83c61c7 100644 --- a/src/test/run-pass/builtin-superkinds-in-metadata.rs +++ b/src/test/run-pass/builtin-superkinds-in-metadata.rs @@ -19,10 +19,12 @@ use trait_superkinds_in_metadata::{RequiresCopy}; struct X(T); -impl RequiresShare for X { } +impl Copy for X {} -impl RequiresRequiresShareAndSend for X { } +impl RequiresShare for X { } -impl RequiresCopy for X { } +impl RequiresRequiresShareAndSend for X { } + +impl RequiresCopy for X { } pub fn main() { } diff --git a/src/test/run-pass/cell-does-not-clone.rs b/src/test/run-pass/cell-does-not-clone.rs index c7c655b3db48c..6455f1e4bb2b9 100644 --- a/src/test/run-pass/cell-does-not-clone.rs +++ b/src/test/run-pass/cell-does-not-clone.rs @@ -24,6 +24,8 @@ impl Clone for Foo { } } +impl Copy for Foo {} + pub fn main() { let x = Cell::new(Foo { x: 22 }); let _y = x.get(); diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index a0d35fd596b53..2a9756d7714cd 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -14,6 +14,8 @@ use std::cmp; #[deriving(Show)] enum cat_type { tuxedo, tabby, tortoiseshell } +impl Copy for cat_type {} + impl cmp::PartialEq for cat_type { fn eq(&self, other: &cat_type) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/coherence-impl-in-fn.rs b/src/test/run-pass/coherence-impl-in-fn.rs index 51cd62677ca1c..df0012e07ec72 100644 --- a/src/test/run-pass/coherence-impl-in-fn.rs +++ b/src/test/run-pass/coherence-impl-in-fn.rs @@ -10,6 +10,7 @@ pub fn main() { enum x { foo } + impl Copy for x {} impl ::std::cmp::PartialEq for x { fn eq(&self, other: &x) -> bool { (*self) as int == (*other) as int diff --git a/src/test/run-pass/coherence-where-clause.rs b/src/test/run-pass/coherence-where-clause.rs index faec0c502808c..e0d9d569d175d 100644 --- a/src/test/run-pass/coherence-where-clause.rs +++ b/src/test/run-pass/coherence-where-clause.rs @@ -28,6 +28,8 @@ struct MyType { dummy: uint } +impl Copy for MyType {} + impl MyTrait for MyType { fn get(&self) -> MyType { (*self).clone() } } diff --git a/src/test/run-pass/const-nullary-univariant-enum.rs b/src/test/run-pass/const-nullary-univariant-enum.rs index fe171a9f73dc7..9a1a5de936005 100644 --- a/src/test/run-pass/const-nullary-univariant-enum.rs +++ b/src/test/run-pass/const-nullary-univariant-enum.rs @@ -12,6 +12,8 @@ enum Foo { Bar = 0xDEADBEE } +impl Copy for Foo {} + static X: Foo = Foo::Bar; pub fn main() { diff --git a/src/test/run-pass/dst-struct-sole.rs b/src/test/run-pass/dst-struct-sole.rs index 04fe6d5cefdc3..26cb27cc65392 100644 --- a/src/test/run-pass/dst-struct-sole.rs +++ b/src/test/run-pass/dst-struct-sole.rs @@ -33,6 +33,8 @@ fn foo2(x: &Fat<[T]>) { #[deriving(PartialEq,Eq)] struct Bar; +impl Copy for Bar {} + trait ToBar { fn to_bar(&self) -> Bar; } diff --git a/src/test/run-pass/dst-struct.rs b/src/test/run-pass/dst-struct.rs index 6b8e25e85590f..bf5b300f7cf0a 100644 --- a/src/test/run-pass/dst-struct.rs +++ b/src/test/run-pass/dst-struct.rs @@ -49,6 +49,8 @@ fn foo3(x: &Fat>) { #[deriving(PartialEq,Eq)] struct Bar; +impl Copy for Bar {} + trait ToBar { fn to_bar(&self) -> Bar; } diff --git a/src/test/run-pass/dst-trait.rs b/src/test/run-pass/dst-trait.rs index 9762730955104..907c7810736ba 100644 --- a/src/test/run-pass/dst-trait.rs +++ b/src/test/run-pass/dst-trait.rs @@ -17,11 +17,15 @@ struct Fat { #[deriving(PartialEq,Eq)] struct Bar; +impl Copy for Bar {} + #[deriving(PartialEq,Eq)] struct Bar1 { f: int } +impl Copy for Bar1 {} + trait ToBar { fn to_bar(&self) -> Bar; fn to_val(&self) -> int; diff --git a/src/test/run-pass/empty-tag.rs b/src/test/run-pass/empty-tag.rs index 6b780d854599e..e5d11ac1adb2a 100644 --- a/src/test/run-pass/empty-tag.rs +++ b/src/test/run-pass/empty-tag.rs @@ -11,6 +11,8 @@ #[deriving(Show)] enum chan { chan_t, } +impl Copy for chan {} + impl PartialEq for chan { fn eq(&self, other: &chan) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/enum-discrim-width-stuff.rs b/src/test/run-pass/enum-discrim-width-stuff.rs index deb3f6b6c7c3e..cf8e742947d1d 100644 --- a/src/test/run-pass/enum-discrim-width-stuff.rs +++ b/src/test/run-pass/enum-discrim-width-stuff.rs @@ -20,6 +20,7 @@ macro_rules! check { A = 0 } static C: E = E::V; + impl Copy for E {} pub fn check() { assert_eq!(size_of::(), size_of::<$t>()); assert_eq!(E::V as $t, $v as $t); diff --git a/src/test/run-pass/explicit-self-generic.rs b/src/test/run-pass/explicit-self-generic.rs index 829870930a456..eeda299c71fa6 100644 --- a/src/test/run-pass/explicit-self-generic.rs +++ b/src/test/run-pass/explicit-self-generic.rs @@ -18,10 +18,14 @@ type EqFn = proc(K, K):'static -> bool; struct LM { resize_at: uint, size: uint } +impl Copy for LM {} + enum HashMap { HashMap_(LM) } +impl Copy for HashMap {} + fn linear_map() -> HashMap { HashMap::HashMap_(LM{ resize_at: 32, diff --git a/src/test/run-pass/export-unexported-dep.rs b/src/test/run-pass/export-unexported-dep.rs index 3fc5310a29bc7..48e9d9dea22cd 100644 --- a/src/test/run-pass/export-unexported-dep.rs +++ b/src/test/run-pass/export-unexported-dep.rs @@ -15,6 +15,8 @@ mod foo { // not exported enum t { t1, t2, } + impl Copy for t {} + impl PartialEq for t { fn eq(&self, other: &t) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/expr-copy.rs b/src/test/run-pass/expr-copy.rs index 4a45ce660585f..6e9ba4f8f41f1 100644 --- a/src/test/run-pass/expr-copy.rs +++ b/src/test/run-pass/expr-copy.rs @@ -15,6 +15,8 @@ fn f(arg: &mut A) { struct A { a: int } +impl Copy for A {} + pub fn main() { let mut x = A {a: 10}; f(&mut x); diff --git a/src/test/run-pass/expr-if-struct.rs b/src/test/run-pass/expr-if-struct.rs index 758d726851d07..c95ca3fff8c56 100644 --- a/src/test/run-pass/expr-if-struct.rs +++ b/src/test/run-pass/expr-if-struct.rs @@ -16,6 +16,8 @@ struct I { i: int } +impl Copy for I {} + fn test_rec() { let rs = if true { I {i: 100} } else { I {i: 101} }; assert_eq!(rs.i, 100); @@ -24,6 +26,8 @@ fn test_rec() { #[deriving(Show)] enum mood { happy, sad, } +impl Copy for mood {} + impl PartialEq for mood { fn eq(&self, other: &mood) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/expr-match-struct.rs b/src/test/run-pass/expr-match-struct.rs index ea96005dc602e..83101a3d2cc3a 100644 --- a/src/test/run-pass/expr-match-struct.rs +++ b/src/test/run-pass/expr-match-struct.rs @@ -15,6 +15,8 @@ // Tests for match as expressions resulting in struct types struct R { i: int } +impl Copy for R {} + fn test_rec() { let rs = match true { true => R {i: 100}, _ => panic!() }; assert_eq!(rs.i, 100); @@ -23,6 +25,8 @@ fn test_rec() { #[deriving(Show)] enum mood { happy, sad, } +impl Copy for mood {} + impl PartialEq for mood { fn eq(&self, other: &mood) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/exterior.rs b/src/test/run-pass/exterior.rs index e95c203413155..2ca5f430a2a37 100644 --- a/src/test/run-pass/exterior.rs +++ b/src/test/run-pass/exterior.rs @@ -13,6 +13,8 @@ use std::cell::Cell; struct Point {x: int, y: int, z: int} +impl Copy for Point {} + fn f(p: &Cell) { assert!((p.get().z == 12)); p.set(Point {x: 10, y: 11, z: 13}); diff --git a/src/test/run-pass/extern-pass-TwoU16s.rs b/src/test/run-pass/extern-pass-TwoU16s.rs index 6161d31c4a9ea..2b80a40403626 100644 --- a/src/test/run-pass/extern-pass-TwoU16s.rs +++ b/src/test/run-pass/extern-pass-TwoU16s.rs @@ -16,6 +16,8 @@ pub struct TwoU16s { one: u16, two: u16 } +impl Copy for TwoU16s {} + #[link(name = "rust_test_helpers")] extern { pub fn rust_dbg_extern_identity_TwoU16s(v: TwoU16s) -> TwoU16s; diff --git a/src/test/run-pass/extern-pass-TwoU32s.rs b/src/test/run-pass/extern-pass-TwoU32s.rs index 3e6b650207447..be4998c86fddf 100644 --- a/src/test/run-pass/extern-pass-TwoU32s.rs +++ b/src/test/run-pass/extern-pass-TwoU32s.rs @@ -16,6 +16,8 @@ pub struct TwoU32s { one: u32, two: u32 } +impl Copy for TwoU32s {} + #[link(name = "rust_test_helpers")] extern { pub fn rust_dbg_extern_identity_TwoU32s(v: TwoU32s) -> TwoU32s; diff --git a/src/test/run-pass/extern-pass-TwoU64s.rs b/src/test/run-pass/extern-pass-TwoU64s.rs index 5ad1e89425b09..e8d91815bf9d7 100644 --- a/src/test/run-pass/extern-pass-TwoU64s.rs +++ b/src/test/run-pass/extern-pass-TwoU64s.rs @@ -16,6 +16,8 @@ pub struct TwoU64s { one: u64, two: u64 } +impl Copy for TwoU64s {} + #[link(name = "rust_test_helpers")] extern { pub fn rust_dbg_extern_identity_TwoU64s(v: TwoU64s) -> TwoU64s; diff --git a/src/test/run-pass/extern-pass-TwoU8s.rs b/src/test/run-pass/extern-pass-TwoU8s.rs index 14ba7c80059b5..7aa710df80058 100644 --- a/src/test/run-pass/extern-pass-TwoU8s.rs +++ b/src/test/run-pass/extern-pass-TwoU8s.rs @@ -16,6 +16,8 @@ pub struct TwoU8s { one: u8, two: u8 } +impl Copy for TwoU8s {} + #[link(name = "rust_test_helpers")] extern { pub fn rust_dbg_extern_identity_TwoU8s(v: TwoU8s) -> TwoU8s; diff --git a/src/test/run-pass/foreign-fn-with-byval.rs b/src/test/run-pass/foreign-fn-with-byval.rs index 6a26ec44312d7..5d6815fc3c7a4 100644 --- a/src/test/run-pass/foreign-fn-with-byval.rs +++ b/src/test/run-pass/foreign-fn-with-byval.rs @@ -14,6 +14,8 @@ pub struct S { z: u64, } +impl Copy for S {} + #[link(name = "rust_test_helpers")] extern { pub fn get_x(x: S) -> u64; diff --git a/src/test/run-pass/generic-fn.rs b/src/test/run-pass/generic-fn.rs index 89f342b4ee5ed..a341bfe22eb91 100644 --- a/src/test/run-pass/generic-fn.rs +++ b/src/test/run-pass/generic-fn.rs @@ -14,6 +14,8 @@ fn id(x: T) -> T { return x; } struct Triple {x: int, y: int, z: int} +impl Copy for Triple {} + pub fn main() { let mut x = 62; let mut y = 63; diff --git a/src/test/run-pass/guards-not-exhaustive.rs b/src/test/run-pass/guards-not-exhaustive.rs index c7f3c9d718221..b1bc40b662de1 100644 --- a/src/test/run-pass/guards-not-exhaustive.rs +++ b/src/test/run-pass/guards-not-exhaustive.rs @@ -10,6 +10,8 @@ enum Q { R(Option) } +impl Copy for Q {} + fn xyzzy(q: Q) -> uint { match q { Q::R(S) if S.is_some() => { 0 } diff --git a/src/test/run-pass/guards.rs b/src/test/run-pass/guards.rs index 5bfbe4bf5a01d..0157423863c2a 100644 --- a/src/test/run-pass/guards.rs +++ b/src/test/run-pass/guards.rs @@ -10,6 +10,8 @@ struct Pair { x: int, y: int } +impl Copy for Pair {} + pub fn main() { let a: int = match 10i { x if x < 7 => { 1i } x if x < 11 => { 2i } 10 => { 3i } _ => { 4i } }; diff --git a/src/test/run-pass/issue-12860.rs b/src/test/run-pass/issue-12860.rs index 4496a921e2448..1caa04ae0b16d 100644 --- a/src/test/run-pass/issue-12860.rs +++ b/src/test/run-pass/issue-12860.rs @@ -20,6 +20,8 @@ struct XYZ { z: int } +impl Copy for XYZ {} + fn main() { let mut connected = HashSet::new(); let mut border = HashSet::new(); diff --git a/src/test/run-pass/issue-19100.rs b/src/test/run-pass/issue-19100.rs index cee5c808f9982..0ebd3ae8d9769 100644 --- a/src/test/run-pass/issue-19100.rs +++ b/src/test/run-pass/issue-19100.rs @@ -13,6 +13,8 @@ enum Foo { Baz } +impl Copy for Foo {} + impl Foo { fn foo(&self) { match self { diff --git a/src/test/run-pass/issue-2288.rs b/src/test/run-pass/issue-2288.rs index 85dd879c830ce..1f371f0a1c204 100644 --- a/src/test/run-pass/issue-2288.rs +++ b/src/test/run-pass/issue-2288.rs @@ -12,10 +12,13 @@ trait clam { fn chowder(&self, y: A); } + struct foo { x: A, } +impl Copy for foo {} + impl clam for foo { fn chowder(&self, _y: A) { } diff --git a/src/test/run-pass/issue-2633.rs b/src/test/run-pass/issue-2633.rs index a9ebfbcbf3322..bc014f699c731 100644 --- a/src/test/run-pass/issue-2633.rs +++ b/src/test/run-pass/issue-2633.rs @@ -12,6 +12,8 @@ struct cat { meow: extern "Rust" fn(), } +impl Copy for cat {} + fn meow() { println!("meow") } @@ -24,6 +26,8 @@ fn cat() -> cat { struct KittyInfo {kitty: cat} +impl Copy for KittyInfo {} + // Code compiles and runs successfully if we add a + before the first arg fn nyan(kitty: cat, _kitty_info: KittyInfo) { (kitty.meow)(); diff --git a/src/test/run-pass/issue-3121.rs b/src/test/run-pass/issue-3121.rs index d0e995da5f130..9e9d611f1a320 100644 --- a/src/test/run-pass/issue-3121.rs +++ b/src/test/run-pass/issue-3121.rs @@ -13,6 +13,10 @@ enum side { mayo, catsup, vinegar } enum order { hamburger, fries(side), shake } enum meal { to_go(order), for_here(order) } +impl Copy for side {} +impl Copy for order {} +impl Copy for meal {} + fn foo(m: Box, cond: bool) { match *m { meal::to_go(_) => { } diff --git a/src/test/run-pass/issue-3563-3.rs b/src/test/run-pass/issue-3563-3.rs index 4e330b9a0e7dd..d04d8f92ac40d 100644 --- a/src/test/run-pass/issue-3563-3.rs +++ b/src/test/run-pass/issue-3563-3.rs @@ -29,6 +29,8 @@ struct Point { y: int, } +impl Copy for Point {} + // Represents an offset on a canvas. (This has the same structure as a Point. // but different semantics). struct Size { @@ -36,11 +38,15 @@ struct Size { height: int, } +impl Copy for Size {} + struct Rect { top_left: Point, size: Size, } +impl Copy for Rect {} + // Contains the information needed to do shape rendering via ASCII art. struct AsciiArt { width: uint, diff --git a/src/test/run-pass/issue-3743.rs b/src/test/run-pass/issue-3743.rs index bebaad2d297c7..ada3e37c092a7 100644 --- a/src/test/run-pass/issue-3743.rs +++ b/src/test/run-pass/issue-3743.rs @@ -13,6 +13,8 @@ struct Vec2 { y: f64 } +impl Copy for Vec2 {} + // methods we want to export as methods as well as operators impl Vec2 { #[inline(always)] diff --git a/src/test/run-pass/issue-3753.rs b/src/test/run-pass/issue-3753.rs index 9fbabed3a94dd..de6926e551296 100644 --- a/src/test/run-pass/issue-3753.rs +++ b/src/test/run-pass/issue-3753.rs @@ -19,11 +19,15 @@ pub struct Point { y: f64 } +impl Copy for Point {} + pub enum Shape { Circle(Point, f64), Rectangle(Point, Point) } +impl Copy for Shape {} + impl Shape { pub fn area(&self, sh: Shape) -> f64 { match sh { diff --git a/src/test/run-pass/issue-5688.rs b/src/test/run-pass/issue-5688.rs index 73bf375923a74..0a13e001fabf5 100644 --- a/src/test/run-pass/issue-5688.rs +++ b/src/test/run-pass/issue-5688.rs @@ -18,7 +18,11 @@ failed to typecheck correctly. */ struct X { vec: &'static [int] } + +impl Copy for X {} + static V: &'static [X] = &[X { vec: &[1, 2, 3] }]; + pub fn main() { for &v in V.iter() { println!("{}", v.vec); diff --git a/src/test/run-pass/lang-item-public.rs b/src/test/run-pass/lang-item-public.rs index 982d4f6a0b56d..81774c73c392c 100644 --- a/src/test/run-pass/lang-item-public.rs +++ b/src/test/run-pass/lang-item-public.rs @@ -13,6 +13,7 @@ // ignore-windows #13361 #![no_std] +#![feature(lang_items)] extern crate "lang-item-public" as lang_lib; diff --git a/src/test/run-pass/match-arm-statics.rs b/src/test/run-pass/match-arm-statics.rs index 85fa61266a338..400aab64b4cdb 100644 --- a/src/test/run-pass/match-arm-statics.rs +++ b/src/test/run-pass/match-arm-statics.rs @@ -38,6 +38,8 @@ const VARIANT2_NORTH: EnumWithStructVariants = EnumWithStructVariants::Variant2 pub mod glfw { pub struct InputState(uint); + impl Copy for InputState {} + pub const RELEASE : InputState = InputState(0); pub const PRESS : InputState = InputState(1); pub const REPEAT : InputState = InputState(2); diff --git a/src/test/run-pass/method-self-arg-trait.rs b/src/test/run-pass/method-self-arg-trait.rs index b821c064cacfe..36dfe83a9ebae 100644 --- a/src/test/run-pass/method-self-arg-trait.rs +++ b/src/test/run-pass/method-self-arg-trait.rs @@ -14,6 +14,8 @@ static mut COUNT: u64 = 1; struct Foo; +impl Copy for Foo {} + trait Bar { fn foo1(&self); fn foo2(self); diff --git a/src/test/run-pass/method-self-arg.rs b/src/test/run-pass/method-self-arg.rs index 3d73f34f8cfd6..788a25efcf987 100644 --- a/src/test/run-pass/method-self-arg.rs +++ b/src/test/run-pass/method-self-arg.rs @@ -14,6 +14,8 @@ static mut COUNT: uint = 1; struct Foo; +impl Copy for Foo {} + impl Foo { fn foo(self, x: &Foo) { unsafe { COUNT *= 2; } diff --git a/src/test/run-pass/monomorphize-abi-alignment.rs b/src/test/run-pass/monomorphize-abi-alignment.rs index 2233a5c3ea774..f5b51cd423301 100644 --- a/src/test/run-pass/monomorphize-abi-alignment.rs +++ b/src/test/run-pass/monomorphize-abi-alignment.rs @@ -19,12 +19,25 @@ */ struct S { i:u8, t:T } -impl S { fn unwrap(self) -> T { self.t } } + +impl Copy for S {} + +impl S { + fn unwrap(self) -> T { + self.t + } +} + #[deriving(PartialEq, Show)] struct A((u32, u32)); + +impl Copy for A {} + #[deriving(PartialEq, Show)] struct B(u64); +impl Copy for B {} + pub fn main() { static Ca: S = S { i: 0, t: A((13, 104)) }; static Cb: S = S { i: 0, t: B(31337) }; diff --git a/src/test/run-pass/multidispatch1.rs b/src/test/run-pass/multidispatch1.rs index 76c87f5d4c59f..87d188418bdd3 100644 --- a/src/test/run-pass/multidispatch1.rs +++ b/src/test/run-pass/multidispatch1.rs @@ -18,6 +18,8 @@ struct MyType { dummy: uint } +impl Copy for MyType {} + impl MyTrait for MyType { fn get(&self) -> uint { self.dummy } } diff --git a/src/test/run-pass/multidispatch2.rs b/src/test/run-pass/multidispatch2.rs index 13131be93c892..1aa15cc598349 100644 --- a/src/test/run-pass/multidispatch2.rs +++ b/src/test/run-pass/multidispatch2.rs @@ -27,6 +27,8 @@ struct MyType { dummy: uint } +impl Copy for MyType {} + impl MyTrait for MyType { fn get(&self) -> uint { self.dummy } } diff --git a/src/test/run-pass/newtype.rs b/src/test/run-pass/newtype.rs index 0d1103086ae79..093fd6c81cc63 100644 --- a/src/test/run-pass/newtype.rs +++ b/src/test/run-pass/newtype.rs @@ -10,7 +10,14 @@ struct mytype(Mytype); -struct Mytype {compute: fn(mytype) -> int, val: int} +impl Copy for mytype {} + +struct Mytype { + compute: fn(mytype) -> int, + val: int, +} + +impl Copy for Mytype {} fn compute(i: mytype) -> int { let mytype(m) = i; diff --git a/src/test/run-pass/out-pointer-aliasing.rs b/src/test/run-pass/out-pointer-aliasing.rs index 2a44df7a1b566..5f399deb88530 100644 --- a/src/test/run-pass/out-pointer-aliasing.rs +++ b/src/test/run-pass/out-pointer-aliasing.rs @@ -13,6 +13,8 @@ pub struct Foo { _f2: int, } +impl Copy for Foo {} + #[inline(never)] pub fn foo(f: &mut Foo) -> Foo { let ret = *f; diff --git a/src/test/run-pass/overloaded-autoderef-order.rs b/src/test/run-pass/overloaded-autoderef-order.rs index 0a9ac734c26fd..f0daf371ca79e 100644 --- a/src/test/run-pass/overloaded-autoderef-order.rs +++ b/src/test/run-pass/overloaded-autoderef-order.rs @@ -15,6 +15,8 @@ struct DerefWrapper { y: Y } +impl Copy for DerefWrapper {} + impl DerefWrapper { fn get_x(self) -> X { self.x @@ -33,6 +35,8 @@ mod priv_test { pub y: Y } + impl Copy for DerefWrapperHideX {} + impl DerefWrapperHideX { pub fn new(x: X, y: Y) -> DerefWrapperHideX { DerefWrapperHideX { diff --git a/src/test/run-pass/packed-struct-vec.rs b/src/test/run-pass/packed-struct-vec.rs index c20e62351a618..59bb5678b6936 100644 --- a/src/test/run-pass/packed-struct-vec.rs +++ b/src/test/run-pass/packed-struct-vec.rs @@ -19,6 +19,8 @@ struct Foo { baz: u64 } +impl Copy for Foo {} + pub fn main() { let foos = [Foo { bar: 1, baz: 2 }, .. 10]; diff --git a/src/test/run-pass/rec-tup.rs b/src/test/run-pass/rec-tup.rs index 0dc547f1a027e..8adad012ec69b 100644 --- a/src/test/run-pass/rec-tup.rs +++ b/src/test/run-pass/rec-tup.rs @@ -10,6 +10,8 @@ struct Point {x: int, y: int} +impl Copy for Point {} + type rect = (Point, Point); fn fst(r: rect) -> Point { let (fst, _) = r; return fst; } diff --git a/src/test/run-pass/rec.rs b/src/test/run-pass/rec.rs index b9b5cfebb0b56..02fcf1ad0689e 100644 --- a/src/test/run-pass/rec.rs +++ b/src/test/run-pass/rec.rs @@ -13,6 +13,8 @@ struct Rect {x: int, y: int, w: int, h: int} +impl Copy for Rect {} + fn f(r: Rect, x: int, y: int, w: int, h: int) { assert_eq!(r.x, x); assert_eq!(r.y, y); diff --git a/src/test/run-pass/regions-dependent-addr-of.rs b/src/test/run-pass/regions-dependent-addr-of.rs index f074ca9a88921..79f8ca48882cf 100644 --- a/src/test/run-pass/regions-dependent-addr-of.rs +++ b/src/test/run-pass/regions-dependent-addr-of.rs @@ -29,6 +29,8 @@ struct C { f: int } +impl Copy for C {} + fn get_v1(a: &A) -> &int { // Region inferencer must deduce that &v < L2 < L1 let foo = &a.value; // L1 diff --git a/src/test/run-pass/regions-early-bound-used-in-bound-method.rs b/src/test/run-pass/regions-early-bound-used-in-bound-method.rs index c011d11749b60..5b4169a4e8462 100644 --- a/src/test/run-pass/regions-early-bound-used-in-bound-method.rs +++ b/src/test/run-pass/regions-early-bound-used-in-bound-method.rs @@ -19,6 +19,8 @@ struct Box<'a> { t: &'a int } +impl<'a> Copy for Box<'a> {} + impl<'a> GetRef<'a> for Box<'a> { fn get(&self) -> &'a int { self.t diff --git a/src/test/run-pass/regions-early-bound-used-in-bound.rs b/src/test/run-pass/regions-early-bound-used-in-bound.rs index 58de2e0e20e0c..73eb7ca71882c 100644 --- a/src/test/run-pass/regions-early-bound-used-in-bound.rs +++ b/src/test/run-pass/regions-early-bound-used-in-bound.rs @@ -19,6 +19,8 @@ struct Box<'a, T:'a> { t: &'a T } +impl<'a,T:'a> Copy for Box<'a,T> {} + impl<'a,T:Clone> GetRef<'a,T> for Box<'a,T> { fn get(&self) -> &'a T { self.t diff --git a/src/test/run-pass/regions-early-bound-used-in-type-param.rs b/src/test/run-pass/regions-early-bound-used-in-type-param.rs index 708664f33e930..622f820971ffb 100644 --- a/src/test/run-pass/regions-early-bound-used-in-type-param.rs +++ b/src/test/run-pass/regions-early-bound-used-in-type-param.rs @@ -19,6 +19,8 @@ struct Box { t: T } +impl Copy for Box {} + impl Get for Box { fn get(&self) -> T { self.t.clone() diff --git a/src/test/run-pass/regions-mock-tcx.rs b/src/test/run-pass/regions-mock-tcx.rs index e13edae330ae7..e10c12a603729 100644 --- a/src/test/run-pass/regions-mock-tcx.rs +++ b/src/test/run-pass/regions-mock-tcx.rs @@ -32,6 +32,9 @@ enum TypeStructure<'tcx> { TypeInt, TypeFunction(Type<'tcx>, Type<'tcx>), } + +impl<'tcx> Copy for TypeStructure<'tcx> {} + impl<'tcx> PartialEq for TypeStructure<'tcx> { fn eq(&self, other: &TypeStructure<'tcx>) -> bool { match (*self, *other) { @@ -93,6 +96,8 @@ struct NodeId { id: uint } +impl Copy for NodeId {} + type Ast<'ast> = &'ast AstStructure<'ast>; struct AstStructure<'ast> { @@ -100,12 +105,16 @@ struct AstStructure<'ast> { kind: AstKind<'ast> } +impl<'ast> Copy for AstStructure<'ast> {} + enum AstKind<'ast> { ExprInt, ExprVar(uint), ExprLambda(Ast<'ast>), } +impl<'ast> Copy for AstKind<'ast> {} + fn compute_types<'tcx,'ast>(tcx: &mut TypeContext<'tcx,'ast>, ast: Ast<'ast>) -> Type<'tcx> { diff --git a/src/test/run-pass/self-in-mut-slot-immediate-value.rs b/src/test/run-pass/self-in-mut-slot-immediate-value.rs index f2482474073e0..1603f7f9763fb 100644 --- a/src/test/run-pass/self-in-mut-slot-immediate-value.rs +++ b/src/test/run-pass/self-in-mut-slot-immediate-value.rs @@ -15,6 +15,8 @@ struct Value { n: int } +impl Copy for Value {} + impl Value { fn squared(mut self) -> Value { self.n *= self.n; diff --git a/src/test/run-pass/shape_intrinsic_tag_then_rec.rs b/src/test/run-pass/shape_intrinsic_tag_then_rec.rs deleted file mode 100644 index 930364c0e22c8..0000000000000 --- a/src/test/run-pass/shape_intrinsic_tag_then_rec.rs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2012 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. - - -// Exercises a bug in the shape code that was exposed -// on x86_64: when there is an enum embedded in an -// interior record which is then itself interior to -// something else, shape calculations were off. - -#[deriving(Clone, Show)] -enum opt_span { - //hack (as opposed to option), to make `span` compile - os_none, - os_some(Box), -} - -#[deriving(Clone, Show)] -struct Span { - lo: uint, - hi: uint, - expanded_from: opt_span, -} - -#[deriving(Clone, Show)] -struct Spanned { - data: T, - span: Span, -} - -type ty_ = uint; - -#[deriving(Clone, Show)] -struct Path_ { - global: bool, - idents: Vec , - types: Vec>, -} - -type path = Spanned; -type ty = Spanned; - -#[deriving(Clone, Show)] -struct X { - sp: Span, - path: path, -} - -pub fn main() { - let sp: Span = Span {lo: 57451u, hi: 57542u, expanded_from: opt_span::os_none}; - let t: Box = box Spanned { data: 3u, span: sp.clone() }; - let p_: Path_ = Path_ { - global: true, - idents: vec!("hi".to_string()), - types: vec!(t), - }; - let p: path = Spanned { data: p_, span: sp.clone() }; - let x = X { sp: sp, path: p }; - println!("{}", x.path.clone()); - println!("{}", x.clone()); -} diff --git a/src/test/run-pass/simd-generics.rs b/src/test/run-pass/simd-generics.rs index 68c210b018ab9..31c29b615fc09 100644 --- a/src/test/run-pass/simd-generics.rs +++ b/src/test/run-pass/simd-generics.rs @@ -15,6 +15,8 @@ use std::ops; #[simd] struct f32x4(f32, f32, f32, f32); +impl Copy for f32x4 {} + fn add>(lhs: T, rhs: T) -> T { lhs + rhs } diff --git a/src/test/run-pass/small-enum-range-edge.rs b/src/test/run-pass/small-enum-range-edge.rs index 17d647e58b5e2..de38a553e123f 100644 --- a/src/test/run-pass/small-enum-range-edge.rs +++ b/src/test/run-pass/small-enum-range-edge.rs @@ -14,11 +14,17 @@ #[repr(u8)] enum Eu { Lu = 0, Hu = 255 } + +impl Copy for Eu {} + static CLu: Eu = Eu::Lu; static CHu: Eu = Eu::Hu; #[repr(i8)] enum Es { Ls = -128, Hs = 127 } + +impl Copy for Es {} + static CLs: Es = Es::Ls; static CHs: Es = Es::Hs; diff --git a/src/test/run-pass/struct-return.rs b/src/test/run-pass/struct-return.rs index 63574316fe573..bb06aec23f6bc 100644 --- a/src/test/run-pass/struct-return.rs +++ b/src/test/run-pass/struct-return.rs @@ -11,8 +11,13 @@ // ignore-lexer-test FIXME #15883 pub struct Quad { a: u64, b: u64, c: u64, d: u64 } + +impl Copy for Quad {} + pub struct Floats { a: f64, b: u8, c: f64 } +impl Copy for Floats {} + mod rustrt { use super::{Floats, Quad}; diff --git a/src/test/run-pass/structured-compare.rs b/src/test/run-pass/structured-compare.rs index 88f72932ca057..d0446d83d2e01 100644 --- a/src/test/run-pass/structured-compare.rs +++ b/src/test/run-pass/structured-compare.rs @@ -13,6 +13,8 @@ #[deriving(Show)] enum foo { large, small, } +impl Copy for foo {} + impl PartialEq for foo { fn eq(&self, other: &foo) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/tag-variant-disr-val.rs b/src/test/run-pass/tag-variant-disr-val.rs index 7aa2ba280acaf..cf53c1a912a54 100644 --- a/src/test/run-pass/tag-variant-disr-val.rs +++ b/src/test/run-pass/tag-variant-disr-val.rs @@ -20,6 +20,8 @@ enum color { orange = 8 >> 1 } +impl Copy for color {} + impl PartialEq for color { fn eq(&self, other: &color) -> bool { ((*self) as uint) == ((*other) as uint) diff --git a/src/test/run-pass/trait-coercion-generic.rs b/src/test/run-pass/trait-coercion-generic.rs index 1e241ad22784e..7d924f977cbef 100644 --- a/src/test/run-pass/trait-coercion-generic.rs +++ b/src/test/run-pass/trait-coercion-generic.rs @@ -18,6 +18,8 @@ struct Struct { y: int, } +impl Copy for Struct {} + impl Trait<&'static str> for Struct { fn f(&self, x: &'static str) { println!("Hi, {}!", x); diff --git a/src/test/run-pass/trait-coercion.rs b/src/test/run-pass/trait-coercion.rs index 55beebbf2bc57..37d69ddfe0766 100644 --- a/src/test/run-pass/trait-coercion.rs +++ b/src/test/run-pass/trait-coercion.rs @@ -19,6 +19,8 @@ struct Struct { y: int, } +impl Copy for Struct {} + impl Trait for Struct { fn f(&self) { println!("Hi!"); diff --git a/src/test/run-pass/typeclasses-eq-example-static.rs b/src/test/run-pass/typeclasses-eq-example-static.rs index a5547c0eea98b..6b00a8b5c2d9f 100644 --- a/src/test/run-pass/typeclasses-eq-example-static.rs +++ b/src/test/run-pass/typeclasses-eq-example-static.rs @@ -18,8 +18,11 @@ trait Equal { fn isEq(a: &Self, b: &Self) -> bool; } +#[deriving(Clone)] enum Color { cyan, magenta, yellow, black } +impl Copy for Color {} + impl Equal for Color { fn isEq(a: &Color, b: &Color) -> bool { match (*a, *b) { @@ -32,6 +35,7 @@ impl Equal for Color { } } +#[deriving(Clone)] enum ColorTree { leaf(Color), branch(Box, Box) @@ -40,9 +44,12 @@ enum ColorTree { impl Equal for ColorTree { fn isEq(a: &ColorTree, b: &ColorTree) -> bool { match (a, b) { - (&leaf(x), &leaf(y)) => { Equal::isEq(&x, &y) } + (&leaf(ref x), &leaf(ref y)) => { + Equal::isEq(&(*x).clone(), &(*y).clone()) + } (&branch(ref l1, ref r1), &branch(ref l2, ref r2)) => { - Equal::isEq(&**l1, &**l2) && Equal::isEq(&**r1, &**r2) + Equal::isEq(&(**l1).clone(), &(**l2).clone()) && + Equal::isEq(&(**r1).clone(), &(**r2).clone()) } _ => { false } } diff --git a/src/test/run-pass/typeclasses-eq-example.rs b/src/test/run-pass/typeclasses-eq-example.rs index 21b9c774e8c43..e4b7d2eb60bd3 100644 --- a/src/test/run-pass/typeclasses-eq-example.rs +++ b/src/test/run-pass/typeclasses-eq-example.rs @@ -17,8 +17,11 @@ trait Equal { fn isEq(&self, a: &Self) -> bool; } +#[deriving(Clone)] enum Color { cyan, magenta, yellow, black } +impl Copy for Color {} + impl Equal for Color { fn isEq(&self, a: &Color) -> bool { match (*self, *a) { @@ -31,6 +34,7 @@ impl Equal for Color { } } +#[deriving(Clone)] enum ColorTree { leaf(Color), branch(Box, Box) @@ -39,9 +43,9 @@ enum ColorTree { impl Equal for ColorTree { fn isEq(&self, a: &ColorTree) -> bool { match (self, a) { - (&leaf(x), &leaf(y)) => { x.isEq(&y) } + (&leaf(ref x), &leaf(ref y)) => { x.isEq(&(*y).clone()) } (&branch(ref l1, ref r1), &branch(ref l2, ref r2)) => { - (&**l1).isEq(&**l2) && (&**r1).isEq(&**r2) + (*l1).isEq(&(**l2).clone()) && (*r1).isEq(&(**r2).clone()) } _ => { false } } diff --git a/src/test/run-pass/ufcs-explicit-self.rs b/src/test/run-pass/ufcs-explicit-self.rs index b96820eee14b7..b6b9fb67f9053 100644 --- a/src/test/run-pass/ufcs-explicit-self.rs +++ b/src/test/run-pass/ufcs-explicit-self.rs @@ -12,6 +12,8 @@ struct Foo { f: int, } +impl Copy for Foo {} + impl Foo { fn foo(self: Foo, x: int) -> int { self.f + x @@ -28,6 +30,8 @@ struct Bar { f: T, } +impl Copy for Bar {} + impl Bar { fn foo(self: Bar, x: int) -> int { x diff --git a/src/test/run-pass/unboxed-closures-monomorphization.rs b/src/test/run-pass/unboxed-closures-monomorphization.rs index 43fb4b296ccb9..cd97fd96fa3bb 100644 --- a/src/test/run-pass/unboxed-closures-monomorphization.rs +++ b/src/test/run-pass/unboxed-closures-monomorphization.rs @@ -30,6 +30,9 @@ fn main(){ #[deriving(Show, PartialEq)] struct Foo(uint, &'static str); + + impl Copy for Foo {} + let x = Foo(42, "forty-two"); let f = bar(x); assert_eq!(f.call_once(()), x);