Skip to content

Commit

Permalink
Add missing error and panic docs
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Aug 28, 2023
1 parent a9c569b commit bdd9d39
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions crates/block-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
2 changes: 1 addition & 1 deletion crates/block2/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<A: BlockArguments, R: EncodeReturn> Block<A, R> {
let ptr: *const Self = self;
let layout = unsafe { ptr.cast::<ffi::Block_layout>().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) }
}
Expand Down
2 changes: 2 additions & 0 deletions crates/block2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

Expand Down
2 changes: 2 additions & 0 deletions crates/objc-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 5 additions & 0 deletions crates/objc2-encode/src/encoding_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, ParseError> {
let mut parser = Parser::new(s);
parser.strip_leading_qualifiers();
Expand Down
2 changes: 2 additions & 0 deletions crates/objc2-encode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
2 changes: 2 additions & 0 deletions crates/objc2-proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

Expand Down
5 changes: 5 additions & 0 deletions crates/objc2/src/declare/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
let c_name = CString::new(name).unwrap();
let proto = unsafe { ffi::objc_allocateProtocol(c_name.as_ptr()) };
Expand Down
11 changes: 7 additions & 4 deletions crates/objc2/src/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ unsafe fn try_no_ret<F: FnOnce()>(closure: F) -> Result<(), Option<Id<Exception>
/// 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.
Expand All @@ -263,8 +268,6 @@ unsafe fn try_no_ret<F: FnOnce()>(closure: F) -> Result<(), Option<Id<Exception>
/// technically possible on some systems with `@throw nil`, or in OOM
/// situations.
///
/// [`catch_unwind`]: std::panic::catch_unwind
///
///
/// # Safety
///
Expand All @@ -286,8 +289,8 @@ pub unsafe fn catch<R>(
*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)]
Expand Down
2 changes: 2 additions & 0 deletions crates/objc2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

Expand Down
1 change: 1 addition & 0 deletions crates/objc2/src/rc/test_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions crates/objc2/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<A, R>(&self, sel: Sel) -> Result<(), VerificationError>
where
A: EncodeArguments,
Expand Down

0 comments on commit bdd9d39

Please sign in to comment.