rust/tests/ui/dst/dst-bad-coercions.rs

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

27 lines
776 B
Rust
Raw Normal View History

2014-09-01 18:25:01 -05:00
// Test implicit coercions involving DSTs and raw pointers.
struct S;
2015-04-18 00:12:20 -05:00
trait T {}
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
}
pub fn main() {
2016-08-11 23:47:56 -05:00
// Test that we cannot convert from *-ptr to &S and &T
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
2016-08-11 23:47:56 -05:00
// Test that we cannot convert from *-ptr to &S and &T (mut version)
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-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
let x: *mut S = &S; //~ ERROR mismatched types
2014-09-01 18:25:01 -05:00
}