2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2018-08-31 13:02:01 +00:00
|
|
|
#![allow(non_camel_case_types)]
|
|
|
|
|
2013-07-10 21:43:25 +00:00
|
|
|
trait clam<A> {
|
2013-03-13 02:32:14 +00:00
|
|
|
fn chowder(&self, y: A);
|
2012-07-13 21:44:48 +00:00
|
|
|
}
|
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.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
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]
2014-12-06 01:01:33 +00:00
|
|
|
|
2015-03-30 13:38:27 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2013-01-28 18:46:43 +00:00
|
|
|
struct foo<A> {
|
2012-09-07 02:40:15 +00:00
|
|
|
x: A,
|
2012-09-08 02:04:40 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 21:43:25 +00:00
|
|
|
impl<A> clam<A> for foo<A> {
|
2013-08-17 15:37:42 +00:00
|
|
|
fn chowder(&self, _y: A) {
|
2012-07-13 21:44:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 21:43:25 +00:00
|
|
|
fn foo<A>(b: A) -> foo<A> {
|
2012-09-05 22:58:43 +00:00
|
|
|
foo {
|
|
|
|
x: b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 18:47:21 +00:00
|
|
|
fn f<A>(x: Box<dyn clam<A>>, a: A) {
|
2012-07-13 21:44:48 +00:00
|
|
|
x.chowder(a);
|
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2012-07-13 21:44:48 +00:00
|
|
|
|
|
|
|
let c = foo(42);
|
2022-07-07 02:36:10 +00:00
|
|
|
let d: Box<dyn clam<isize>> = Box::new(c) as Box<dyn clam<isize>>;
|
2012-07-13 21:44:48 +00:00
|
|
|
f(d, c.x);
|
|
|
|
}
|