]> git.proxmox.com Git - rustc.git/blame - src/test/codegen-units/overloaded-operators.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / codegen-units / overloaded-operators.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#![crate_type="lib"]
16
17use std::ops::{Index, IndexMut, Add, Deref};
18
19pub struct Indexable {
20 data: [u8; 3]
21}
22
23impl Index<usize> for Indexable {
24 type Output = u8;
25
54a0048b 26 //~ TRANS_ITEM fn overloaded_operators::{{impl}}[0]::index[0]
7453a54e
SL
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
36impl IndexMut<usize> for Indexable {
54a0048b 37 //~ TRANS_ITEM fn overloaded_operators::{{impl}}[1]::index_mut[0]
7453a54e
SL
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
54a0048b
SL
48//~ TRANS_ITEM fn overloaded_operators::{{impl}}[2]::eq[0]
49//~ TRANS_ITEM fn overloaded_operators::{{impl}}[2]::ne[0]
7453a54e
SL
50#[derive(PartialEq)]
51pub struct Equatable(u32);
52
53
54impl Add<u32> for Equatable {
55 type Output = u32;
56
54a0048b 57 //~ TRANS_ITEM fn overloaded_operators::{{impl}}[3]::add[0]
7453a54e
SL
58 fn add(self, rhs: u32) -> u32 {
59 self.0 + rhs
60 }
61}
62
63impl Deref for Equatable {
64 type Target = u32;
65
54a0048b 66 //~ TRANS_ITEM fn overloaded_operators::{{impl}}[4]::deref[0]
7453a54e
SL
67 fn deref(&self) -> &Self::Target {
68 &self.0
69 }
70}
71
72//~ TRANS_ITEM drop-glue i8