// run-rustfix #![warn(clippy::assertions_on_result_states)] use std::result::Result; struct Foo; #[derive(Debug)] struct DebugFoo; #[derive(Copy, Clone, Debug)] struct CopyFoo; macro_rules! get_ok_macro { () => { Ok::<_, DebugFoo>(Foo) }; } fn main() { // test ok let r: Result = Ok(Foo); debug_assert!(r.is_ok()); r.unwrap(); // test ok with non-debug error type let r: Result = Ok(Foo); assert!(r.is_ok()); // test ok with some messages let r: Result = Ok(Foo); assert!(r.is_ok(), "oops"); // test ok with unit error let r: Result = Ok(Foo); assert!(r.is_ok()); // test temporary ok fn get_ok() -> Result { Ok(Foo) } get_ok().unwrap(); // test macro ok get_ok_macro!().unwrap(); // test ok that shouldn't be moved let r: Result = Ok(CopyFoo); fn test_ref_unmoveable_ok(r: &Result) { assert!(r.is_ok()); } test_ref_unmoveable_ok(&r); assert!(r.is_ok()); r.unwrap(); // test ok that is copied let r: Result = Ok(CopyFoo); r.unwrap(); r.unwrap(); // test reference to ok let r: Result = Ok(CopyFoo); fn test_ref_copy_ok(r: &Result) { r.unwrap(); } test_ref_copy_ok(&r); r.unwrap(); // test err let r: Result = Err(Foo); debug_assert!(r.is_err()); r.unwrap_err(); // test err with non-debug value type let r: Result = Err(Foo); assert!(r.is_err()); }