Skip to content

Commit 33ad05f

Browse files
committed
use cfg attribute instead of if cfg!
1 parent d4ae855 commit 33ad05f

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

library/core/src/macros/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,8 @@ pub macro cfg_select($($tt:tt)*) {
291291
#[allow_internal_unstable(edition_panic)]
292292
macro_rules! debug_assert {
293293
($($arg:tt)*) => {
294-
if $crate::cfg!(debug_assertions) {
295-
$crate::assert!($($arg)*);
296-
}
294+
#[cfg(debug_assertions)]
295+
$crate::assert!($($arg)*);
297296
};
298297
}
299298

@@ -321,9 +320,8 @@ macro_rules! debug_assert {
321320
#[rustc_diagnostic_item = "debug_assert_eq_macro"]
322321
macro_rules! debug_assert_eq {
323322
($($arg:tt)*) => {
324-
if $crate::cfg!(debug_assertions) {
325-
$crate::assert_eq!($($arg)*);
326-
}
323+
#[cfg(debug_assertions)]
324+
$crate::assert_eq!($($arg)*);
327325
};
328326
}
329327

@@ -351,9 +349,8 @@ macro_rules! debug_assert_eq {
351349
#[rustc_diagnostic_item = "debug_assert_ne_macro"]
352350
macro_rules! debug_assert_ne {
353351
($($arg:tt)*) => {
354-
if $crate::cfg!(debug_assertions) {
355-
$crate::assert_ne!($($arg)*);
356-
}
352+
#[cfg(debug_assertions)]
353+
$crate::assert_ne!($($arg)*);
357354
};
358355
}
359356

@@ -403,9 +400,8 @@ macro_rules! debug_assert_ne {
403400
#[allow_internal_unstable(assert_matches)]
404401
#[rustc_macro_transparency = "semitransparent"]
405402
pub macro debug_assert_matches($($arg:tt)*) {
406-
if $crate::cfg!(debug_assertions) {
407-
$crate::assert_matches::assert_matches!($($arg)*);
408-
}
403+
#[cfg(debug_assertions)]
404+
$crate::assert_matches::assert_matches!($($arg)*);
409405
}
410406

411407
/// Returns whether the given expression matches the provided pattern.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ compile-flags: -C opt-level=3
2+
//@ check-pass
3+
4+
fn main() {
5+
let one = Thing;
6+
let two = Thing;
7+
8+
debug_assert_eq!(one, two);
9+
}
10+
11+
#[derive(Debug)]
12+
#[cfg_attr(debug_assertions, derive(PartialEq))]
13+
struct Thing;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ compile-flags: -C opt-level=0
2+
//@ check-pass
3+
4+
fn main() {
5+
let one = Thing;
6+
let two = Thing;
7+
8+
debug_assert_eq!(one, two);
9+
}
10+
11+
#[derive(Debug)]
12+
#[cfg_attr(debug_assertions, derive(PartialEq))]
13+
struct Thing;

0 commit comments

Comments
 (0)