]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/dst-bad-assign.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / dst-bad-assign.rs
CommitLineData
1a4d82fc
JJ
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
1a4d82fc
JJ
13struct Fat<T: ?Sized> {
14 f1: isize,
15 f2: &'static str,
16 ptr: T
17}
18
19#[derive(PartialEq,Eq)]
20struct Bar;
21
22#[derive(PartialEq,Eq)]
23struct Bar1 {
24 f: isize
25}
26
27trait ToBar {
28 fn to_bar(&self) -> Bar;
29 fn to_val(&self) -> isize;
30}
31
32impl ToBar for Bar1 {
33 fn to_bar(&self) -> Bar {
34 Bar
35 }
36 fn to_val(&self) -> isize {
37 self.f
38 }
39}
40
41pub fn main() {
42 // Assignment.
43 let f5: &mut Fat<ToBar> = &mut Fat { f1: 5, f2: "some str", ptr: Bar1 {f :42} };
c34b1796
AL
44 // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
45 let z: Box<ToBar> = Box::new(Bar1 {f: 36});
85aaf69f
SL
46 f5.ptr = Bar1 {f: 36};
47 //~^ ERROR mismatched types
48 //~| expected `ToBar`
49 //~| found `Bar1`
50 //~| expected trait ToBar
51 //~| found struct `Bar1`
54a0048b 52 //~| ERROR `ToBar: std::marker::Sized` is not satisfied
1a4d82fc 53}