]> git.proxmox.com Git - rustc.git/blob - tests/codegen-units/item-collection/overloaded-operators.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / codegen-units / item-collection / overloaded-operators.rs
1 // compile-flags:-Zprint-mono-items=eager
2
3 #![deny(dead_code)]
4 #![crate_type="lib"]
5
6 use std::ops::{Index, IndexMut, Add, Deref};
7
8 pub struct Indexable {
9 data: [u8; 3]
10 }
11
12 impl Index<usize> for Indexable {
13 type Output = u8;
14
15 //~ MONO_ITEM fn <Indexable as std::ops::Index<usize>>::index
16 fn index(&self, index: usize) -> &Self::Output {
17 if index >= 3 {
18 &self.data[0]
19 } else {
20 &self.data[index]
21 }
22 }
23 }
24
25 impl IndexMut<usize> for Indexable {
26 //~ MONO_ITEM fn <Indexable as std::ops::IndexMut<usize>>::index_mut
27 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
28 if index >= 3 {
29 &mut self.data[0]
30 } else {
31 &mut self.data[index]
32 }
33 }
34 }
35
36
37 //~ MONO_ITEM fn <Equatable as std::cmp::PartialEq>::eq
38 //~ MONO_ITEM fn <Equatable as std::cmp::PartialEq>::ne
39 #[derive(PartialEq)]
40 pub struct Equatable(u32);
41
42
43 impl Add<u32> for Equatable {
44 type Output = u32;
45
46 //~ MONO_ITEM fn <Equatable as std::ops::Add<u32>>::add
47 fn add(self, rhs: u32) -> u32 {
48 self.0 + rhs
49 }
50 }
51
52 impl Deref for Equatable {
53 type Target = u32;
54
55 //~ MONO_ITEM fn <Equatable as std::ops::Deref>::deref
56 fn deref(&self) -> &Self::Target {
57 &self.0
58 }
59 }