Don't allow newtype structs to be dereferenced. #6246

This commit is contained in:
Brian Anderson
2013-11-01 18:06:31 -07:00
parent 18cef3fad4
commit 3b1862a82f
78 changed files with 594 additions and 674 deletions

View File

@@ -46,35 +46,35 @@ pub struct CharPos(uint);
impl Pos for BytePos {
fn from_uint(n: uint) -> BytePos { BytePos(n as u32) }
fn to_uint(&self) -> uint { **self as uint }
fn to_uint(&self) -> uint { let BytePos(n) = *self; n as uint }
}
impl Add<BytePos, BytePos> for BytePos {
fn add(&self, rhs: &BytePos) -> BytePos {
BytePos(**self + **rhs)
BytePos((self.to_uint() + rhs.to_uint()) as u32)
}
}
impl Sub<BytePos, BytePos> for BytePos {
fn sub(&self, rhs: &BytePos) -> BytePos {
BytePos(**self - **rhs)
BytePos((self.to_uint() - rhs.to_uint()) as u32)
}
}
impl Pos for CharPos {
fn from_uint(n: uint) -> CharPos { CharPos(n) }
fn to_uint(&self) -> uint { **self }
fn to_uint(&self) -> uint { let CharPos(n) = *self; n }
}
impl Add<CharPos,CharPos> for CharPos {
fn add(&self, rhs: &CharPos) -> CharPos {
CharPos(**self + **rhs)
CharPos(self.to_uint() + rhs.to_uint())
}
}
impl Sub<CharPos,CharPos> for CharPos {
fn sub(&self, rhs: &CharPos) -> CharPos {
CharPos(**self - **rhs)
CharPos(self.to_uint() - rhs.to_uint())
}
}