summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.fixed
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/unnecessary_map_on_constructor.fixed')
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_map_on_constructor.fixed56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.fixed b/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.fixed
new file mode 100644
index 000000000..d0ba7ed74
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.fixed
@@ -0,0 +1,56 @@
+#![allow(unused)]
+#![warn(clippy::unnecessary_map_on_constructor)]
+
+use std::ffi::OsStr;
+
+fn fun(t: i32) -> i32 {
+ t
+}
+
+fn notfun(e: SimpleError) -> SimpleError {
+ e
+}
+macro_rules! expands_to_fun {
+ () => {
+ fun
+ };
+}
+
+#[derive(Copy, Clone)]
+struct SimpleError {}
+
+type SimpleResult = std::result::Result<i32, SimpleError>;
+
+fn main() {
+ let x: i32 = 4;
+
+ let err = SimpleError {};
+ let a = Some(x);
+ let b: SimpleResult = Ok(x);
+ let c: SimpleResult = Err(err);
+
+ let a = Some(fun(x));
+ let b: SimpleResult = Ok(fun(x));
+ let c: SimpleResult = Err(notfun(err));
+
+ let a = Option::Some(fun(x));
+ let b: SimpleResult = SimpleResult::Ok(fun(x));
+ let c: SimpleResult = SimpleResult::Err(notfun(err));
+ let b: std::result::Result<i32, SimpleError> = Ok(fun(x));
+ let c: std::result::Result<i32, SimpleError> = Err(notfun(err));
+
+ let a = Some(fun(x));
+ let b: SimpleResult = Ok(fun(x));
+ let c: SimpleResult = Err(notfun(err));
+
+ // Should not trigger warning
+ a.map(fun);
+ b.map(fun);
+ c.map_err(notfun);
+
+ b.map_err(notfun); // Ok(_).map_err
+ c.map(fun); // Err(_).map()
+
+ option_env!("PATH").map(OsStr::new);
+ Some(x).map(expands_to_fun!());
+}