2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-09-25 16:51:35 -05:00
|
|
|
#![allow(dead_code)]
|
|
|
|
#![allow(unused_mut)]
|
|
|
|
#![allow(unused_variables)]
|
2015-11-03 10:39:51 -06:00
|
|
|
#![deny(non_snake_case)]
|
2015-11-24 07:56:20 -06:00
|
|
|
#![feature(stmt_expr_attributes)]
|
2015-11-03 10:39:51 -06:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let a = 413;
|
|
|
|
#[cfg(unset)]
|
|
|
|
let a = ();
|
|
|
|
assert_eq!(a, 413);
|
|
|
|
|
|
|
|
let mut b = 612;
|
|
|
|
#[cfg(unset)]
|
|
|
|
{
|
|
|
|
b = 1111;
|
|
|
|
}
|
|
|
|
assert_eq!(b, 612);
|
|
|
|
|
|
|
|
#[cfg(unset)]
|
|
|
|
undefined_fn();
|
|
|
|
|
|
|
|
#[cfg(unset)]
|
|
|
|
undefined_macro!();
|
|
|
|
#[cfg(unset)]
|
|
|
|
undefined_macro![];
|
|
|
|
#[cfg(unset)]
|
|
|
|
undefined_macro!{};
|
|
|
|
|
|
|
|
// pretty printer bug...
|
|
|
|
// #[cfg(unset)]
|
|
|
|
// undefined_macro!{}
|
|
|
|
|
|
|
|
let () = (#[cfg(unset)] 341,); // Should this also work on parens?
|
|
|
|
let t = (1, #[cfg(unset)] 3, 4);
|
|
|
|
assert_eq!(t, (1, 4));
|
|
|
|
|
|
|
|
let f = |_: u32, _: u32| ();
|
|
|
|
f(2, 1, #[cfg(unset)] 6);
|
|
|
|
|
|
|
|
let _: u32 = a.clone(#[cfg(unset)] undefined);
|
|
|
|
|
|
|
|
let _: [(); 0] = [#[cfg(unset)] 126];
|
|
|
|
let t = [#[cfg(unset)] 1, 2, 6];
|
|
|
|
assert_eq!(t, [2, 6]);
|
|
|
|
|
|
|
|
{
|
|
|
|
let r;
|
|
|
|
#[cfg(unset)]
|
|
|
|
(r = 5);
|
|
|
|
#[cfg(not(unset))]
|
|
|
|
(r = 10);
|
|
|
|
assert_eq!(r, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check that macro expanded code works
|
|
|
|
|
|
|
|
macro_rules! if_cfg {
|
2019-08-17 17:10:56 -05:00
|
|
|
($cfg:meta? $ib:block else $eb:block) => {
|
2015-11-03 10:39:51 -06:00
|
|
|
{
|
|
|
|
let r;
|
|
|
|
#[cfg($cfg)]
|
|
|
|
(r = $ib);
|
|
|
|
#[cfg(not($cfg))]
|
|
|
|
(r = $eb);
|
|
|
|
r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-17 17:10:56 -05:00
|
|
|
let n = if_cfg!(unset? {
|
2015-11-03 10:39:51 -06:00
|
|
|
413
|
|
|
|
} else {
|
|
|
|
612
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!((#[cfg(unset)] 1, #[cfg(not(unset))] 2), (2,));
|
|
|
|
assert_eq!(n, 612);
|
|
|
|
|
|
|
|
// check that lints work
|
|
|
|
|
|
|
|
#[allow(non_snake_case)]
|
2023-06-12 03:55:36 -05:00
|
|
|
let FOOBAR: () = {
|
2015-11-03 10:39:51 -06:00
|
|
|
fn SYLADEX() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
{
|
|
|
|
fn CRUXTRUDER() {}
|
|
|
|
}
|
|
|
|
}
|