Skip to content

Commit 1e77cac

Browse files
committed
Resolve precedence clippy lint
warning: operator precedence can trip the unwary --> src/read.rs:963:18 | 963 | let n = (((n1 - 0xD800) as u32) << 10 | (n2 - 0xDC00) as u32) + 0x1_0000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(((n1 - 0xD800) as u32) << 10) | (n2 - 0xDC00) as u32` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#precedence = note: `-W clippy::precedence` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::precedence)]` warning: operator precedence can trip the unwary --> src/read.rs:991:28 | 991 | ptr.write((n >> 6 & 0b0001_1111) as u8 | 0b1100_0000); | ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(n >> 6) & 0b0001_1111` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#precedence warning: operator precedence can trip the unwary --> src/read.rs:995:28 | 995 | ptr.write((n >> 12 & 0b0000_1111) as u8 | 0b1110_0000); | ^^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(n >> 12) & 0b0000_1111` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#precedence warning: operator precedence can trip the unwary --> src/read.rs:996:35 | 996 | ptr.add(1).write((n >> 6 & 0b0011_1111) as u8 | 0b1000_0000); | ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(n >> 6) & 0b0011_1111` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#precedence warning: operator precedence can trip the unwary --> src/read.rs:1000:28 | 1000 | ptr.write((n >> 18 & 0b0000_0111) as u8 | 0b1111_0000); | ^^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(n >> 18) & 0b0000_0111` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#precedence warning: operator precedence can trip the unwary --> src/read.rs:1002:29 | 1002 | .write((n >> 12 & 0b0011_1111) as u8 | 0b1000_0000); | ^^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(n >> 12) & 0b0011_1111` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#precedence warning: operator precedence can trip the unwary --> src/read.rs:1003:35 | 1003 | ptr.add(2).write((n >> 6 & 0b0011_1111) as u8 | 0b1000_0000); | ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(n >> 6) & 0b0011_1111` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#precedence
1 parent b2a1415 commit 1e77cac

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/read.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ fn parse_unicode_escape<'de, R: Read<'de>>(
960960

961961
// This value is in range U+10000..=U+10FFFF, which is always a valid
962962
// codepoint.
963-
let n = (((n1 - 0xD800) as u32) << 10 | (n2 - 0xDC00) as u32) + 0x1_0000;
963+
let n = ((((n1 - 0xD800) as u32) << 10) | (n2 - 0xDC00) as u32) + 0x1_0000;
964964
push_wtf8_codepoint(n, scratch);
965965
return Ok(());
966966
}
@@ -988,19 +988,21 @@ fn push_wtf8_codepoint(n: u32, scratch: &mut Vec<u8>) {
988988
let encoded_len = match n {
989989
0..=0x7F => unreachable!(),
990990
0x80..=0x7FF => {
991-
ptr.write((n >> 6 & 0b0001_1111) as u8 | 0b1100_0000);
991+
ptr.write(((n >> 6) & 0b0001_1111) as u8 | 0b1100_0000);
992992
2
993993
}
994994
0x800..=0xFFFF => {
995-
ptr.write((n >> 12 & 0b0000_1111) as u8 | 0b1110_0000);
996-
ptr.add(1).write((n >> 6 & 0b0011_1111) as u8 | 0b1000_0000);
995+
ptr.write(((n >> 12) & 0b0000_1111) as u8 | 0b1110_0000);
996+
ptr.add(1)
997+
.write(((n >> 6) & 0b0011_1111) as u8 | 0b1000_0000);
997998
3
998999
}
9991000
0x1_0000..=0x10_FFFF => {
1000-
ptr.write((n >> 18 & 0b0000_0111) as u8 | 0b1111_0000);
1001+
ptr.write(((n >> 18) & 0b0000_0111) as u8 | 0b1111_0000);
10011002
ptr.add(1)
1002-
.write((n >> 12 & 0b0011_1111) as u8 | 0b1000_0000);
1003-
ptr.add(2).write((n >> 6 & 0b0011_1111) as u8 | 0b1000_0000);
1003+
.write(((n >> 12) & 0b0011_1111) as u8 | 0b1000_0000);
1004+
ptr.add(2)
1005+
.write(((n >> 6) & 0b0011_1111) as u8 | 0b1000_0000);
10041006
4
10051007
}
10061008
0x11_0000.. => unreachable!(),

0 commit comments

Comments
 (0)