fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1//@aux-build:proc_macros.rs 2#![feature(let_chains)] 3#![allow( 4 clippy::blocks_in_if_conditions, 5 clippy::if_same_then_else, 6 clippy::ifs_same_cond, 7 clippy::let_unit_value, 8 clippy::needless_else, 9 clippy::no_effect, 10 clippy::nonminimal_bool, 11 clippy::short_circuit_statement, 12 clippy::unnecessary_operation, 13 unused 14)] 15#![warn(clippy::needless_if)] 16 17extern crate proc_macros; 18use proc_macros::{external, with_span}; 19 20fn maybe_side_effect() -> bool { 21 true 22} 23 24fn main() { 25 // Lint 26 27 // Do not remove the condition 28 maybe_side_effect(); 29 // Do not lint 30 if (true) { 31 } else { 32 } 33 ({ 34 return; 35 }); 36 // Do not lint if `else if` is present 37 if (true) { 38 } else if (true) { 39 } 40 // Do not lint `if let` or let chains 41 if let true = true {} 42 if let true = true && true {} 43 if true && let true = true {} 44 // Can lint nested `if let`s 45 ({ 46 if let true = true && true { true } else { false } 47 } && true); 48 external! { if (true) {} } 49 with_span! { 50 span 51 if (true) {} 52 } 53 54 if true { 55 // comment 56 } 57 58 if true { 59 #[cfg(any())] 60 foo; 61 } 62 63 macro_rules! empty_expansion { 64 () => {}; 65 } 66 67 if true { 68 empty_expansion!(); 69 } 70 71 macro_rules! empty_repetition { 72 ($($t:tt)*) => { 73 if true { 74 $($t)* 75 } 76 } 77 } 78 79 empty_repetition!(); 80 81 // Must be placed into an expression context to not be interpreted as a block 82 ({ maybe_side_effect() }); 83 // Would be a block followed by `&&true` - a double reference to `true` 84 ({ maybe_side_effect() } && true); 85 86 // Don't leave trailing attributes 87 #[allow(unused)] 88 true; 89 90 let () = if maybe_side_effect() {}; 91}