]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dst/dst-bad-assign-3.rs
Rollup merge of #100479 - compiler-errors:argument-type-error-improvements, r=lcnr
[rust.git] / src / test / ui / dst / dst-bad-assign-3.rs
1 // Forbid assignment into a dynamically sized type.
2
3 #![feature(unsized_tuple_coercion)]
4
5 type Fat<T> = (isize, &'static str, T);
6
7 #[derive(PartialEq,Eq)]
8 struct Bar;
9
10 #[derive(PartialEq,Eq)]
11 struct Bar1 {
12     f: isize
13 }
14
15 trait ToBar {
16     fn to_bar(&self) -> Bar;
17     fn to_val(&self) -> isize;
18 }
19
20 impl ToBar for Bar1 {
21     fn to_bar(&self) -> Bar {
22         Bar
23     }
24     fn to_val(&self) -> isize {
25         self.f
26     }
27 }
28
29 pub fn main() {
30     // Assignment.
31     let f5: &mut Fat<dyn ToBar> = &mut (5, "some str", Bar1 {f :42});
32     let z: Box<dyn ToBar> = Box::new(Bar1 {f: 36});
33     f5.2 = Bar1 {f: 36};
34     //~^ ERROR mismatched types
35     //~| expected trait object `dyn ToBar`, found struct `Bar1`
36     //~| expected trait object `dyn ToBar`
37     //~| found struct `Bar1`
38     //~| ERROR the size for values of type
39 }