rust/tests/ui/use_unwrap_or.rs
2022-03-17 18:57:28 +01:00

28 lines
826 B
Rust

#![warn(clippy::use_unwrap_or)]
struct SomeStruct {}
impl SomeStruct {
fn or(self, _: Option<Self>) -> Self { self }
fn unwrap(&self){}
}
fn main() {
let option: Option<&str> = None;
let _ = option.or(Some("fallback")).unwrap(); // should trigger lint
let result: Result<&str, &str> = Err("Error");
let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint
// Not Option/Result
let instance = SomeStruct {};
let _ = instance.or(Some(SomeStruct {})).unwrap(); // should not trigger lint
// None in or
let option: Option<&str> = None;
let _ = option.or(None).unwrap(); // should not trigger lint
// Not Err in or
let result: Result<&str, &str> = Err("Error");
let _ = result.or::<&str>(Err("Other Error")).unwrap(); // should not trigger lint
}