Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 069a652

Browse files
committed
Use && instead & to get logical short-circuiting
1 parent 120a1af commit 069a652

File tree

10 files changed

+29
-28
lines changed

10 files changed

+29
-28
lines changed

lumen_runtime/src/atom.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl Ord for Atom {
168168
let other_length = other.name.len();
169169

170170
let bytes_ordering = if (ORDINAL_BYTE_COUNT < self_length)
171-
& (ORDINAL_BYTE_COUNT < other_length)
171+
&& (ORDINAL_BYTE_COUNT < other_length)
172172
{
173173
let range = ORDINAL_BYTE_COUNT..self_length.min(other_length);
174174

@@ -190,12 +190,12 @@ impl Ord for Atom {
190190
impl PartialEq for Atom {
191191
/// See https://github.com/erlang/otp/blob/be44d6827e2374a43068b35de85ed16441c771be/erts/emulator/beam/erl_utils.h#L159-L186
192192
fn eq(&self, other: &Atom) -> bool {
193-
(self.ordinal == other.ordinal) & {
193+
(self.ordinal == other.ordinal) && {
194194
let length = self.name.len();
195195

196196
// for equality, can check len before bytes because it is faster
197197
(length == other.name.len())
198-
& if ORDINAL_BYTE_COUNT < length {
198+
&& if ORDINAL_BYTE_COUNT < length {
199199
let range = ORDINAL_BYTE_COUNT..length;
200200

201201
self.name.as_bytes()[range.clone()] == other.name.as_bytes()[range.clone()]

lumen_runtime/src/binary.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ fn start_length_to_part_range(
319319
if length >= 0 {
320320
let non_negative_length = length as usize;
321321

322-
if (start <= available_byte_count) & (start + non_negative_length <= available_byte_count) {
322+
if (start <= available_byte_count) && (start + non_negative_length <= available_byte_count)
323+
{
323324
Ok(PartRange {
324325
byte_offset: start,
325326
byte_count: non_negative_length,
@@ -330,7 +331,7 @@ fn start_length_to_part_range(
330331
} else {
331332
let start_isize = start as isize;
332333

333-
if (start <= available_byte_count) & (0 <= start_isize + length) {
334+
if (start <= available_byte_count) && (0 <= start_isize + length) {
334335
let byte_offset = (start_isize + length) as usize;
335336
let byte_count = (-length) as usize;
336337

lumen_runtime/src/binary/heap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'b, 'a: 'b> Part<'a, usize, isize, binary::Binary<'b>> for Binary {
229229
byte_count,
230230
} = start_length_to_part_range(start, length, available_byte_count)?;
231231

232-
if (byte_offset == 0) & (byte_count == available_byte_count) {
232+
if (byte_offset == 0) && (byte_count == available_byte_count) {
233233
Ok(binary::Binary::Heap(self))
234234
} else {
235235
let process_subbinary = process.subbinary(self.into(), byte_offset, 0, byte_count, 0);
@@ -274,7 +274,7 @@ impl PartialEq<sub::Binary> for Binary {
274274
/// > * Bitstrings are compared byte by byte, incomplete bytes are compared bit by bit.
275275
/// > -- https://hexdocs.pm/elixir/operators.html#term-ordering
276276
fn eq(&self, other: &sub::Binary) -> bool {
277-
(other.bit_count == 0) & self.byte_iter().eq(other.byte_iter())
277+
(other.bit_count == 0) && self.byte_iter().eq(other.byte_iter())
278278
}
279279
}
280280

lumen_runtime/src/binary/sub.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ impl Hash for Binary {
221221
impl PartialEq for Binary {
222222
fn eq(&self, other: &Binary) -> bool {
223223
(self.bit_len() == other.bit_len())
224-
& self
224+
&& self
225225
.byte_iter()
226226
.zip(other.byte_iter())
227227
.all(|(self_byte, other_byte)| self_byte == other_byte)
228-
& self
228+
&& self
229229
.bit_count_iter()
230230
.zip(other.bit_count_iter())
231231
.all(|(self_bit, other_bit)| self_bit == other_bit)
@@ -321,7 +321,7 @@ impl Iterator for BitCountIter {
321321

322322
fn next(&mut self) -> Option<u8> {
323323
if (self.current_byte_offset == self.max_byte_offset)
324-
& (self.current_bit_offset == self.max_bit_offset)
324+
&& (self.current_bit_offset == self.max_bit_offset)
325325
{
326326
None
327327
} else {
@@ -386,7 +386,7 @@ impl PartialEq<heap::Binary> for Binary {
386386
/// > * Bitstrings are compared byte by byte, incomplete bytes are compared bit by bit.
387387
/// > -- https://hexdocs.pm/elixir/operators.html#term-ordering
388388
fn eq(&self, other: &heap::Binary) -> bool {
389-
(self.bit_count == 0) & self.byte_iter().eq(other.byte_iter())
389+
(self.bit_count == 0) && self.byte_iter().eq(other.byte_iter())
390390
}
391391
}
392392

lumen_runtime/src/exception.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ impl PartialEq for Exception {
146146
/// track down exceptions.
147147
fn eq(&self, other: &Exception) -> bool {
148148
(self.class == other.class)
149-
& (self.reason == other.reason)
150-
& (self.stacktrace == other.stacktrace)
149+
&& (self.reason == other.reason)
150+
&& (self.stacktrace == other.stacktrace)
151151
}
152152
}
153153

lumen_runtime/src/integer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl From<BigInt> for Integer {
7171
let small_min_big_int: BigInt = small::MIN.into();
7272
let small_max_big_int: BigInt = small::MAX.into();
7373

74-
if (small_min_big_int <= big_int) & (big_int <= small_max_big_int) {
74+
if (small_min_big_int <= big_int) && (big_int <= small_max_big_int) {
7575
let (sign, bytes) = big_int.to_bytes_be();
7676
let small_usize = bytes
7777
.iter()

lumen_runtime/src/otp/erlang.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub fn binary_to_float_1(binary: Term, process: &Process) -> Result {
250250
FpCategory::Normal | FpCategory::Subnormal =>
251251
// unlike Rust, Erlang requires float strings to have a decimal point
252252
{
253-
if (inner.fract() == 0.0) & !string.chars().any(|b| b == '.') {
253+
if (inner.fract() == 0.0) && !string.chars().any(|b| b == '.') {
254254
Err(badarg!())
255255
} else {
256256
Ok(inner.into_process(&process))
@@ -1230,7 +1230,7 @@ pub fn size_1(binary_or_tuple: Term, process: &Process) -> Result {
12301230
}
12311231

12321232
pub fn spawn_3(module: Term, function: Term, arguments: Term, process: &Process) -> Result {
1233-
let option_pid = if (module.tag() == Atom) & (function.tag() == Atom) {
1233+
let option_pid = if (module.tag() == Atom) && (function.tag() == Atom) {
12341234
match arguments.tag() {
12351235
EmptyList => {
12361236
let arc_process =
@@ -1341,7 +1341,7 @@ pub fn split_binary_2(binary: Term, position: Term, process: &Process) -> Result
13411341
);
13421342

13431343
Ok(Term::slice_to_tuple(&[prefix, suffix], &process))
1344-
} else if (index == byte_length) & (subbinary.bit_count == 0) {
1344+
} else if (index == byte_length) && (subbinary.bit_count == 0) {
13451345
let empty_suffix = Term::subbinary(
13461346
subbinary.original,
13471347
subbinary.byte_offset + index,

lumen_runtime/src/stacktrace.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn term_is_location_keyword_pair(term: Term) -> bool {
5454
}
5555

5656
fn tuple_is_location_keyword_pair(tuple: &Tuple) -> bool {
57-
(tuple.len() == 2) & {
57+
(tuple.len() == 2) && {
5858
let first_element = tuple[0];
5959

6060
match first_element.tag() {
@@ -123,12 +123,12 @@ fn tuple_is_item(tuple: &Tuple) -> bool {
123123

124124
match first_element.tag() {
125125
// {M, F, arity | args}
126-
Atom => tuple[1].is_atom() & is_arity_or_arguments(tuple[2]),
126+
Atom => tuple[1].is_atom() && is_arity_or_arguments(tuple[2]),
127127
// {function, args, location}
128128
Boxed => {
129129
let unboxed: &Term = first_element.unbox_reference();
130130

131-
(unboxed.tag() == Function) & term_is_location(tuple[2])
131+
(unboxed.tag() == Function) && term_is_location(tuple[2])
132132
}
133133
_ => false,
134134
}
@@ -137,9 +137,9 @@ fn tuple_is_item(tuple: &Tuple) -> bool {
137137
4 => {
138138
// {M, F, arity | args, location}
139139
tuple[0].is_atom()
140-
& tuple[1].is_atom()
141-
& is_arity_or_arguments(tuple[2])
142-
& term_is_location(tuple[3])
140+
&& tuple[1].is_atom()
141+
&& is_arity_or_arguments(tuple[2])
142+
&& term_is_location(tuple[3])
143143
}
144144
_ => false,
145145
}

lumen_runtime/src/term.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ impl Term {
826826
let float: &Float = float_term.unbox_reference();
827827
let float_f64 = float.inner;
828828

829-
(float_f64.fract() == 0.0) & {
829+
(float_f64.fract() == 0.0) && {
830830
let small_integer_isize = small_integer.small_integer_to_isize();
831831

832832
// float is out-of-range of SmallInteger, so it can't be equal
@@ -934,7 +934,7 @@ impl Term {
934934
let float: &Float = float_term.unbox_reference();
935935
let float_f64 = float.inner;
936936

937-
(float_f64.fract() == 0.0) & {
937+
(float_f64.fract() == 0.0) && {
938938
// Float fits in small integer range, so it can't be a BigInt
939939
// https://github.com/erlang/otp/blob/741c5a5e1dbffd32d0478d4941ab0f725d709086/erts/emulator/beam/utils.c#L3199-L3202
940940
if (((small::MIN - 1) as f64) < float_f64) | (float_f64 < ((small::MAX + 1) as f64)) {
@@ -949,7 +949,7 @@ impl Term {
949949
// > A float is more precise than an integer until all
950950
// > significant figures of the float are to the left of the
951951
// > decimal point.
952-
} else if (float::INTEGRAL_MIN <= float_f64) & (float_f64 <= float::INTEGRAL_MAX) {
952+
} else if (float::INTEGRAL_MIN <= float_f64) && (float_f64 <= float::INTEGRAL_MAX) {
953953
let big_integer_f64: f64 = big_integer.into();
954954

955955
big_integer_f64 == float_f64

lumen_runtime/src/tuple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl Tuple {
145145
Some(size_term) => {
146146
let size_usize: usize = size_term.try_into()?;
147147

148-
(element == record_tag) & (self.len() == size_usize)
148+
(element == record_tag) && (self.len() == size_usize)
149149
}
150150
None => element == record_tag,
151151
}
@@ -331,7 +331,7 @@ impl Ord for Tuple {
331331
impl PartialEq for Tuple {
332332
fn eq(&self, other: &Tuple) -> bool {
333333
(self.arity.tagged == other.arity.tagged)
334-
& self
334+
&& self
335335
.iter()
336336
.zip(other.iter())
337337
.all(|(self_element, other_element)| self_element == other_element)

0 commit comments

Comments
 (0)