Skip to content

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed
 

‎src/libsyntax/codemap.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -822,14 +822,14 @@ impl CodeMap {
822822
total_extra_bytes += mbc.bytes - 1;
823823
// We should never see a byte position in the middle of a
824824
// character
825-
assert!(bpos.to_usize() >= mbc.pos.to_usize() + mbc.bytes);
825+
assert!(bpos.to_u32() >= mbc.pos.to_u32() + mbc.bytes);
826826
} else {
827827
break;
828828
}
829829
}
830830

831-
assert!(map.start_pos.to_usize() + total_extra_bytes <= bpos.to_usize());
832-
CharPos(bpos.to_usize() - map.start_pos.to_usize() - total_extra_bytes)
831+
assert!(map.start_pos.to_u32() + total_extra_bytes <= bpos.to_u32());
832+
CharPos(bpos.to_usize() - map.start_pos.to_usize() - total_extra_bytes as usize)
833833
}
834834

835835
// Return the index of the filemap (in self.files) which contains pos.

‎src/libsyntax_pos/lib.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ pub struct MultiByteChar {
657657
/// The absolute offset of the character in the CodeMap
658658
pub pos: BytePos,
659659
/// The number of bytes, >=2
660-
pub bytes: usize,
660+
pub bytes: u32,
661661
}
662662

663663
/// Identifies an offset of a non-narrow character in a FileMap
@@ -1174,6 +1174,8 @@ fn remove_bom(src: &mut String) {
11741174
pub trait Pos {
11751175
fn from_usize(n: usize) -> Self;
11761176
fn to_usize(&self) -> usize;
1177+
fn from_u32(n: u32) -> Self;
1178+
fn to_u32(&self) -> u32;
11771179
}
11781180

11791181
/// A byte offset. Keep this small (currently 32-bits), as AST contains
@@ -1195,7 +1197,13 @@ impl Pos for BytePos {
11951197
fn from_usize(n: usize) -> BytePos { BytePos(n as u32) }
11961198

11971199
#[inline(always)]
1198-
fn to_usize(&self) -> usize { let BytePos(n) = *self; n as usize }
1200+
fn to_usize(&self) -> usize { self.0 as usize }
1201+
1202+
#[inline(always)]
1203+
fn from_u32(n: u32) -> BytePos { BytePos(n) }
1204+
1205+
#[inline(always)]
1206+
fn to_u32(&self) -> u32 { self.0 }
11991207
}
12001208

12011209
impl Add for BytePos {
@@ -1233,7 +1241,13 @@ impl Pos for CharPos {
12331241
fn from_usize(n: usize) -> CharPos { CharPos(n) }
12341242

12351243
#[inline(always)]
1236-
fn to_usize(&self) -> usize { let CharPos(n) = *self; n }
1244+
fn to_usize(&self) -> usize { self.0 }
1245+
1246+
#[inline(always)]
1247+
fn from_u32(n: u32) -> CharPos { CharPos(n as usize) }
1248+
1249+
#[inline(always)]
1250+
fn to_u32(&self) -> u32 { self.0 as u32}
12371251
}
12381252

12391253
impl Add for CharPos {

0 commit comments

Comments
 (0)
Please sign in to comment.