Skip to content

Commit

Permalink
even more wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Noratrieb committed Jan 1, 2024
1 parent c2a4946 commit 80ea420
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl AllocDecodingState {
let counter = DECODER_SESSION_ID.fetch_add(1, Ordering::SeqCst);

// Make sure this is never zero.
let session_id = DecodingSessionId::new((counter & 0x7FFFFFFF) + 1).unwrap();
let session_id = DecodingSessionId::new((counter & 0x7FFFFFFF).wrapping_add(1)).unwrap();

AllocDecodingSession { state: self, session_id }
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_query_system/src/dep_graph/serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ impl SerializedDepGraph {
// edge list, or the end of the array if this is the last edge.
let end = self
.edge_list_indices
.get(source + 1)
.get(source.wrapping_add(1))
.map(|h| h.start())
.unwrap_or_else(|| self.edge_list_data.len() - DEP_NODE_PAD);
.unwrap_or_else(|| self.edge_list_data.len().wrapping_sub(DEP_NODE_PAD));

// The number of edges for this node is implicitly stored in the combination of the byte
// width and the length.
let bytes_per_index = header.bytes_per_index();
let len = (end - header.start()) / bytes_per_index;
let len = (end.wrapping_sub(header.start())) / bytes_per_index;

// LLVM doesn't hoist EdgeHeader::mask so we do it ourselves.
let mask = header.mask();
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_serialize/src/leb128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ macro_rules! impl_write_unsigned_leb128 {
*out.get_unchecked_mut(i) = value as u8;
}

i += 1;
i = i.wrapping_add(1);
break;
} else {
unsafe {
*out.get_unchecked_mut(i) = ((value & 0x7f) | 0x80) as u8;
}

value >>= 7;
i += 1;
i = i.wrapping_add(1);
}
}

Expand Down Expand Up @@ -60,7 +60,7 @@ macro_rules! impl_read_unsigned_leb128 {
return byte as $int_ty;
}
let mut result = (byte & 0x7F) as $int_ty;
let mut shift = 7;
let mut shift = 7_usize;
loop {
let byte = decoder.read_u8();
if (byte & 0x80) == 0 {
Expand All @@ -69,7 +69,7 @@ macro_rules! impl_read_unsigned_leb128 {
} else {
result |= ((byte & 0x7F) as $int_ty) << shift;
}
shift += 7;
shift = shift.wrapping_add(7);
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_serialize/src/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl FileEncoder {
// Tracking position this way instead of having a `self.position` field
// means that we only need to update `self.buffered` on a write call,
// as opposed to updating `self.position` and `self.buffered`.
self.flushed + self.buffered
self.flushed.wrapping_add(self.buffered)
}

#[cold]
Expand Down Expand Up @@ -119,7 +119,7 @@ impl FileEncoder {
}
if let Some(dest) = self.buffer_empty().get_mut(..buf.len()) {
dest.copy_from_slice(buf);
self.buffered += buf.len();
self.buffered = self.buffered.wrapping_add(buf.len());
} else {
self.write_all_cold_path(buf);
}
Expand Down Expand Up @@ -158,7 +158,7 @@ impl FileEncoder {
if written > N {
Self::panic_invalid_write::<N>(written);
}
self.buffered += written;
self.buffered = self.buffered.wrapping_add(written);
}

#[cold]
Expand Down

0 comments on commit 80ea420

Please sign in to comment.