1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
14 #![warn(clippy::block_in_if_condition_expr)]
15 #![warn(clippy::block_in_if_condition_stmt)]
16 #![allow(unused, clippy::let_and_return)]
17 #![warn(clippy::nonminimal_bool)]
24 macro_rules! blocky_too {
39 fn condition_has_block() -> i32 {
50 fn condition_has_block_with_single_expression() -> i32 {
58 fn predicate<F: FnOnce(T) -> bool, T>(pfn: F, val:T) -> bool {
65 // this is a sneaky case, where the block isn't directly in the condition, but is actually
66 // inside a closure that the condition is using. same principle applies. add some extra
67 // expressions to make sure linter isn't confused by them.
68 if v == 3 && sky == "blue" && predicate(|x| { let target = 3; x == target }, v) {
71 if predicate(|x| { let target = 3; x == target }, v) {
75 fn condition_is_normal() -> i32 {
84 fn closure_without_block() {
85 if predicate(|x| x == 3, 6) {
90 fn condition_is_unsafe_block() {
93 // this should not warn because the condition is an unsafe block
94 if unsafe { 1u32 == std::mem::transmute(a) } {
95 println!("1u32 == a");
102 fn macro_in_closure() {
103 let option = Some(true);
105 if option.unwrap_or_else(|| unimplemented!()) {