mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 18:53:39 +00:00
a41cb7adbe
* add `rest_arg` to pass second argument from `map_or(U, F)` * extract some procedures into closure refac: rename rest_arg/second_arg refac: organize function argument order * put `second_arg` next to `arg` argument
42 lines
1012 B
Rust
42 lines
1012 B
Rust
// run-rustfix
|
|
#![warn(clippy::manual_ok_or)]
|
|
#![allow(clippy::or_fun_call)]
|
|
#![allow(clippy::disallowed_names)]
|
|
#![allow(clippy::redundant_closure)]
|
|
#![allow(dead_code)]
|
|
#![allow(unused_must_use)]
|
|
|
|
fn main() {
|
|
// basic case
|
|
let foo: Option<i32> = None;
|
|
foo.ok_or("error");
|
|
|
|
// eta expansion case
|
|
foo.ok_or("error");
|
|
|
|
// turbo fish syntax
|
|
None::<i32>.ok_or("error");
|
|
|
|
// multiline case
|
|
#[rustfmt::skip]
|
|
foo.ok_or(&format!(
|
|
"{}{}{}{}{}{}{}",
|
|
"Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer"));
|
|
|
|
// not applicable, closure isn't direct `Ok` wrapping
|
|
foo.map_or(Err("error"), |v| Ok(v + 1));
|
|
|
|
// not applicable, or side isn't `Result::Err`
|
|
foo.map_or(Ok::<i32, &str>(1), |v| Ok(v));
|
|
|
|
// not applicable, expr is not a `Result` value
|
|
foo.map_or(42, |v| v);
|
|
|
|
// TODO patterns not covered yet
|
|
match foo {
|
|
Some(v) => Ok(v),
|
|
None => Err("error"),
|
|
};
|
|
foo.map_or_else(|| Err("error"), |v| Ok(v));
|
|
}
|