2019-05-12 10:10:23 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2019-09-18 06:37:41 +00:00
|
|
|
//! Used to test that certain lints don't trigger in imported external macros
|
|
|
|
|
2019-05-12 10:10:23 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! foofoo {
|
|
|
|
() => {
|
|
|
|
loop {}
|
|
|
|
};
|
|
|
|
}
|
2019-09-18 06:37:41 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! must_use_unit {
|
|
|
|
() => {
|
|
|
|
#[must_use]
|
|
|
|
fn foo() {}
|
|
|
|
};
|
|
|
|
}
|
2019-10-24 05:52:01 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! try_err {
|
|
|
|
() => {
|
|
|
|
pub fn try_err_fn() -> Result<i32, i32> {
|
|
|
|
let err: i32 = 1;
|
|
|
|
// To avoid warnings during rustfix
|
2021-03-01 17:53:33 +00:00
|
|
|
if true { Err(err)? } else { Ok(2) }
|
2019-10-24 05:52:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-12-05 10:06:13 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! string_add {
|
|
|
|
() => {
|
|
|
|
let y = "".to_owned();
|
|
|
|
let z = y + "...";
|
|
|
|
};
|
|
|
|
}
|
2019-12-08 19:46:21 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! take_external {
|
|
|
|
($s:expr) => {
|
|
|
|
std::mem::replace($s, Default::default())
|
|
|
|
};
|
|
|
|
}
|
2020-02-09 18:58:08 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! option_env_unwrap_external {
|
|
|
|
($env: expr) => {
|
|
|
|
option_env!($env).unwrap()
|
|
|
|
};
|
|
|
|
($env: expr, $message: expr) => {
|
|
|
|
option_env!($env).expect($message)
|
|
|
|
};
|
|
|
|
}
|
2020-10-24 08:50:11 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! ref_arg_binding {
|
|
|
|
() => {
|
|
|
|
let ref _y = 42;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! ref_arg_function {
|
|
|
|
() => {
|
|
|
|
fn fun_example(ref _x: usize) {}
|
|
|
|
};
|
|
|
|
}
|
2020-11-03 00:00:30 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! as_conv_with_arg {
|
|
|
|
(0u32 as u64) => {
|
|
|
|
()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! as_conv {
|
|
|
|
() => {
|
|
|
|
0u32 as u64
|
|
|
|
};
|
|
|
|
}
|
2020-12-21 10:09:49 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! large_enum_variant {
|
|
|
|
() => {
|
|
|
|
enum LargeEnumInMacro {
|
|
|
|
A(i32),
|
|
|
|
B([i32; 8000]),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-01-05 19:11:37 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! field_reassign_with_default {
|
|
|
|
() => {
|
|
|
|
#[derive(Default)]
|
|
|
|
struct A {
|
|
|
|
pub i: i32,
|
|
|
|
pub j: i64,
|
|
|
|
}
|
|
|
|
fn lint() {
|
|
|
|
let mut a: A = Default::default();
|
|
|
|
a.i = 42;
|
|
|
|
a;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-06-05 06:11:44 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! default_numeric_fallback {
|
|
|
|
() => {
|
|
|
|
let x = 22;
|
|
|
|
};
|
|
|
|
}
|
2021-10-09 13:54:16 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! mut_mut {
|
|
|
|
() => {
|
|
|
|
let mut_mut_ty: &mut &mut u32 = &mut &mut 1u32;
|
|
|
|
};
|
|
|
|
}
|
2022-02-17 00:08:53 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! ptr_as_ptr_cast {
|
|
|
|
($ptr: ident) => {
|
|
|
|
$ptr as *const i32
|
|
|
|
};
|
|
|
|
}
|
2022-06-23 20:34:52 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! manual_rem_euclid {
|
|
|
|
() => {
|
|
|
|
let value: i32 = 5;
|
|
|
|
let _: i32 = ((value % 4) + 4) % 4;
|
|
|
|
};
|
|
|
|
}
|