Skip to content

Commit f29e62a

Browse files
committed
Fix a warning in libcore on 16bit targets.
This code is assuming that usize >= 32bits, but it is not the case on 16bit targets. It is producing a warning that will fail the compilation on MSP430 if deny(warnings) is enabled. It is very unlikely that someone would actually use this code on a microcontroller, but since unicode was merged into libcore we have compile it on 16bit targets.
1 parent 491512b commit f29e62a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/libcore/unicode/bool_trie.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ pub struct BoolTrie {
4242
}
4343
impl BoolTrie {
4444
pub fn lookup(&self, c: char) -> bool {
45-
let c = c as usize;
45+
let c = c as u32;
4646
if c < 0x800 {
47-
trie_range_leaf(c, self.r1[c >> 6])
47+
trie_range_leaf(c, self.r1[(c >> 6) as usize])
4848
} else if c < 0x10000 {
49-
let child = self.r2[(c >> 6) - 0x20];
49+
let child = self.r2[(c >> 6) as usize - 0x20];
5050
trie_range_leaf(c, self.r3[child as usize])
5151
} else {
52-
let child = self.r4[(c >> 12) - 0x10];
53-
let leaf = self.r5[((child as usize) << 6) + ((c >> 6) & 0x3f)];
52+
let child = self.r4[(c >> 12) as usize - 0x10];
53+
let leaf = self.r5[((child as usize) << 6) + ((c >> 6) as usize & 0x3f)];
5454
trie_range_leaf(c, self.r6[leaf as usize])
5555
}
5656
}
@@ -63,14 +63,14 @@ pub struct SmallBoolTrie {
6363

6464
impl SmallBoolTrie {
6565
pub fn lookup(&self, c: char) -> bool {
66-
let c = c as usize;
67-
match self.r1.get(c >> 6) {
66+
let c = c as u32;
67+
match self.r1.get((c >> 6) as usize) {
6868
Some(&child) => trie_range_leaf(c, self.r2[child as usize]),
6969
None => false,
7070
}
7171
}
7272
}
7373

74-
fn trie_range_leaf(c: usize, bitmap_chunk: u64) -> bool {
74+
fn trie_range_leaf(c: u32, bitmap_chunk: u64) -> bool {
7575
((bitmap_chunk >> (c & 63)) & 1) != 0
7676
}

0 commit comments

Comments
 (0)