]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/dst-bad-assign-3.rs
Optimized error reporting for recursive requirements #47720
[rust.git] / src / test / compile-fail / dst-bad-assign-3.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(unsized_tuple_coercion)]
14
15 type Fat<T: ?Sized> = (isize, &'static str, T);
16 //~^ WARNING trait bounds are not (yet) enforced
17
18 #[derive(PartialEq,Eq)]
19 struct Bar;
20
21 #[derive(PartialEq,Eq)]
22 struct Bar1 {
23     f: isize
24 }
25
26 trait ToBar {
27     fn to_bar(&self) -> Bar;
28     fn to_val(&self) -> isize;
29 }
30
31 impl ToBar for Bar1 {
32     fn to_bar(&self) -> Bar {
33         Bar
34     }
35     fn to_val(&self) -> isize {
36         self.f
37     }
38 }
39
40 pub fn main() {
41     // Assignment.
42     let f5: &mut Fat<ToBar> = &mut (5, "some str", Bar1 {f :42});
43     let z: Box<ToBar> = Box::new(Bar1 {f: 36});
44     f5.2 = Bar1 {f: 36};
45     //~^ ERROR mismatched types
46     //~| expected type `ToBar`
47     //~| found type `Bar1`
48     //~| expected trait ToBar, found struct `Bar1`
49     //~| ERROR `ToBar: std::marker::Sized` is not satisfied
50 }