]> git.lizzy.rs Git - rust.git/commitdiff
Move test to new UI test system
authorPhilipp Hansch <dev@phansch.net>
Mon, 9 Apr 2018 06:20:46 +0000 (08:20 +0200)
committerPhilipp Hansch <dev@phansch.net>
Sun, 15 Apr 2018 11:01:09 +0000 (13:01 +0200)
tests/compile-fail/map_nil_fn.rs [deleted file]
tests/ui/option_map_unit_fn.rs [new file with mode: 0644]
tests/ui/option_map_unit_fn.stderr [new file with mode: 0644]

diff --git a/tests/compile-fail/map_nil_fn.rs b/tests/compile-fail/map_nil_fn.rs
deleted file mode 100644 (file)
index b580e53..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-#![feature(plugin)]
-#![feature(const_fn)]
-#![plugin(clippy)]
-
-#![deny(clippy_pedantic)]
-#![allow(unused, missing_docs_in_private_items)]
-
-fn do_nothing<T>(_: T) {}
-
-fn diverge<T>(_: T) -> ! {
-    panic!()
-}
-
-fn plus_one(value: usize) -> usize {
-    value + 1
-}
-
-struct HasOption {
-    field: Option<usize>,
-}
-
-impl HasOption {
-    fn do_option_nothing(self: &HasOption, value: usize) {}
-
-    fn do_option_plus_one(self: &HasOption, value: usize) -> usize {
-        value + 1
-    }
-}
-
-#[cfg_attr(rustfmt, rustfmt_skip)]
-fn main() {
-    let x = HasOption { field: Some(10) };
-
-    x.field.map(plus_one);
-    let _ : Option<()> = x.field.map(do_nothing);
-
-    x.field.map(do_nothing);
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil function
-    //~| HELP try this
-    //~| SUGGESTION if let Some(...) = x.field { do_nothing(...) }
-
-    x.field.map(do_nothing);
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil function
-    //~| HELP try this
-    //~| SUGGESTION if let Some(...) = x.field { do_nothing(...) }
-
-    x.field.map(diverge);
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil function
-    //~| HELP try this
-    //~| SUGGESTION if let Some(...) = x.field { diverge(...) }
-
-    let captured = 10;
-    if let Some(value) = x.field { do_nothing(value + captured) };
-    let _ : Option<()> = x.field.map(|value| do_nothing(value + captured));
-
-    x.field.map(|value| x.do_option_nothing(value + captured));
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { x.do_option_nothing(value + captured) }
-
-    x.field.map(|value| { x.do_option_plus_one(value + captured); });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { x.do_option_plus_one(value + captured); }
-
-
-    x.field.map(|value| do_nothing(value + captured));
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { do_nothing(value + captured) }
-
-    x.field.map(|value| { do_nothing(value + captured) });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { do_nothing(value + captured) }
-
-    x.field.map(|value| { do_nothing(value + captured); });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { do_nothing(value + captured) }
-
-    x.field.map(|value| { { do_nothing(value + captured); } });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { do_nothing(value + captured) }
-
-
-    x.field.map(|value| diverge(value + captured));
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { diverge(value + captured) }
-
-    x.field.map(|value| { diverge(value + captured) });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { diverge(value + captured) }
-
-    x.field.map(|value| { diverge(value + captured); });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { diverge(value + captured) }
-
-    x.field.map(|value| { { diverge(value + captured); } });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { diverge(value + captured) }
-
-
-    x.field.map(|value| plus_one(value + captured));
-    x.field.map(|value| { plus_one(value + captured) });
-    x.field.map(|value| { let y = plus_one(value + captured); });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { let y = plus_one(value + captured); }
-
-    x.field.map(|value| { plus_one(value + captured); });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { plus_one(value + captured); }
-
-    x.field.map(|value| { { plus_one(value + captured); } });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { plus_one(value + captured); }
-
-
-    x.field.map(|ref value| { do_nothing(value + captured) });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(ref value) = x.field { do_nothing(value + captured) }
-
-
-    x.field.map(|value| { do_nothing(value); do_nothing(value) });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { ... }
-
-    x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) });
-    //~^ ERROR called `map(f)` on an Option value where `f` is a nil closure
-    //~| HELP try this
-    //~| SUGGESTION if let Some(value) = x.field { ... }
-}
diff --git a/tests/ui/option_map_unit_fn.rs b/tests/ui/option_map_unit_fn.rs
new file mode 100644 (file)
index 0000000..9718276
--- /dev/null
@@ -0,0 +1,81 @@
+#![warn(option_map_unit_fn)]
+#![allow(unused)]
+
+fn do_nothing<T>(_: T) {}
+
+fn diverge<T>(_: T) -> ! {
+    panic!()
+}
+
+fn plus_one(value: usize) -> usize {
+    value + 1
+}
+
+struct HasOption {
+    field: Option<usize>,
+}
+
+impl HasOption {
+    fn do_option_nothing(self: &Self, value: usize) {}
+
+    fn do_option_plus_one(self: &Self, value: usize) -> usize {
+        value + 1
+    }
+}
+
+#[cfg_attr(rustfmt, rustfmt_skip)]
+fn main() {
+    let x = HasOption { field: Some(10) };
+
+    x.field.map(plus_one);
+    let _ : Option<()> = x.field.map(do_nothing);
+
+    x.field.map(do_nothing);
+
+    x.field.map(do_nothing);
+
+    x.field.map(diverge);
+
+    let captured = 10;
+    if let Some(value) = x.field { do_nothing(value + captured) };
+    let _ : Option<()> = x.field.map(|value| do_nothing(value + captured));
+
+    x.field.map(|value| x.do_option_nothing(value + captured));
+
+    x.field.map(|value| { x.do_option_plus_one(value + captured); });
+
+
+    x.field.map(|value| do_nothing(value + captured));
+
+    x.field.map(|value| { do_nothing(value + captured) });
+
+    x.field.map(|value| { do_nothing(value + captured); });
+
+    x.field.map(|value| { { do_nothing(value + captured); } });
+
+
+    x.field.map(|value| diverge(value + captured));
+
+    x.field.map(|value| { diverge(value + captured) });
+
+    x.field.map(|value| { diverge(value + captured); });
+
+    x.field.map(|value| { { diverge(value + captured); } });
+
+
+    x.field.map(|value| plus_one(value + captured));
+    x.field.map(|value| { plus_one(value + captured) });
+    x.field.map(|value| { let y = plus_one(value + captured); });
+
+    x.field.map(|value| { plus_one(value + captured); });
+
+    x.field.map(|value| { { plus_one(value + captured); } });
+
+
+    x.field.map(|ref value| { do_nothing(value + captured) });
+
+
+    x.field.map(|value| { do_nothing(value); do_nothing(value) });
+
+    x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) });
+}
diff --git a/tests/ui/option_map_unit_fn.stderr b/tests/ui/option_map_unit_fn.stderr
new file mode 100644 (file)
index 0000000..ee0945d
--- /dev/null
@@ -0,0 +1,156 @@
+error: called `map(f)` on an Option value where `f` is a unit function
+  --> $DIR/option_map_unit_fn.rs:33:5
+   |
+33 |     x.field.map(do_nothing);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(...) = x.field { do_nothing(...) }`
+   |
+   = note: `-D option-map-unit-fn` implied by `-D warnings`
+
+error: called `map(f)` on an Option value where `f` is a unit function
+  --> $DIR/option_map_unit_fn.rs:35:5
+   |
+35 |     x.field.map(do_nothing);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(...) = x.field { do_nothing(...) }`
+
+error: called `map(f)` on an Option value where `f` is a unit function
+  --> $DIR/option_map_unit_fn.rs:37:5
+   |
+37 |     x.field.map(diverge);
+   |     ^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(...) = x.field { diverge(...) }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:43:5
+   |
+43 |     x.field.map(|value| x.do_option_nothing(value + captured));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { x.do_option_nothing(value + captured) }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:45:5
+   |
+45 |     x.field.map(|value| { x.do_option_plus_one(value + captured); });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { x.do_option_plus_one(value + captured); }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:48:5
+   |
+48 |     x.field.map(|value| do_nothing(value + captured));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:50:5
+   |
+50 |     x.field.map(|value| { do_nothing(value + captured) });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:52:5
+   |
+52 |     x.field.map(|value| { do_nothing(value + captured); });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:54:5
+   |
+54 |     x.field.map(|value| { { do_nothing(value + captured); } });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:57:5
+   |
+57 |     x.field.map(|value| diverge(value + captured));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:59:5
+   |
+59 |     x.field.map(|value| { diverge(value + captured) });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:61:5
+   |
+61 |     x.field.map(|value| { diverge(value + captured); });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:63:5
+   |
+63 |     x.field.map(|value| { { diverge(value + captured); } });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:68:5
+   |
+68 |     x.field.map(|value| { let y = plus_one(value + captured); });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { let y = plus_one(value + captured); }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:70:5
+   |
+70 |     x.field.map(|value| { plus_one(value + captured); });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:72:5
+   |
+72 |     x.field.map(|value| { { plus_one(value + captured); } });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:75:5
+   |
+75 |     x.field.map(|ref value| { do_nothing(value + captured) });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(ref value) = x.field { do_nothing(value + captured) }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:78:5
+   |
+78 |     x.field.map(|value| { do_nothing(value); do_nothing(value) });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { ... }`
+
+error: called `map(f)` on an Option value where `f` is a unit closure
+  --> $DIR/option_map_unit_fn.rs:80:5
+   |
+80 |     x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) });
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
+   |     |
+   |     help: try this: `if let Some(value) = x.field { ... }`
+
+error: aborting due to 19 previous errors
+