Skip to content

Commit c61310f

Browse files
committed
even more wrapping
1 parent c2a4946 commit c61310f

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

compiler/rustc_middle/src/mir/interpret/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl AllocDecodingState {
285285
let counter = DECODER_SESSION_ID.fetch_add(1, Ordering::SeqCst);
286286

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

290290
AllocDecodingSession { state: self, session_id }
291291
}

compiler/rustc_query_system/src/dep_graph/serialized.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ impl SerializedDepGraph {
101101
// edge list, or the end of the array if this is the last edge.
102102
let end = self
103103
.edge_list_indices
104-
.get(source + 1)
104+
.get(SerializedDepNodeIndex::from_usize(source.index().wrapping_add(1)))
105105
.map(|h| h.start())
106-
.unwrap_or_else(|| self.edge_list_data.len() - DEP_NODE_PAD);
106+
.unwrap_or_else(|| self.edge_list_data.len().wrapping_sub(DEP_NODE_PAD));
107107

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

113113
// LLVM doesn't hoist EdgeHeader::mask so we do it ourselves.
114114
let mask = header.mask();

compiler/rustc_serialize/src/leb128.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ macro_rules! impl_write_unsigned_leb128 {
2424
*out.get_unchecked_mut(i) = value as u8;
2525
}
2626

27-
i += 1;
27+
i = i.wrapping_add(1);
2828
break;
2929
} else {
3030
unsafe {
3131
*out.get_unchecked_mut(i) = ((value & 0x7f) | 0x80) as u8;
3232
}
3333

3434
value >>= 7;
35-
i += 1;
35+
i = i.wrapping_add(1);
3636
}
3737
}
3838

@@ -60,7 +60,7 @@ macro_rules! impl_read_unsigned_leb128 {
6060
return byte as $int_ty;
6161
}
6262
let mut result = (byte & 0x7F) as $int_ty;
63-
let mut shift = 7;
63+
let mut shift = 7_usize;
6464
loop {
6565
let byte = decoder.read_u8();
6666
if (byte & 0x80) == 0 {
@@ -69,7 +69,7 @@ macro_rules! impl_read_unsigned_leb128 {
6969
} else {
7070
result |= ((byte & 0x7F) as $int_ty) << shift;
7171
}
72-
shift += 7;
72+
shift = shift.wrapping_add(7);
7373
}
7474
}
7575
};

compiler/rustc_serialize/src/opaque.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl FileEncoder {
6565
// Tracking position this way instead of having a `self.position` field
6666
// means that we only need to update `self.buffered` on a write call,
6767
// as opposed to updating `self.position` and `self.buffered`.
68-
self.flushed + self.buffered
68+
self.flushed.wrapping_add(self.buffered)
6969
}
7070

7171
#[cold]
@@ -119,7 +119,7 @@ impl FileEncoder {
119119
}
120120
if let Some(dest) = self.buffer_empty().get_mut(..buf.len()) {
121121
dest.copy_from_slice(buf);
122-
self.buffered += buf.len();
122+
self.buffered = self.buffered.wrapping_add(buf.len());
123123
} else {
124124
self.write_all_cold_path(buf);
125125
}
@@ -158,7 +158,7 @@ impl FileEncoder {
158158
if written > N {
159159
Self::panic_invalid_write::<N>(written);
160160
}
161-
self.buffered += written;
161+
self.buffered = self.buffered.wrapping_add(written);
162162
}
163163

164164
#[cold]

0 commit comments

Comments
 (0)