2014-09-01 23:25:01 +00:00
|
|
|
// Test implicit coercions involving DSTs and raw pointers.
|
|
|
|
|
2014-08-27 05:07:28 +00:00
|
|
|
struct S;
|
2015-04-18 05:12:20 +00:00
|
|
|
trait T {}
|
2014-08-27 05:07:28 +00:00
|
|
|
impl T for S {}
|
|
|
|
|
2015-01-05 21:16:49 +00:00
|
|
|
struct Foo<T: ?Sized> {
|
2014-09-01 23:25:01 +00:00
|
|
|
f: T
|
|
|
|
}
|
|
|
|
|
2014-08-27 05:07:28 +00:00
|
|
|
pub fn main() {
|
2016-08-12 04:47:56 +00:00
|
|
|
// Test that we cannot convert from *-ptr to &S and &T
|
2014-08-27 05:07:28 +00:00
|
|
|
let x: *const S = &S;
|
2014-09-01 23:25:01 +00:00
|
|
|
let y: &S = x; //~ ERROR mismatched types
|
2019-05-28 18:46:13 +00:00
|
|
|
let y: &dyn T = x; //~ ERROR mismatched types
|
2014-08-27 05:07:28 +00:00
|
|
|
|
2016-08-12 04:47:56 +00:00
|
|
|
// Test that we cannot convert from *-ptr to &S and &T (mut version)
|
2014-08-27 05:07:28 +00:00
|
|
|
let x: *mut S = &mut S;
|
2014-09-01 23:25:01 +00:00
|
|
|
let y: &S = x; //~ ERROR mismatched types
|
2019-05-28 18:46:13 +00:00
|
|
|
let y: &dyn T = x; //~ ERROR mismatched types
|
2014-08-27 05:07:28 +00:00
|
|
|
|
2014-09-01 23:25:01 +00:00
|
|
|
// Test that we cannot convert an immutable ptr to a mutable one using *-ptrs
|
2019-05-28 18:46:13 +00:00
|
|
|
let x: &mut dyn T = &S; //~ ERROR mismatched types
|
|
|
|
let x: *mut dyn T = &S; //~ ERROR mismatched types
|
2014-09-12 14:45:39 +00:00
|
|
|
let x: *mut S = &S; //~ ERROR mismatched types
|
2014-09-01 23:25:01 +00:00
|
|
|
}
|