]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dst/dst-bad-coercions.rs
Rollup merge of #100479 - compiler-errors:argument-type-error-improvements, r=lcnr
[rust.git] / src / test / ui / dst / dst-bad-coercions.rs
1 // Test implicit coercions involving DSTs and raw pointers.
2
3 struct S;
4 trait T {}
5 impl T for S {}
6
7 struct Foo<T: ?Sized> {
8     f: T
9 }
10
11 pub fn main() {
12     // Test that we cannot convert from *-ptr to &S and &T
13     let x: *const S = &S;
14     let y: &S = x; //~ ERROR mismatched types
15     let y: &dyn T = x; //~ ERROR mismatched types
16
17     // Test that we cannot convert from *-ptr to &S and &T (mut version)
18     let x: *mut S = &mut S;
19     let y: &S = x; //~ ERROR mismatched types
20     let y: &dyn T = x; //~ ERROR mismatched types
21
22     // Test that we cannot convert an immutable ptr to a mutable one using *-ptrs
23     let x: &mut dyn T = &S; //~ ERROR mismatched types
24     let x: *mut dyn T = &S; //~ ERROR mismatched types
25     let x: *mut S = &S; //~ ERROR mismatched types
26 }