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