Skip to content

Commit 48fcac2

Browse files
committed
use cfg attribute instead of if cfg!
1 parent d4ae855 commit 48fcac2

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

library/core/src/macros/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ 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) {
294+
#[cfg(debug_assertions)] {
295295
$crate::assert!($($arg)*);
296296
}
297297
};
@@ -321,7 +321,7 @@ macro_rules! debug_assert {
321321
#[rustc_diagnostic_item = "debug_assert_eq_macro"]
322322
macro_rules! debug_assert_eq {
323323
($($arg:tt)*) => {
324-
if $crate::cfg!(debug_assertions) {
324+
#[cfg(debug_assertions)] {
325325
$crate::assert_eq!($($arg)*);
326326
}
327327
};
@@ -351,7 +351,7 @@ macro_rules! debug_assert_eq {
351351
#[rustc_diagnostic_item = "debug_assert_ne_macro"]
352352
macro_rules! debug_assert_ne {
353353
($($arg:tt)*) => {
354-
if $crate::cfg!(debug_assertions) {
354+
#[cfg(debug_assertions)] {
355355
$crate::assert_ne!($($arg)*);
356356
}
357357
};
@@ -403,7 +403,7 @@ macro_rules! debug_assert_ne {
403403
#[allow_internal_unstable(assert_matches)]
404404
#[rustc_macro_transparency = "semitransparent"]
405405
pub macro debug_assert_matches($($arg:tt)*) {
406-
if $crate::cfg!(debug_assertions) {
406+
#[cfg(debug_assertions)] {
407407
$crate::assert_matches::assert_matches!($($arg)*);
408408
}
409409
}
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)