]> git.proxmox.com Git - rustc.git/blame - src/test/codegen-units/item-collection/unsizing.rs
New upstream version 1.28.0~beta.14+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
94b46f34 12// compile-flags:-Zprint-mono-items=eager
ea8adc8c 13// compile-flags:-Zinline-in-all-cgus
7453a54e
SL
14
15#![deny(dead_code)]
16#![feature(coerce_unsized)]
17#![feature(unsize)]
ff7c6d11 18#![feature(start)]
7453a54e
SL
19
20use std::marker::Unsize;
21use std::ops::CoerceUnsized;
22
23trait Trait {
24 fn foo(&self);
25}
26
27// Simple Case
28impl Trait for bool {
29 fn foo(&self) {}
30}
31
32impl Trait for char {
33 fn foo(&self) {}
34}
35
36// Struct Field Case
37struct Struct<T: ?Sized> {
38 _a: u32,
39 _b: i32,
40 _c: T
41}
42
43impl Trait for f64 {
44 fn foo(&self) {}
45}
46
47// Custom Coercion Case
48impl Trait for u32 {
49 fn foo(&self) {}
50}
51
52#[derive(Clone, Copy)]
53struct Wrapper<T: ?Sized>(*const T);
54
55impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Wrapper<U>> for Wrapper<T> {}
56
94b46f34 57//~ MONO_ITEM fn unsizing::start[0]
ff7c6d11
XL
58#[start]
59fn start(_: isize, _: *const *const u8) -> isize {
7453a54e
SL
60 // simple case
61 let bool_sized = &true;
94b46f34
XL
62 //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<bool> @@ unsizing0[Internal]
63 //~ MONO_ITEM fn unsizing::{{impl}}[0]::foo[0]
7453a54e
SL
64 let _bool_unsized = bool_sized as &Trait;
65
cc61c64b
XL
66 let char_sized = &'a';
67
94b46f34
XL
68 //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<char> @@ unsizing0[Internal]
69 //~ MONO_ITEM fn unsizing::{{impl}}[1]::foo[0]
7453a54e
SL
70 let _char_unsized = char_sized as &Trait;
71
72 // struct field
73 let struct_sized = &Struct {
74 _a: 1,
75 _b: 2,
76 _c: 3.0f64
77 };
94b46f34
XL
78 //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<f64> @@ unsizing0[Internal]
79 //~ MONO_ITEM fn unsizing::{{impl}}[2]::foo[0]
7453a54e
SL
80 let _struct_unsized = struct_sized as &Struct<Trait>;
81
82 // custom coercion
83 let wrapper_sized = Wrapper(&0u32);
94b46f34
XL
84 //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<u32> @@ unsizing0[Internal]
85 //~ MONO_ITEM fn unsizing::{{impl}}[3]::foo[0]
7453a54e 86 let _wrapper_sized = wrapper_sized as Wrapper<Trait>;
ff7c6d11
XL
87
88 0
7453a54e 89}