Skip to content

Commit 265b89a

Browse files
author
Jorge Aparicio
committed
libsyntax: convert BytePos/CharPos binops to by value
1 parent b5537fa commit 265b89a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/libsyntax/codemap.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,35 +52,71 @@ impl Pos for BytePos {
5252
fn to_uint(&self) -> uint { let BytePos(n) = *self; n as uint }
5353
}
5454

55+
// NOTE(stage0): Remove impl after a snapshot
56+
#[cfg(stage0)]
5557
impl Add<BytePos, BytePos> for BytePos {
5658
fn add(&self, rhs: &BytePos) -> BytePos {
5759
BytePos((self.to_uint() + rhs.to_uint()) as u32)
5860
}
5961
}
6062

63+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
64+
impl Add<BytePos, BytePos> for BytePos {
65+
fn add(self, rhs: BytePos) -> BytePos {
66+
BytePos((self.to_uint() + rhs.to_uint()) as u32)
67+
}
68+
}
69+
70+
// NOTE(stage0): Remove impl after a snapshot
71+
#[cfg(stage0)]
6172
impl Sub<BytePos, BytePos> for BytePos {
6273
fn sub(&self, rhs: &BytePos) -> BytePos {
6374
BytePos((self.to_uint() - rhs.to_uint()) as u32)
6475
}
6576
}
6677

78+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
79+
impl Sub<BytePos, BytePos> for BytePos {
80+
fn sub(self, rhs: BytePos) -> BytePos {
81+
BytePos((self.to_uint() - rhs.to_uint()) as u32)
82+
}
83+
}
84+
6785
impl Pos for CharPos {
6886
fn from_uint(n: uint) -> CharPos { CharPos(n) }
6987
fn to_uint(&self) -> uint { let CharPos(n) = *self; n }
7088
}
7189

90+
// NOTE(stage0): Remove impl after a snapshot
91+
#[cfg(stage0)]
7292
impl Add<CharPos,CharPos> for CharPos {
7393
fn add(&self, rhs: &CharPos) -> CharPos {
7494
CharPos(self.to_uint() + rhs.to_uint())
7595
}
7696
}
7797

98+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
99+
impl Add<CharPos, CharPos> for CharPos {
100+
fn add(self, rhs: CharPos) -> CharPos {
101+
CharPos(self.to_uint() + rhs.to_uint())
102+
}
103+
}
104+
105+
// NOTE(stage0): Remove impl after a snapshot
106+
#[cfg(stage0)]
78107
impl Sub<CharPos,CharPos> for CharPos {
79108
fn sub(&self, rhs: &CharPos) -> CharPos {
80109
CharPos(self.to_uint() - rhs.to_uint())
81110
}
82111
}
83112

113+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
114+
impl Sub<CharPos, CharPos> for CharPos {
115+
fn sub(self, rhs: CharPos) -> CharPos {
116+
CharPos(self.to_uint() - rhs.to_uint())
117+
}
118+
}
119+
84120
/// Spans represent a region of code, used for error reporting. Positions in spans
85121
/// are *absolute* positions from the beginning of the codemap, not positions
86122
/// relative to FileMaps. Methods on the CodeMap can be used to relate spans back

0 commit comments

Comments
 (0)