summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed
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/bind_instead_of_map_multipart.fixed
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/bind_instead_of_map_multipart.fixed')
-rw-r--r--src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed
new file mode 100644
index 000000000..e15898432
--- /dev/null
+++ b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed
@@ -0,0 +1,62 @@
+// run-rustfix
+#![deny(clippy::bind_instead_of_map)]
+#![allow(clippy::blocks_in_if_conditions)]
+
+pub fn main() {
+ let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() });
+ let _ = Some("42").and_then(|s| if s.len() < 42 { None } else { Some(s.len()) });
+
+ let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() });
+ let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Err(()) } else { Ok(s.len()) });
+
+ let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() });
+ let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Ok(()) } else { Err(s.len()) });
+
+ hard_example();
+ macro_example();
+}
+
+fn hard_example() {
+ Some("42").map(|s| {
+ if {
+ if s == "43" {
+ return 43;
+ }
+ s == "42"
+ } {
+ return 45;
+ }
+ match s.len() {
+ 10 => 2,
+ 20 => {
+ if foo() {
+ return {
+ if foo() {
+ return 20;
+ }
+ println!("foo");
+ 3
+ };
+ }
+ 20
+ },
+ 40 => 30,
+ _ => 1,
+ }
+ });
+}
+
+fn foo() -> bool {
+ true
+}
+
+macro_rules! m {
+ () => {
+ Some(10)
+ };
+}
+
+fn macro_example() {
+ let _ = Some("").and_then(|s| if s.len() == 20 { m!() } else { Some(20) });
+ let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) });
+}