]> git.lizzy.rs Git - rust.git/blob - src/test/ui/structs/struct-base-wrong-type.rs
Rollup merge of #57107 - mjbshaw:thread_local_test, r=nikomatsakis
[rust.git] / src / test / ui / structs / struct-base-wrong-type.rs
1 // Check that `base` in `Fru { field: expr, ..base }` must have right type.
2 //
3 // See also struct-base-wrong-type-2.rs, which tests same condition
4 // within a function body.
5
6 struct Foo { a: isize, b: isize }
7 struct Bar { x: isize }
8
9 static bar: Bar = Bar { x: 5 };
10 static foo: Foo = Foo { a: 2, ..bar }; //~  ERROR mismatched types
11                                        //~| expected type `Foo`
12                                        //~| found type `Bar`
13                                        //~| expected struct `Foo`, found struct `Bar`
14 static foo_i: Foo = Foo { a: 2, ..4 }; //~  ERROR mismatched types
15                                        //~| expected type `Foo`
16                                        //~| found type `{integer}`
17                                        //~| expected struct `Foo`, found integer
18
19 fn main() {
20     let b = Bar { x: 5 };
21     // errors below are no longer caught since error above causes
22     // compilation to abort before we bother checking function bodies.
23     // See also struct-base-wrong-type-2.rs, which checks that we
24     // would catch these errors eventually.
25     let f = Foo { a: 2, ..b };
26     let f__isize = Foo { a: 2, ..4 };
27 }