]> git.proxmox.com Git - rustc.git/blame - src/test/codegen-units/item-collection/unsizing.rs
New upstream version 1.13.0+dfsg1
[rustc.git] / src / test / codegen-units / item-collection / unsizing.rs
CommitLineData
7453a54e
SL
1// Copyright 2012-2015 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// ignore-tidy-linelength
12// compile-flags:-Zprint-trans-items=eager
13
14#![deny(dead_code)]
15#![feature(coerce_unsized)]
16#![feature(unsize)]
17
18use std::marker::Unsize;
19use std::ops::CoerceUnsized;
20
21trait Trait {
22 fn foo(&self);
23}
24
25// Simple Case
26impl Trait for bool {
27 fn foo(&self) {}
28}
29
30impl Trait for char {
31 fn foo(&self) {}
32}
33
34// Struct Field Case
35struct Struct<T: ?Sized> {
36 _a: u32,
37 _b: i32,
38 _c: T
39}
40
41impl Trait for f64 {
42 fn foo(&self) {}
43}
44
45// Custom Coercion Case
46impl Trait for u32 {
47 fn foo(&self) {}
48}
49
50#[derive(Clone, Copy)]
51struct Wrapper<T: ?Sized>(*const T);
52
53impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Wrapper<U>> for Wrapper<T> {}
54
55//~ TRANS_ITEM fn unsizing::main[0]
56fn main()
57{
58 // simple case
59 let bool_sized = &true;
9e0c209e 60 //~ TRANS_ITEM drop-glue i8
54a0048b 61 //~ TRANS_ITEM fn unsizing::{{impl}}[0]::foo[0]
7453a54e
SL
62 let _bool_unsized = bool_sized as &Trait;
63
64 let char_sized = &true;
54a0048b 65 //~ TRANS_ITEM fn unsizing::{{impl}}[1]::foo[0]
7453a54e
SL
66 let _char_unsized = char_sized as &Trait;
67
68 // struct field
69 let struct_sized = &Struct {
70 _a: 1,
71 _b: 2,
72 _c: 3.0f64
73 };
54a0048b 74 //~ TRANS_ITEM fn unsizing::{{impl}}[2]::foo[0]
7453a54e
SL
75 let _struct_unsized = struct_sized as &Struct<Trait>;
76
77 // custom coercion
78 let wrapper_sized = Wrapper(&0u32);
54a0048b 79 //~ TRANS_ITEM fn unsizing::{{impl}}[3]::foo[0]
7453a54e
SL
80 let _wrapper_sized = wrapper_sized as Wrapper<Trait>;
81}