1
Fork 0

Add a lint to warn about call to .*or(foo(..))

This commit is contained in:
mcarton 2016-01-16 18:47:45 +01:00
parent 604be945d2
commit c6604bb281
5 changed files with 90 additions and 4 deletions

View file

@ -175,6 +175,33 @@ fn search_is_some() {
let _ = foo.rposition().is_some();
}
/// Checks implementation of the OR_FUN_CALL lint
fn or_fun_call() {
let foo = Some(vec![1]);
foo.unwrap_or(Vec::new());
//~^ERROR use of `unwrap_or`
//~|HELP try this
//~|SUGGESTION foo.unwrap_or_else(Vec::new);
let bar = Some(vec![1]);
bar.unwrap_or(Vec::with_capacity(12));
//~^ERROR use of `unwrap_or`
//~|HELP try this
//~|SUGGESTION bar.unwrap_or_else(|| Vec::with_capacity(12));
let baz : Result<_, ()> = Ok(vec![1]);
baz.unwrap_or(Vec::new());
//~^ERROR use of `unwrap_or`
//~|HELP try this
//~|SUGGESTION baz.unwrap_or_else(|_| Vec::new());
let qux : Result<_, ()> = Ok(vec![1]);
qux.unwrap_or(Vec::with_capacity(12));
//~^ERROR use of `unwrap_or`
//~|HELP try this
//~|SUGGESTION qux.unwrap_or_else(|_| Vec::with_capacity(12));
}
fn main() {
use std::io;