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