summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs')
-rw-r--r--src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs b/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs
new file mode 100644
index 000000000..169589f6d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs
@@ -0,0 +1,64 @@
+#![warn(clippy::blocks_in_if_conditions)]
+#![allow(unused, clippy::let_and_return)]
+
+fn predicate<F: FnOnce(T) -> bool, T>(pfn: F, val: T) -> bool {
+ pfn(val)
+}
+
+fn pred_test() {
+ let v = 3;
+ let sky = "blue";
+ // This is a sneaky case, where the block isn't directly in the condition,
+ // but is actually inside a closure that the condition is using.
+ // The same principle applies -- add some extra expressions to make sure
+ // linter isn't confused by them.
+ if v == 3
+ && sky == "blue"
+ && predicate(
+ |x| {
+ let target = 3;
+ x == target
+ },
+ v,
+ )
+ {}
+
+ if predicate(
+ |x| {
+ let target = 3;
+ x == target
+ },
+ v,
+ ) {}
+}
+
+fn closure_without_block() {
+ if predicate(|x| x == 3, 6) {}
+}
+
+fn macro_in_closure() {
+ let option = Some(true);
+
+ if option.unwrap_or_else(|| unimplemented!()) {
+ unimplemented!()
+ }
+}
+
+fn closure(_: impl FnMut()) -> bool {
+ true
+}
+
+fn function_with_empty_closure() {
+ if closure(|| {}) {}
+}
+
+#[rustfmt::skip]
+fn main() {
+ let mut range = 0..10;
+ range.all(|i| {i < 10} );
+
+ let v = vec![1, 2, 3];
+ if v.into_iter().any(|x| {x == 4}) {
+ println!("contains 4!");
+ }
+}