]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/dst-bad-assign.rs
Update compile fail tests to use isize.
[rust.git] / src / test / compile-fail / dst-bad-assign.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Forbid assignment into a dynamically sized type.
12
13 #![feature(box_syntax)]
14
15 struct Fat<T: ?Sized> {
16     f1: isize,
17     f2: &'static str,
18     ptr: T
19 }
20
21 #[derive(PartialEq,Eq)]
22 struct Bar;
23
24 #[derive(PartialEq,Eq)]
25 struct Bar1 {
26     f: isize
27 }
28
29 trait ToBar {
30     fn to_bar(&self) -> Bar;
31     fn to_val(&self) -> isize;
32 }
33
34 impl ToBar for Bar1 {
35     fn to_bar(&self) -> Bar {
36         Bar
37     }
38     fn to_val(&self) -> isize {
39         self.f
40     }
41 }
42
43 pub fn main() {
44     // Assignment.
45     let f5: &mut Fat<ToBar> = &mut Fat { f1: 5, f2: "some str", ptr: Bar1 {f :42} };
46     let z: Box<ToBar> = box Bar1 {f: 36};
47     f5.ptr = Bar1 {f: 36}; //~ ERROR mismatched types: expected `ToBar`, found `Bar1`
48     //~^ ERROR the trait `core::marker::Sized` is not implemented for the type `ToBar`
49 }