diff --git a/crates/block-sys/src/lib.rs b/crates/block-sys/src/lib.rs index a19f8fb84..a642c9f86 100644 --- a/crates/block-sys/src/lib.rs +++ b/crates/block-sys/src/lib.rs @@ -20,6 +20,8 @@ #![deny(unsafe_op_in_unsafe_fn)] #![warn(clippy::cargo)] #![warn(clippy::ptr_as_ptr)] +#![warn(clippy::missing_errors_doc)] +#![warn(clippy::missing_panics_doc)] // Update in Cargo.toml as well. #![doc(html_root_url = "https://docs.rs/block-sys/0.2.0")] #![cfg_attr(feature = "unstable-docsrs", feature(doc_auto_cfg, doc_cfg_hide))] diff --git a/crates/block2/src/block.rs b/crates/block2/src/block.rs index 892c0e88b..0b32ad489 100644 --- a/crates/block2/src/block.rs +++ b/crates/block2/src/block.rs @@ -116,7 +116,7 @@ impl Block { let ptr: *const Self = self; let layout = unsafe { ptr.cast::().as_ref().unwrap_unchecked() }; // TODO: Is `invoke` actually ever null? - let invoke = layout.invoke.unwrap(); + let invoke = layout.invoke.unwrap_or_else(|| unreachable!()); unsafe { A::__call_block(invoke, ptr as *mut Self, args) } } diff --git a/crates/block2/src/lib.rs b/crates/block2/src/lib.rs index d5cda24d0..73346095c 100644 --- a/crates/block2/src/lib.rs +++ b/crates/block2/src/lib.rs @@ -84,6 +84,8 @@ #![deny(unsafe_op_in_unsafe_fn)] #![warn(clippy::cargo)] #![warn(clippy::ptr_as_ptr)] +#![warn(clippy::missing_errors_doc)] +#![warn(clippy::missing_panics_doc)] // Update in Cargo.toml as well. #![doc(html_root_url = "https://docs.rs/block2/0.3.0")] diff --git a/crates/objc-sys/src/lib.rs b/crates/objc-sys/src/lib.rs index 9790c317f..90b5217ff 100644 --- a/crates/objc-sys/src/lib.rs +++ b/crates/objc-sys/src/lib.rs @@ -21,6 +21,8 @@ #![deny(unsafe_op_in_unsafe_fn)] #![warn(clippy::cargo)] #![warn(clippy::ptr_as_ptr)] +#![warn(clippy::missing_errors_doc)] +#![warn(clippy::missing_panics_doc)] #![allow(clippy::upper_case_acronyms)] #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] diff --git a/crates/objc2-encode/src/encoding_box.rs b/crates/objc2-encode/src/encoding_box.rs index d3e05f766..e369fbff9 100644 --- a/crates/objc2-encode/src/encoding_box.rs +++ b/crates/objc2-encode/src/encoding_box.rs @@ -111,6 +111,11 @@ impl EncodingBox { /// returned by `method_getTypeEncoding`. /// /// [`from_str`][Self::from_str] is simpler, use that instead if you can. + /// + /// + /// # Errors + /// + /// Returns an error if the string was an ill-formatted encoding string. pub fn from_start_of_str(s: &mut &str) -> Result { let mut parser = Parser::new(s); parser.strip_leading_qualifiers(); diff --git a/crates/objc2-encode/src/lib.rs b/crates/objc2-encode/src/lib.rs index b005945f1..1bb1f564e 100644 --- a/crates/objc2-encode/src/lib.rs +++ b/crates/objc2-encode/src/lib.rs @@ -45,6 +45,8 @@ #![deny(unsafe_op_in_unsafe_fn)] #![warn(clippy::cargo)] #![warn(clippy::ptr_as_ptr)] +#![warn(clippy::missing_errors_doc)] +#![warn(clippy::missing_panics_doc)] // Update in Cargo.toml as well. #![doc(html_root_url = "https://docs.rs/objc2-encode/3.0.0")] #![cfg_attr(feature = "unstable-c-unwind", feature(c_unwind))] diff --git a/crates/objc2-proc-macros/src/lib.rs b/crates/objc2-proc-macros/src/lib.rs index 4b67518de..0c23f88f0 100644 --- a/crates/objc2-proc-macros/src/lib.rs +++ b/crates/objc2-proc-macros/src/lib.rs @@ -12,6 +12,8 @@ #![deny(unsafe_op_in_unsafe_fn)] #![warn(clippy::cargo)] #![warn(clippy::ptr_as_ptr)] +#![warn(clippy::missing_errors_doc)] +#![warn(clippy::missing_panics_doc)] // Update in Cargo.toml as well. #![doc(html_root_url = "https://docs.rs/objc2-proc-macros/0.1.1")] diff --git a/crates/objc2/src/declare/mod.rs b/crates/objc2/src/declare/mod.rs index ae3054abc..8a54835b5 100644 --- a/crates/objc2/src/declare/mod.rs +++ b/crates/objc2/src/declare/mod.rs @@ -666,6 +666,11 @@ impl ProtocolBuilder { /// Constructs a [`ProtocolBuilder`] with the given name. /// /// Returns [`None`] if the protocol couldn't be allocated. + /// + /// + /// # Panics + /// + /// Panics if the name contains an internal NULL byte. pub fn new(name: &str) -> Option { let c_name = CString::new(name).unwrap(); let proto = unsafe { ffi::objc_allocateProtocol(c_name.as_ptr()) }; diff --git a/crates/objc2/src/exception.rs b/crates/objc2/src/exception.rs index 719784ed1..d3e399f91 100644 --- a/crates/objc2/src/exception.rs +++ b/crates/objc2/src/exception.rs @@ -254,6 +254,11 @@ unsafe fn try_no_ret(closure: F) -> Result<(), Option /// Accordingly, if your Rust code is compiled with `panic=abort` this cannot /// catch the exception. /// +/// [`catch_unwind`]: std::panic::catch_unwind +/// +/// +/// # Errors +/// /// Returns a `Result` that is either `Ok` if the closure succeeded without an /// exception being thrown, or an `Err` with the exception. The exception is /// automatically released. @@ -263,8 +268,6 @@ unsafe fn try_no_ret(closure: F) -> Result<(), Option /// technically possible on some systems with `@throw nil`, or in OOM /// situations. /// -/// [`catch_unwind`]: std::panic::catch_unwind -/// /// /// # Safety /// @@ -286,8 +289,8 @@ pub unsafe fn catch( *value_ref = Some(closure()); }; let result = unsafe { try_no_ret(closure) }; - // If the try succeeded, this was set so it's safe to unwrap - result.map(|()| value.unwrap()) + // If the try succeeded, value was set so it's safe to unwrap + result.map(|()| value.unwrap_or_else(|| unreachable!())) } #[cfg(test)] diff --git a/crates/objc2/src/lib.rs b/crates/objc2/src/lib.rs index 22396917d..76be46550 100644 --- a/crates/objc2/src/lib.rs +++ b/crates/objc2/src/lib.rs @@ -167,6 +167,8 @@ #![deny(unsafe_op_in_unsafe_fn)] #![warn(clippy::cargo)] #![warn(clippy::ptr_as_ptr)] +#![warn(clippy::missing_errors_doc)] +#![warn(clippy::missing_panics_doc)] // Update in Cargo.toml as well. #![doc(html_root_url = "https://docs.rs/objc2/0.4.1")] diff --git a/crates/objc2/src/rc/test_object.rs b/crates/objc2/src/rc/test_object.rs index 7338c1f49..debc48b04 100644 --- a/crates/objc2/src/rc/test_object.rs +++ b/crates/objc2/src/rc/test_object.rs @@ -30,6 +30,7 @@ impl __ThreadTestData { } #[track_caller] + #[allow(clippy::missing_panics_doc)] pub fn assert_current(&self) { let current = Self::current(); let mut expected = self.clone(); diff --git a/crates/objc2/src/runtime/mod.rs b/crates/objc2/src/runtime/mod.rs index 236c35335..416e0c04c 100644 --- a/crates/objc2/src/runtime/mod.rs +++ b/crates/objc2/src/runtime/mod.rs @@ -827,6 +827,7 @@ impl AnyClass { /// let result = cls.verify_sel::<(&AnyClass,), bool>(sel); /// assert!(result.is_ok()); /// ``` + #[allow(clippy::missing_errors_doc)] // Written differently in the docs pub fn verify_sel(&self, sel: Sel) -> Result<(), VerificationError> where A: EncodeArguments,