Skip to content

Commit

Permalink
Merge pull request #480 from madsmtm/more-warnings
Browse files Browse the repository at this point in the history
Add more warnings to crate root
  • Loading branch information
madsmtm authored Aug 28, 2023
2 parents b832f25 + b9933b5 commit 7959167
Show file tree
Hide file tree
Showing 34 changed files with 762 additions and 693 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ jobs:
$PUBLIC_CRATES
--features=$INTERESTING_FEATURES
--features=$LATEST_MACOS_FEATURE
env:
RUSTFLAGS: "--codegen=debuginfo=0" # Removed --deny=warnings

ui:
name: Compiler UI
Expand Down
4 changes: 4 additions & 0 deletions crates/block-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@

#![no_std]
#![warn(elided_lifetimes_in_paths)]
#![warn(missing_copy_implementations)]
#![deny(non_ascii_idents)]
#![warn(unreachable_pub)]
#![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 Expand Up @@ -291,6 +294,7 @@ pub struct Block_layout {
}

#[repr(C)]
#[allow(missing_copy_implementations)]
pub struct Block_descriptor_header {
/// Reserved for future use. Currently always 0.
pub reserved: c_ulong, // usize
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
4 changes: 4 additions & 0 deletions crates/block2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@

#![no_std]
#![warn(elided_lifetimes_in_paths)]
#![warn(missing_copy_implementations)]
#![warn(missing_debug_implementations)]
#![warn(missing_docs)]
#![deny(non_ascii_idents)]
#![warn(unreachable_pub)]
#![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
1 change: 1 addition & 0 deletions crates/icrate/src/Foundation/__macro_helpers/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use objc2::rc::Id;
use objc2::Message;

/// Allows storing an `Id` in a static and lazily loading it.
#[derive(Debug)]
pub struct CachedId<T> {
ptr: AtomicPtr<T>,
}
Expand Down
4 changes: 4 additions & 0 deletions crates/icrate/src/Foundation/__macro_helpers/ns_string.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(feature = "Foundation_NSString")]
#![allow(missing_copy_implementations)]
//! Macro for making a static NSString.
//!
//! This closely follows what clang does, see:
Expand Down Expand Up @@ -37,6 +38,7 @@ extern "C" {
/// [`CFRuntimeBase`]: <https://github.com/apple-oss-distributions/CF/blob/CF-1153.18/CFRuntime.h#L216-L228>
/// [`CF_CONST_STRING`]: <https://github.com/apple-oss-distributions/CF/blob/CF-1153.18/CFInternal.h#L332-L336>
#[repr(C)]
#[derive(Debug)]
pub struct CFConstString {
isa: &'static AnyClass,
// Important that we don't use `usize` here, since that would be wrong on
Expand Down Expand Up @@ -118,6 +120,7 @@ pub const fn is_ascii_no_nul(bytes: &[u8]) -> bool {
true
}

#[derive(Debug)]
pub struct Utf16Char {
pub repr: [u16; 2],
pub len: usize,
Expand Down Expand Up @@ -147,6 +150,7 @@ impl Utf16Char {
}
}

#[derive(Debug)]
pub struct EncodeUtf16Iter {
str: &'static [u8],
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions crates/icrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#![no_std]
#![cfg_attr(feature = "unstable-docsrs", feature(doc_auto_cfg))]
#![warn(elided_lifetimes_in_paths)]
#![warn(missing_copy_implementations)]
#![warn(missing_debug_implementations)]
#![deny(non_ascii_idents)]
#![warn(unreachable_pub)]
#![deny(unsafe_op_in_unsafe_fn)]
Expand Down
1 change: 1 addition & 0 deletions crates/objc-sys/src/image_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// only used behind experimental features (`unstable-static-*`).
#[repr(C)]
#[doc(hidden)]
#[allow(missing_copy_implementations)]
pub struct __ImageInfo {
// These are not actually `unsigned int`, even though the docs say so
/// The version of the image info struct.
Expand Down
3 changes: 3 additions & 0 deletions crates/objc-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@

#![no_std]
#![warn(elided_lifetimes_in_paths)]
#![warn(missing_copy_implementations)]
#![deny(non_ascii_idents)]
#![warn(unreachable_pub)]
#![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
3 changes: 2 additions & 1 deletion crates/objc2-encode/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ use crate::EncodingBox;
/// use objc2_encode::Encoding;
/// assert!(Encoding::Array(10, &Encoding::FloatComplex).equivalent_to_str("[10jf]"));
/// ```
// Not `Copy`, since this may one day contain `Box`
// Not `Copy`, since this may one day be merged with `EncodingBox`
#[allow(missing_copy_implementations)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
// See <https://en.cppreference.com/w/c/language/type>
#[non_exhaustive] // Maybe we're missing some encodings?
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
4 changes: 4 additions & 0 deletions crates/objc2-encode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@

#![no_std]
#![warn(elided_lifetimes_in_paths)]
#![warn(missing_copy_implementations)]
#![warn(missing_debug_implementations)]
#![warn(missing_docs)]
#![deny(non_ascii_idents)]
#![warn(unreachable_pub)]
#![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
4 changes: 4 additions & 0 deletions crates/objc2-proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@

#![warn(elided_lifetimes_in_paths)]
#![warn(missing_docs)]
#![warn(missing_copy_implementations)]
#![warn(missing_debug_implementations)]
#![deny(non_ascii_idents)]
#![warn(unreachable_pub)]
#![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
2 changes: 2 additions & 0 deletions crates/objc2/src/__macro_helpers/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::ffi;
use crate::runtime::{AnyClass, Sel};

/// Allows storing a [`Sel`] in a static and lazily loading it.
#[derive(Debug)]
pub struct CachedSel {
ptr: AtomicPtr<ffi::objc_selector>,
}
Expand Down Expand Up @@ -52,6 +53,7 @@ impl CachedSel {
}

/// Allows storing a [`AnyClass`] reference in a static and lazily loading it.
#[derive(Debug)]
pub struct CachedClass {
ptr: AtomicPtr<AnyClass>,
}
Expand Down
3 changes: 3 additions & 0 deletions crates/objc2/src/__macro_helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub use self::declare_class::{
///
/// <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#retainable-object-pointers-as-operands-and-arguments>
// TODO: Use an enum instead of u8 here when stable
#[derive(Debug)]
pub struct RetainSemantics<const INNER: u8> {}

pub type New = RetainSemantics<1>;
Expand Down Expand Up @@ -425,6 +426,7 @@ const fn in_selector_family(mut selector: &[u8], mut family: &[u8]) -> bool {
///
/// <https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/CodeGen/CGObjCMac.cpp#L5211-L5234>
#[repr(C)]
#[derive(Debug)]
pub struct ModuleInfo {
version: usize,
size: usize,
Expand Down Expand Up @@ -496,6 +498,7 @@ impl ClassBuilder {
/// - Only methods on the protocol are overriden.
/// - TODO: The methods have the correct signature.
/// - All required methods are overridden.
#[derive(Debug)]
pub struct ClassProtocolMethodsBuilder<'a, 'b> {
builder: &'a mut ClassBuilder,
#[allow(unused)]
Expand Down
2 changes: 2 additions & 0 deletions crates/objc2/src/declare/ivar_bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use super::InnerIvarType;
/// so using C99 `_Bool`; if you want to use `BOOL` in Objective-C, you should
/// use `IvarEncode<Bool>`.
#[repr(transparent)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub struct IvarBool(bool);

unsafe impl Encode for IvarBool {
Expand Down
1 change: 1 addition & 0 deletions crates/objc2/src/declare/ivar_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod private {
///
/// Further may be added when the standard library guarantee their layout.
#[repr(transparent)]
#[allow(missing_debug_implementations)]
pub struct IvarDrop<T: private::IvarDropHelper>(<T as private::IvarDropHelper>::Inner);

impl<T: private::IvarDropHelper> super::ivar::private::Sealed for IvarDrop<T> {}
Expand Down
1 change: 1 addition & 0 deletions crates/objc2/src/declare/ivar_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use super::InnerIvarType;
// Note: We put the inner type in a `MaybeUninit`, since we may need to access
// this type before the inner type has been properly initialized.
#[repr(transparent)]
#[allow(missing_debug_implementations)]
pub struct IvarEncode<T>(MaybeUninit<T>);

// We intentionally don't implement `Drop`, since that may happen before the
Expand Down
12 changes: 7 additions & 5 deletions crates/objc2/src/declare/ivar_forwarding_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use core::fmt;
use core::future::Future;
use core::hash;
use core::iter::FusedIterator;
use core::ops::{Deref, DerefMut};
use core::ops::Deref;
use core::pin::Pin;
use core::task::{Context, Poll};
use std::error::Error;
Expand Down Expand Up @@ -192,25 +192,27 @@ impl<I: IvarType> FusedIterator for Ivar<I> where <Self as Deref>::Target: Fused

// impl<T: IvarType> borrow::Borrow<<Self as Deref>::Target> for Ivar<T> {
// fn borrow(&self) -> &<Self as Deref>::Target {
// Deref::deref(self)
// self
// }
// }
//
// impl<T: IvarType> borrow::BorrowMut<<Self as Deref>::Target> for Ivar<T> {
// fn borrow_mut(&mut self) -> &mut <Self as Deref>::Target {
// DerefMut::deref_mut(self)
// self
// }
// }

impl<T: IvarType> AsRef<<Self as Deref>::Target> for Ivar<T> {
fn as_ref(&self) -> &<Self as Deref>::Target {
Deref::deref(self)
// Auto-derefs
self
}
}

impl<T: IvarType> AsMut<<Self as Deref>::Target> for Ivar<T> {
fn as_mut(&mut self) -> &mut <Self as Deref>::Target {
DerefMut::deref_mut(self)
// Auto-derefs
self
}
}

Expand Down
Loading

0 comments on commit 7959167

Please sign in to comment.