Skip to content

Commit bdd9d39

Browse files
committed
Add missing error and panic docs
1 parent a9c569b commit bdd9d39

File tree

12 files changed

+32
-5
lines changed

12 files changed

+32
-5
lines changed

crates/block-sys/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#![deny(unsafe_op_in_unsafe_fn)]
2121
#![warn(clippy::cargo)]
2222
#![warn(clippy::ptr_as_ptr)]
23+
#![warn(clippy::missing_errors_doc)]
24+
#![warn(clippy::missing_panics_doc)]
2325
// Update in Cargo.toml as well.
2426
#![doc(html_root_url = "https://docs.rs/block-sys/0.2.0")]
2527
#![cfg_attr(feature = "unstable-docsrs", feature(doc_auto_cfg, doc_cfg_hide))]

crates/block2/src/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<A: BlockArguments, R: EncodeReturn> Block<A, R> {
116116
let ptr: *const Self = self;
117117
let layout = unsafe { ptr.cast::<ffi::Block_layout>().as_ref().unwrap_unchecked() };
118118
// TODO: Is `invoke` actually ever null?
119-
let invoke = layout.invoke.unwrap();
119+
let invoke = layout.invoke.unwrap_or_else(|| unreachable!());
120120

121121
unsafe { A::__call_block(invoke, ptr as *mut Self, args) }
122122
}

crates/block2/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
#![deny(unsafe_op_in_unsafe_fn)]
8585
#![warn(clippy::cargo)]
8686
#![warn(clippy::ptr_as_ptr)]
87+
#![warn(clippy::missing_errors_doc)]
88+
#![warn(clippy::missing_panics_doc)]
8789
// Update in Cargo.toml as well.
8890
#![doc(html_root_url = "https://docs.rs/block2/0.3.0")]
8991

crates/objc-sys/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#![deny(unsafe_op_in_unsafe_fn)]
2222
#![warn(clippy::cargo)]
2323
#![warn(clippy::ptr_as_ptr)]
24+
#![warn(clippy::missing_errors_doc)]
25+
#![warn(clippy::missing_panics_doc)]
2426
#![allow(clippy::upper_case_acronyms)]
2527
#![allow(non_camel_case_types)]
2628
#![allow(non_upper_case_globals)]

crates/objc2-encode/src/encoding_box.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ impl EncodingBox {
111111
/// returned by `method_getTypeEncoding`.
112112
///
113113
/// [`from_str`][Self::from_str] is simpler, use that instead if you can.
114+
///
115+
///
116+
/// # Errors
117+
///
118+
/// Returns an error if the string was an ill-formatted encoding string.
114119
pub fn from_start_of_str(s: &mut &str) -> Result<Self, ParseError> {
115120
let mut parser = Parser::new(s);
116121
parser.strip_leading_qualifiers();

crates/objc2-encode/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#![deny(unsafe_op_in_unsafe_fn)]
4646
#![warn(clippy::cargo)]
4747
#![warn(clippy::ptr_as_ptr)]
48+
#![warn(clippy::missing_errors_doc)]
49+
#![warn(clippy::missing_panics_doc)]
4850
// Update in Cargo.toml as well.
4951
#![doc(html_root_url = "https://docs.rs/objc2-encode/3.0.0")]
5052
#![cfg_attr(feature = "unstable-c-unwind", feature(c_unwind))]

crates/objc2-proc-macros/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#![deny(unsafe_op_in_unsafe_fn)]
1313
#![warn(clippy::cargo)]
1414
#![warn(clippy::ptr_as_ptr)]
15+
#![warn(clippy::missing_errors_doc)]
16+
#![warn(clippy::missing_panics_doc)]
1517
// Update in Cargo.toml as well.
1618
#![doc(html_root_url = "https://docs.rs/objc2-proc-macros/0.1.1")]
1719

crates/objc2/src/declare/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,11 @@ impl ProtocolBuilder {
666666
/// Constructs a [`ProtocolBuilder`] with the given name.
667667
///
668668
/// Returns [`None`] if the protocol couldn't be allocated.
669+
///
670+
///
671+
/// # Panics
672+
///
673+
/// Panics if the name contains an internal NULL byte.
669674
pub fn new(name: &str) -> Option<Self> {
670675
let c_name = CString::new(name).unwrap();
671676
let proto = unsafe { ffi::objc_allocateProtocol(c_name.as_ptr()) };

crates/objc2/src/exception.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ unsafe fn try_no_ret<F: FnOnce()>(closure: F) -> Result<(), Option<Id<Exception>
254254
/// Accordingly, if your Rust code is compiled with `panic=abort` this cannot
255255
/// catch the exception.
256256
///
257+
/// [`catch_unwind`]: std::panic::catch_unwind
258+
///
259+
///
260+
/// # Errors
261+
///
257262
/// Returns a `Result` that is either `Ok` if the closure succeeded without an
258263
/// exception being thrown, or an `Err` with the exception. The exception is
259264
/// automatically released.
@@ -263,8 +268,6 @@ unsafe fn try_no_ret<F: FnOnce()>(closure: F) -> Result<(), Option<Id<Exception>
263268
/// technically possible on some systems with `@throw nil`, or in OOM
264269
/// situations.
265270
///
266-
/// [`catch_unwind`]: std::panic::catch_unwind
267-
///
268271
///
269272
/// # Safety
270273
///
@@ -286,8 +289,8 @@ pub unsafe fn catch<R>(
286289
*value_ref = Some(closure());
287290
};
288291
let result = unsafe { try_no_ret(closure) };
289-
// If the try succeeded, this was set so it's safe to unwrap
290-
result.map(|()| value.unwrap())
292+
// If the try succeeded, value was set so it's safe to unwrap
293+
result.map(|()| value.unwrap_or_else(|| unreachable!()))
291294
}
292295

293296
#[cfg(test)]

crates/objc2/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@
167167
#![deny(unsafe_op_in_unsafe_fn)]
168168
#![warn(clippy::cargo)]
169169
#![warn(clippy::ptr_as_ptr)]
170+
#![warn(clippy::missing_errors_doc)]
171+
#![warn(clippy::missing_panics_doc)]
170172
// Update in Cargo.toml as well.
171173
#![doc(html_root_url = "https://docs.rs/objc2/0.4.1")]
172174

0 commit comments

Comments
 (0)