2014-11-01 08:56:09 +00:00
|
|
|
// Test that overloaded index expressions with DST result types
|
|
|
|
// can't be used as rvalues
|
|
|
|
|
|
|
|
use std::ops::Index;
|
2015-01-20 23:45:07 +00:00
|
|
|
use std::fmt::Debug;
|
2014-11-01 08:56:09 +00:00
|
|
|
|
2015-03-30 13:38:27 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2014-11-01 08:56:09 +00:00
|
|
|
struct S;
|
|
|
|
|
2015-01-08 11:02:42 +00:00
|
|
|
impl Index<usize> for S {
|
2015-01-03 15:40:36 +00:00
|
|
|
type Output = str;
|
|
|
|
|
2015-03-22 01:15:47 +00:00
|
|
|
fn index(&self, _: usize) -> &str {
|
2014-11-01 08:56:09 +00:00
|
|
|
"hello"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-30 13:38:27 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2014-11-01 08:56:09 +00:00
|
|
|
struct T;
|
|
|
|
|
2015-01-08 11:02:42 +00:00
|
|
|
impl Index<usize> for T {
|
2019-05-28 18:46:13 +00:00
|
|
|
type Output = dyn Debug + 'static;
|
2015-01-03 15:40:36 +00:00
|
|
|
|
2019-05-28 18:46:13 +00:00
|
|
|
fn index<'a>(&'a self, idx: usize) -> &'a (dyn Debug + 'static) {
|
2015-01-08 11:02:42 +00:00
|
|
|
static x: usize = 42;
|
2014-11-01 08:56:09 +00:00
|
|
|
&x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
S[0];
|
2019-05-05 11:02:32 +00:00
|
|
|
//~^ ERROR cannot move out of index of `S`
|
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
|
|
|
//~^^ ERROR E0161
|
2014-11-01 08:56:09 +00:00
|
|
|
T[0];
|
2019-05-05 11:02:32 +00:00
|
|
|
//~^ ERROR cannot move out of index of `T`
|
2014-11-01 08:56:09 +00:00
|
|
|
//~^^ ERROR E0161
|
|
|
|
}
|