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