Skip to content

Commit c3386db

Browse files
committed
Use debug_assert! instead of assert! where possible
1 parent 11f812a commit c3386db

File tree

160 files changed

+441
-437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+441
-437
lines changed

src/libarena/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ impl<T> TypedArena<T> {
166166
where
167167
T: Copy,
168168
{
169-
assert!(mem::size_of::<T>() != 0);
170-
assert!(slice.len() != 0);
169+
debug_assert!(mem::size_of::<T>() != 0);
170+
debug_assert!(slice.len() != 0);
171171

172172
let available_capacity_bytes = self.end.get() as usize - self.ptr.get() as usize;
173173
let at_least_bytes = slice.len() * mem::size_of::<T>();
@@ -318,7 +318,7 @@ impl DroplessArena {
318318
fn align(&self, align: usize) {
319319
let final_address = ((self.ptr.get() as usize) + align - 1) & !(align - 1);
320320
self.ptr.set(final_address as *mut u8);
321-
assert!(self.ptr <= self.end);
321+
debug_assert!(self.ptr <= self.end);
322322
}
323323

324324
#[inline(never)]
@@ -357,7 +357,7 @@ impl DroplessArena {
357357
#[inline]
358358
pub fn alloc_raw(&self, bytes: usize, align: usize) -> &mut [u8] {
359359
unsafe {
360-
assert!(bytes != 0);
360+
debug_assert!(bytes != 0);
361361

362362
self.align(align);
363363

@@ -377,7 +377,7 @@ impl DroplessArena {
377377

378378
#[inline]
379379
pub fn alloc<T>(&self, object: T) -> &mut T {
380-
assert!(!mem::needs_drop::<T>());
380+
debug_assert!(!mem::needs_drop::<T>());
381381

382382
let mem = self.alloc_raw(
383383
mem::size_of::<T>(),
@@ -402,9 +402,9 @@ impl DroplessArena {
402402
where
403403
T: Copy,
404404
{
405-
assert!(!mem::needs_drop::<T>());
406-
assert!(mem::size_of::<T>() != 0);
407-
assert!(slice.len() != 0);
405+
debug_assert!(!mem::needs_drop::<T>());
406+
debug_assert!(mem::size_of::<T>() != 0);
407+
debug_assert!(slice.len() != 0);
408408

409409
let mem = self.alloc_raw(
410410
slice.len() * mem::size_of::<T>(),

src/libpanic_unwind/emcc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn payload() -> *mut u8 {
3030
}
3131

3232
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
33-
assert!(!ptr.is_null());
33+
debug_assert!(!ptr.is_null());
3434
let ex = ptr::read(ptr as *mut _);
3535
__cxa_free_exception(ptr as *mut _);
3636
ex

src/librustc/cfg/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct LabelledCFG<'a, 'tcx: 'a> {
3232

3333
impl<'a, 'tcx> LabelledCFG<'a, 'tcx> {
3434
fn local_id_to_string(&self, local_id: hir::ItemLocalId) -> String {
35-
assert!(self.cfg.owner_def_id.is_local());
35+
debug_assert!(self.cfg.owner_def_id.is_local());
3636
let node_id = self.tcx.hir.hir_to_node_id(hir::HirId {
3737
owner: self.tcx.hir.def_index_to_hir_id(self.cfg.owner_def_id.index).owner,
3838
local_id

src/librustc/dep_graph/dep_node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ macro_rules! define_dep_nodes {
301301
pub fn from_def_path_hash(kind: DepKind,
302302
def_path_hash: DefPathHash)
303303
-> DepNode {
304-
assert!(kind.can_reconstruct_query_key() && kind.has_params());
304+
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
305305
DepNode {
306306
kind,
307307
hash: def_path_hash.0,
@@ -313,7 +313,7 @@ macro_rules! define_dep_nodes {
313313
/// does not require any parameters.
314314
#[inline]
315315
pub fn new_no_params(kind: DepKind) -> DepNode {
316-
assert!(!kind.has_params());
316+
debug_assert!(!kind.has_params());
317317
DepNode {
318318
kind,
319319
hash: Fingerprint::ZERO,

src/librustc/hir/def_id.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ newtype_index!(CrateNum
3939

4040
impl CrateNum {
4141
pub fn new(x: usize) -> CrateNum {
42-
assert!(x < (u32::MAX as usize));
42+
debug_assert!(x < (u32::MAX as usize));
4343
CrateNum(x as u32)
4444
}
4545

@@ -127,7 +127,7 @@ impl DefIndex {
127127
pub fn from_proc_macro_index(proc_macro_index: usize) -> DefIndex {
128128
let def_index = DefIndex::from_array_index(proc_macro_index,
129129
DefIndexAddressSpace::High);
130-
assert!(def_index != CRATE_DEF_INDEX);
130+
debug_assert!(def_index != CRATE_DEF_INDEX);
131131
def_index
132132
}
133133

@@ -222,7 +222,7 @@ pub struct LocalDefId(DefIndex);
222222
impl LocalDefId {
223223
#[inline]
224224
pub fn from_def_id(def_id: DefId) -> LocalDefId {
225-
assert!(def_id.is_local());
225+
debug_assert!(def_id.is_local());
226226
LocalDefId(def_id.index)
227227
}
228228

src/librustc/hir/lowering.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ impl<'a> LoweringContext<'a> {
654654
where
655655
F: FnOnce(&mut LoweringContext) -> (Vec<hir::GenericParam>, T),
656656
{
657-
assert!(!self.is_collecting_in_band_lifetimes);
658-
assert!(self.lifetimes_to_define.is_empty());
657+
debug_assert!(!self.is_collecting_in_band_lifetimes);
658+
debug_assert!(self.lifetimes_to_define.is_empty());
659659
let old_anonymous_lifetime_mode = self.anonymous_lifetime_mode;
660660

661661
self.is_collecting_in_band_lifetimes = self.sess.features_untracked().in_band_lifetimes;
@@ -735,7 +735,7 @@ impl<'a> LoweringContext<'a> {
735735
/// When we have either an elided or `'_` lifetime in an impl
736736
/// header, we convert it to
737737
fn collect_fresh_in_band_lifetime(&mut self, span: Span) -> ParamName {
738-
assert!(self.is_collecting_in_band_lifetimes);
738+
debug_assert!(self.is_collecting_in_band_lifetimes);
739739
let index = self.lifetimes_to_define.len();
740740
let hir_name = ParamName::Fresh(index);
741741
self.lifetimes_to_define.push((span, hir_name));
@@ -1596,7 +1596,7 @@ impl<'a> LoweringContext<'a> {
15961596
if let Some(&n) = self.type_def_lifetime_params.get(&def_id) {
15971597
return n;
15981598
}
1599-
assert!(!def_id.is_local());
1599+
debug_assert!(!def_id.is_local());
16001600
let item_generics =
16011601
self.cstore.item_generics_cloned_untracked(def_id, self.sess);
16021602
let n = item_generics.own_counts().lifetimes;
@@ -4369,7 +4369,7 @@ impl<'a> LoweringContext<'a> {
43694369
has_value: has_value,
43704370
},
43714371
Defaultness::Final => {
4372-
assert!(has_value);
4372+
debug_assert!(has_value);
43734373
hir::Defaultness::Final
43744374
}
43754375
}

src/librustc/hir/map/definitions.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl DefPath {
257257
debug!("DefPath::make: key={:?}", key);
258258
match key.disambiguated_data.data {
259259
DefPathData::CrateRoot => {
260-
assert!(key.parent.is_none());
260+
debug_assert!(key.parent.is_none());
261261
break;
262262
}
263263
_ => {
@@ -500,7 +500,7 @@ impl Definitions {
500500
let address_space = super::ITEM_LIKE_SPACE;
501501
let root_index = self.table.allocate(key, def_path_hash, address_space);
502502
assert_eq!(root_index, CRATE_DEF_INDEX);
503-
assert!(self.def_index_to_node[address_space.index()].is_empty());
503+
debug_assert!(self.def_index_to_node[address_space.index()].is_empty());
504504
self.def_index_to_node[address_space.index()].push(ast::CRATE_NODE_ID);
505505
self.node_to_def_index.insert(ast::CRATE_NODE_ID, root_index);
506506

@@ -522,14 +522,15 @@ impl Definitions {
522522
debug!("create_def_with_parent(parent={:?}, node_id={:?}, data={:?})",
523523
parent, node_id, data);
524524

525-
assert!(!self.node_to_def_index.contains_key(&node_id),
526-
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
527-
node_id,
528-
data,
529-
self.table.def_key(self.node_to_def_index[&node_id]));
525+
debug_assert!(!self.node_to_def_index.contains_key(&node_id),
526+
"adding a def'n for node-id {:?} and data {:?} \
527+
but a previous def'n exists: {:?}",
528+
node_id,
529+
data,
530+
self.table.def_key(self.node_to_def_index[&node_id]));
530531

531532
// The root node must be created with create_root_def()
532-
assert!(data != DefPathData::CrateRoot);
533+
debug_assert!(data != DefPathData::CrateRoot);
533534

534535
// Find the next free disambiguator for this key.
535536
let disambiguator = {
@@ -581,8 +582,8 @@ impl Definitions {
581582
/// AST to HIR lowering.
582583
pub fn init_node_id_to_hir_id_mapping(&mut self,
583584
mapping: IndexVec<ast::NodeId, hir::HirId>) {
584-
assert!(self.node_to_hir_id.is_empty(),
585-
"Trying initialize NodeId -> HirId mapping twice");
585+
debug_assert!(self.node_to_hir_id.is_empty(),
586+
"Trying initialize NodeId -> HirId mapping twice");
586587
self.node_to_hir_id = mapping;
587588
}
588589

src/librustc/hir/map/hir_id_validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
8282
fn check<F: FnOnce(&mut HirIdValidator<'a, 'hir>)>(&mut self,
8383
node_id: NodeId,
8484
walk: F) {
85-
assert!(self.owner_def_index.is_none());
85+
debug_assert!(self.owner_def_index.is_none());
8686
let owner_def_index = self.hir_map.local_def_id(node_id).index;
8787
self.owner_def_index = Some(owner_def_index);
8888
walk(self);

src/librustc/hir/map/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl<'hir> Map<'hir> {
350350
}
351351

352352
pub fn def_key(&self, def_id: DefId) -> DefKey {
353-
assert!(def_id.is_local());
353+
debug_assert!(def_id.is_local());
354354
self.definitions.def_key(def_id.index)
355355
}
356356

@@ -361,7 +361,7 @@ impl<'hir> Map<'hir> {
361361
}
362362

363363
pub fn def_path(&self, def_id: DefId) -> DefPath {
364-
assert!(def_id.is_local());
364+
debug_assert!(def_id.is_local());
365365
self.definitions.def_path(def_id.index)
366366
}
367367

@@ -554,7 +554,7 @@ impl<'hir> Map<'hir> {
554554
/// item (possibly associated), a closure, or a `hir::AnonConst`.
555555
pub fn body_owner(&self, BodyId { node_id }: BodyId) -> NodeId {
556556
let parent = self.get_parent_node(node_id);
557-
assert!(self.map[parent.as_usize()].is_body_owner(node_id));
557+
debug_assert!(self.map[parent.as_usize()].is_body_owner(node_id));
558558
parent
559559
}
560560

src/librustc/hir/print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,7 @@ impl<'a> State<'a> {
20012001
self.popen()?;
20022002
let mut i = 0;
20032003
// Make sure we aren't supplied *both* `arg_names` and `body_id`.
2004-
assert!(arg_names.is_empty() || body_id.is_none());
2004+
debug_assert!(arg_names.is_empty() || body_id.is_none());
20052005
self.commasep(Inconsistent, &decl.inputs, |s, ty| {
20062006
s.ibox(indent_unit)?;
20072007
if let Some(arg_name) = arg_names.get(i) {

0 commit comments

Comments
 (0)