rust/tests/ui/dynamically-sized-types/dst-coercions.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
705 B
Rust
Raw Normal View History

//@ run-pass
#![allow(unused_variables)]
2014-09-01 23:25:01 +00:00
// Test coercions involving DST and/or raw pointers
//@ pretty-expanded FIXME #23616
struct S;
2024-02-07 02:42:01 +00:00
trait T { fn dummy(&self) { } } //~ WARN method `dummy` is never used
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-09-01 23:25:01 +00:00
// Test we can convert from &-ptr to *-ptr of struct pointer (not DST)
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;
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
}