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

+8-8
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

+1-1
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

+1-1
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

+2-2
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

+3-3
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

+5-5
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

+11-10
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

+1-1
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

+3-3
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

+1-1
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) {

src/librustc/infer/anon_types/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,15 @@ impl<'cx, 'gcx, 'tcx> ReverseMapper<'cx, 'gcx, 'tcx> {
513513
}
514514

515515
fn fold_kind_mapping_missing_regions_to_empty(&mut self, kind: Kind<'tcx>) -> Kind<'tcx> {
516-
assert!(!self.map_missing_regions_to_empty);
516+
debug_assert!(!self.map_missing_regions_to_empty);
517517
self.map_missing_regions_to_empty = true;
518518
let kind = kind.fold_with(self);
519519
self.map_missing_regions_to_empty = false;
520520
kind
521521
}
522522

523523
fn fold_kind_normally(&mut self, kind: Kind<'tcx>) -> Kind<'tcx> {
524-
assert!(!self.map_missing_regions_to_empty);
524+
debug_assert!(!self.map_missing_regions_to_empty);
525525
kind.fold_with(self)
526526
}
527527
}

src/librustc/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
396396
// If `var_values` has become big enough to be heap-allocated,
397397
// fill up `indices` to facilitate subsequent lookups.
398398
if !var_values.is_array() {
399-
assert!(indices.is_empty());
399+
debug_assert!(indices.is_empty());
400400
*indices =
401401
var_values.iter()
402402
.enumerate()

src/librustc/infer/canonical/query_result.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,8 @@ pub fn make_query_outlives<'tcx>(
576576
givens,
577577
} = region_constraints;
578578

579-
assert!(verifys.is_empty());
580-
assert!(givens.is_empty());
579+
debug_assert!(verifys.is_empty());
580+
debug_assert!(givens.is_empty());
581581

582582
let mut outlives: Vec<_> = constraints
583583
.into_iter()

src/librustc/infer/higher_ranked/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
252252
-> ty::Region<'tcx> {
253253
// Regions that pre-dated the LUB computation stay as they are.
254254
if !is_var_in_set(new_vars, r0) {
255-
assert!(!r0.is_late_bound());
255+
debug_assert!(!r0.is_late_bound());
256256
debug!("generalize_region(r0={:?}): not new variable", r0);
257257
return r0;
258258
}
@@ -266,7 +266,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
266266
debug!("generalize_region(r0={:?}): \
267267
non-new-variables found in {:?}",
268268
r0, tainted);
269-
assert!(!r0.is_late_bound());
269+
debug_assert!(!r0.is_late_bound());
270270
return r0;
271271
}
272272

@@ -349,7 +349,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
349349
r0: ty::Region<'tcx>)
350350
-> ty::Region<'tcx> {
351351
if !is_var_in_set(new_vars, r0) {
352-
assert!(!r0.is_late_bound());
352+
debug_assert!(!r0.is_late_bound());
353353
return r0;
354354
}
355355

@@ -402,7 +402,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
402402
return rev_lookup(infcx, span, a_map, a_r.unwrap());
403403
} else if a_r.is_none() && b_r.is_none() {
404404
// Not related to bound variables from either fn:
405-
assert!(!r0.is_late_bound());
405+
debug_assert!(!r0.is_late_bound());
406406
return r0;
407407
} else {
408408
// Other:
@@ -468,7 +468,7 @@ fn fold_regions_in<'a, 'gcx, 'tcx, T, F>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
468468
// we should only be encountering "escaping" late-bound regions here,
469469
// because the ones at the current level should have been replaced
470470
// with fresh variables
471-
assert!(match *region {
471+
debug_assert!(match *region {
472472
ty::ReLateBound(..) => false,
473473
_ => true
474474
});
@@ -746,13 +746,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
746746
// trait checking, and all of the skolemized regions
747747
// appear inside predicates, which always have
748748
// binders, so this assert is satisfied.
749-
assert!(current_depth > ty::INNERMOST);
749+
debug_assert!(current_depth > ty::INNERMOST);
750750

751751
// since leak-check passed, this skolemized region
752752
// should only have incoming edges from variables
753753
// (which ought not to escape the snapshot, but we
754754
// don't check that) or itself
755-
assert!(
755+
debug_assert!(
756756
match *r {
757757
ty::ReVar(_) => true,
758758
ty::ReSkolemized(_, ref br1) => br == br1,

src/librustc/infer/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10331033
outlives_env: &OutlivesEnvironment<'tcx>,
10341034
will_later_be_reported_by_nll: bool,
10351035
) {
1036-
assert!(self.is_tainted_by_errors() || self.region_obligations.borrow().is_empty(),
1036+
debug_assert!(self.is_tainted_by_errors() || self.region_obligations.borrow().is_empty(),
10371037
"region_obligations not empty: {:#?}",
10381038
self.region_obligations.borrow());
10391039

@@ -1049,7 +1049,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10491049
lexical_region_resolve::resolve(region_rels, var_infos, data);
10501050

10511051
let old_value = self.lexical_region_resolutions.replace(Some(lexical_region_resolutions));
1052-
assert!(old_value.is_none());
1052+
debug_assert!(old_value.is_none());
10531053

10541054
if !self.is_tainted_by_errors() {
10551055
// As a heuristic, just skip reporting region errors
@@ -1072,9 +1072,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10721072
/// translate them into the form that the NLL solver
10731073
/// understands. See the NLL module for mode details.
10741074
pub fn take_and_reset_region_constraints(&self) -> RegionConstraintData<'tcx> {
1075-
assert!(self.region_obligations.borrow().is_empty(),
1076-
"region_obligations not empty: {:#?}",
1077-
self.region_obligations.borrow());
1075+
debug_assert!(self.region_obligations.borrow().is_empty(),
1076+
"region_obligations not empty: {:#?}",
1077+
self.region_obligations.borrow());
10781078

10791079
self.borrow_region_constraints().take_and_reset_data()
10801080
}
@@ -1099,7 +1099,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10991099
.take()
11001100
.expect("regions already resolved")
11011101
.into_infos_and_data();
1102-
assert!(data.is_empty());
1102+
debug_assert!(data.is_empty());
11031103
var_infos
11041104
}
11051105

0 commit comments

Comments
 (0)