]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dst/dst-bad-coerce2.rs
Auto merge of #75936 - sdroege:chunks-exact-construction-bounds-check, r=nagisa
[rust.git] / src / test / ui / dst / dst-bad-coerce2.rs
1 // Attempt to change the mutability as well as unsizing.
2
3 struct Fat<T: ?Sized> {
4     ptr: T
5 }
6
7 struct Foo;
8 trait Bar {}
9 impl Bar for Foo {}
10
11 pub fn main() {
12     // With a vec of ints.
13     let f1 = Fat { ptr: [1, 2, 3] };
14     let f2: &Fat<[isize; 3]> = &f1;
15     let f3: &mut Fat<[isize]> = f2; //~ ERROR mismatched types
16
17     // With a trait.
18     let f1 = Fat { ptr: Foo };
19     let f2: &Fat<Foo> = &f1;
20     let f3: &mut Fat<dyn Bar> = f2; //~ ERROR mismatched types
21
22     // Tuple with a vec of ints.
23     let f1 = ([1, 2, 3],);
24     let f2: &([isize; 3],) = &f1;
25     let f3: &mut ([isize],) = f2; //~ ERROR mismatched types
26
27     // Tuple with a trait.
28     let f1 = (Foo,);
29     let f2: &(Foo,) = &f1;
30     let f3: &mut (dyn Bar,) = f2; //~ ERROR mismatched types
31 }