2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(unused_variables)]
|
2014-09-01 23:25:01 +00:00
|
|
|
// Test coercions involving DST and/or raw pointers
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
//@ pretty-expanded FIXME #23616
|
|
|
|
|
2014-08-27 05:07:28 +00:00
|
|
|
struct S;
|
2024-02-07 02:42:01 +00:00
|
|
|
trait T { fn dummy(&self) { } } //~ WARN method `dummy` is never used
|
2014-08-27 05:07:28 +00:00
|
|
|
impl T for S {}
|
|
|
|
|
|
|
|
pub fn main() {
|
2019-05-28 18:47:21 +00:00
|
|
|
let x: &dyn T = &S;
|
2014-09-01 23:25:01 +00:00
|
|
|
// Test we can convert from &-ptr to *-ptr of trait objects
|
2019-05-28 18:47:21 +00:00
|
|
|
let x: *const dyn T = &S;
|
2014-08-27 05:07:28 +00:00
|
|
|
|
2014-09-01 23:25:01 +00:00
|
|
|
// Test we can convert from &-ptr to *-ptr of struct pointer (not DST)
|
2014-08-27 05:07:28 +00:00
|
|
|
let x: *const S = &S;
|
|
|
|
|
2014-09-01 23:25:01 +00:00
|
|
|
// As above, but mut
|
2019-05-28 18:47:21 +00:00
|
|
|
let x: &mut dyn T = &mut S;
|
|
|
|
let x: *mut dyn T = &mut S;
|
2014-08-27 05:07:28 +00:00
|
|
|
|
|
|
|
let x: *mut S = &mut S;
|
|
|
|
|
2014-10-26 03:10:16 +00:00
|
|
|
// Test we can change the mutability from mut to const.
|
2019-05-28 18:47:21 +00:00
|
|
|
let x: &dyn T = &mut S;
|
|
|
|
let x: *const dyn T = &mut S;
|
2014-09-01 23:25:01 +00:00
|
|
|
}
|