Skip to content

Commit 7af94d1

Browse files
committed
fix tests failing without debug assertions
The `debug_assert!` family of macros are guarded by an `if cfg!(debug_assertions)`, _not_ a `#[cfg(debug_assertions)]` attribute. This means that the code in the assertion is still type checked in release mode, and using code that only exists in debug mode will thus fail in release mode. See rust-lang/rust#62527. Therefore, since the `shard.tid` field has a `#[cfg(debug_assertions)]` attribute on it, it's necessary to also put that attribute on the assertions that use that field. cc @kleimkuhler, since you had previously asked why putting the cfg attribute on these assertions was necessary (#1625 (comment)). I thought you might nbe interested in seeing the answer. :) Signed-off-by: Eliza Weisman <[email protected]>
1 parent 8555055 commit 7af94d1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tokio/src/net/driver/reactor/dispatch/sharded_slab.rs

+3
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ impl Shard {
199199

200200
#[inline(always)]
201201
fn get(&self, idx: usize) -> Option<&page::ScheduledIo> {
202+
#[cfg(debug_assertions)]
202203
debug_assert_eq!(Tid::from_packed(idx).as_usize(), self.tid);
203204

204205
let addr = page::Addr::from_packed(idx);
@@ -212,6 +213,7 @@ impl Shard {
212213

213214
/// Remove an item on the shard's local thread.
214215
fn remove_local(&self, idx: usize) {
216+
#[cfg(debug_assertions)]
215217
debug_assert_eq!(Tid::from_packed(idx).as_usize(), self.tid);
216218
let addr = page::Addr::from_packed(idx);
217219
let page_idx = addr.index();
@@ -223,6 +225,7 @@ impl Shard {
223225

224226
/// Remove an item, while on a different thread from the shard's local thread.
225227
fn remove_remote(&self, idx: usize) {
228+
#[cfg(debug_assertions)]
226229
debug_assert_eq!(Tid::from_packed(idx).as_usize(), self.tid);
227230
let addr = page::Addr::from_packed(idx);
228231
let page_idx = addr.index();

0 commit comments

Comments
 (0)