]> git.lizzy.rs Git - rust.git/blob - src/test/codegen-units/overloaded-operators.rs
fallout: update codegen-units tests
[rust.git] / src / test / codegen-units / overloaded-operators.rs
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 #![crate_type="lib"]
16
17 use std::ops::{Index, IndexMut, Add, Deref};
18
19 pub struct Indexable {
20     data: [u8; 3]
21 }
22
23 impl Index<usize> for Indexable {
24     type Output = u8;
25
26     //~ TRANS_ITEM fn overloaded_operators::{{impl}}[0]::index[0]
27     fn index(&self, index: usize) -> &Self::Output {
28         if index >= 3 {
29             &self.data[0]
30         } else {
31             &self.data[index]
32         }
33     }
34 }
35
36 impl IndexMut<usize> for Indexable {
37     //~ TRANS_ITEM fn overloaded_operators::{{impl}}[1]::index_mut[0]
38     fn index_mut(&mut self, index: usize) -> &mut Self::Output {
39         if index >= 3 {
40             &mut self.data[0]
41         } else {
42             &mut self.data[index]
43         }
44     }
45 }
46
47
48 //~ TRANS_ITEM fn overloaded_operators::{{impl}}[2]::eq[0]
49 //~ TRANS_ITEM fn overloaded_operators::{{impl}}[2]::ne[0]
50 #[derive(PartialEq)]
51 pub struct Equatable(u32);
52
53
54 impl Add<u32> for Equatable {
55     type Output = u32;
56
57     //~ TRANS_ITEM fn overloaded_operators::{{impl}}[3]::add[0]
58     fn add(self, rhs: u32) -> u32 {
59         self.0 + rhs
60     }
61 }
62
63 impl Deref for Equatable {
64     type Target = u32;
65
66     //~ TRANS_ITEM fn overloaded_operators::{{impl}}[4]::deref[0]
67     fn deref(&self) -> &Self::Target {
68         &self.0
69     }
70 }
71
72 //~ TRANS_ITEM drop-glue i8