Skip to content

Commit

Permalink
Update nightly Rust version
Browse files Browse the repository at this point in the history
Code changes are:
- `static mut` now warns, so we introduce `SyncUnsafeCell` and use that
  instead.
- Rename of "object safe" to "dyn-compatible".
- The rest is Clippy.

UI test changes are:
- Removal of "which is required by ...", the end result is generally
  more readable, and hides more implementation details.
- Removal of "the token" in macro diagnostics. Sometimes use "keyword"
  instead. End result is cleaner.
- `dyn T` shows up in diagnostics without `+ 'static`, which is nice.
- A few more very minor changes.
- Due to Clippy suggesting `'_` instead of an explicit lifetime, a few
  uses of `&` in diagnostics are now cleaner.

There are no assembly test changes.
  • Loading branch information
madsmtm committed Nov 14, 2024
1 parent 72bd716 commit a46ab13
Show file tree
Hide file tree
Showing 49 changed files with 373 additions and 333 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ env:
# END AUTOMATICALLY GENERATED

# The current nightly Rust version. Keep this synced with `rust-toolchain.toml`
CURRENT_NIGHTLY: nightly-2024-09-05
CURRENT_NIGHTLY: nightly-2024-11-14
# Various features that we'd usually want to test with
#
# Note: The `exception` feature is not enabled here, since it requires
Expand Down
10 changes: 5 additions & 5 deletions crates/block2/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ where
}

// Basic constants and helpers.
impl<'f, A, R, Closure> StackBlock<'f, A, R, Closure> {
impl<A, R, Closure> StackBlock<'_, A, R, Closure> {
/// The size of the block header and the trailing closure.
///
/// This ensures that the closure that the block contains is also moved to
Expand Down Expand Up @@ -108,7 +108,7 @@ impl<'f, A, R, Closure> StackBlock<'f, A, R, Closure> {
}

// `StackBlock::new`
impl<'f, A, R, Closure: Clone> StackBlock<'f, A, R, Closure> {
impl<A, R, Closure: Clone> StackBlock<'_, A, R, Closure> {
// Clone the closure from one block to another.
unsafe extern "C-unwind" fn clone_closure(dst: *mut c_void, src: *const c_void) {
let dst: *mut Self = dst.cast();
Expand Down Expand Up @@ -446,7 +446,7 @@ where
};
}

impl<'f, A, R, Closure: Clone> Clone for StackBlock<'f, A, R, Closure> {
impl<A, R, Closure: Clone> Clone for StackBlock<'_, A, R, Closure> {
#[inline]
fn clone(&self) -> Self {
Self {
Expand All @@ -457,7 +457,7 @@ impl<'f, A, R, Closure: Clone> Clone for StackBlock<'f, A, R, Closure> {
}
}

impl<'f, A, R, Closure: Copy> Copy for StackBlock<'f, A, R, Closure> {}
impl<A, R, Closure: Copy> Copy for StackBlock<'_, A, R, Closure> {}

impl<'f, A, R, Closure> Deref for StackBlock<'f, A, R, Closure>
where
Expand All @@ -481,7 +481,7 @@ where
}
}

impl<'f, A, R, Closure> fmt::Debug for StackBlock<'f, A, R, Closure> {
impl<A, R, Closure> fmt::Debug for StackBlock<'_, A, R, Closure> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut f = f.debug_struct("StackBlock");
debug_block_header(&self.header, &mut f);
Expand Down
2 changes: 1 addition & 1 deletion crates/header-translator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl<'de> Deserialize<'de> for Counterpart {

struct CounterpartVisitor;

impl<'de> de::Visitor<'de> for CounterpartVisitor {
impl de::Visitor<'_> for CounterpartVisitor {
type Value = Counterpart;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion crates/header-translator/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub enum LocationLibrary<'location, 'config> {
},
}

impl<'location, 'config> LocationLibrary<'location, 'config> {
impl<'config> LocationLibrary<'_, 'config> {
pub fn krate(&self) -> Option<(&'config str, bool)> {
match self {
Self::System => None,
Expand Down
2 changes: 2 additions & 0 deletions crates/objc2/src/__macro_helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod module_info;
mod msg_send;
mod msg_send_retained;
mod os_version;
mod sync_unsafe_cell;
mod writeback;

pub use self::cache::{CachedClass, CachedSel};
Expand All @@ -41,6 +42,7 @@ pub use self::module_info::ModuleInfo;
pub use self::msg_send::MsgSend;
pub use self::msg_send_retained::{MaybeUnwrap, MsgSendId, MsgSendSuperId};
pub use self::os_version::{is_available, AvailableVersion, OSVersion};
pub use self::sync_unsafe_cell::SyncUnsafeCell;

/// Disallow using this passed in value in const and statics for forwards
/// compatibility (this function is not a `const` function).
Expand Down
2 changes: 1 addition & 1 deletion crates/objc2/src/__macro_helpers/msg_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<T: MessageReceiver> MsgSend for T {
}
}

impl<'a, T: ?Sized + Message> MsgSend for &'a Retained<T> {
impl<T: ?Sized + Message> MsgSend for &Retained<T> {
type Inner = T;

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion crates/objc2/src/__macro_helpers/msg_send_retained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl<'a> MsgSendIdFailed<'a> for New {
}
}

impl<'a> MsgSendIdFailed<'a> for Alloc {
impl MsgSendIdFailed<'_> for Alloc {
type Args = ();

#[cold]
Expand Down
32 changes: 32 additions & 0 deletions crates/objc2/src/__macro_helpers/sync_unsafe_cell.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use core::cell::UnsafeCell;

#[repr(transparent)]
#[derive(Debug)]
pub struct SyncUnsafeCell<T: ?Sized> {
value: UnsafeCell<T>,
}

// SAFETY: This type is used for making `static`s which contain `UnsafeCell`.
// The user upholds that such usage is correct.
unsafe impl<T: ?Sized + Sync> Sync for SyncUnsafeCell<T> {}

impl<T> SyncUnsafeCell<T> {
#[inline]
pub const fn new(value: T) -> Self {
Self {
value: UnsafeCell::new(value),
}
}

#[inline]
pub fn into_inner(self) -> T {
self.value.into_inner()
}
}

impl<T: ?Sized> SyncUnsafeCell<T> {
#[inline]
pub const fn get(&self) -> *mut T {
self.value.get()
}
}
4 changes: 2 additions & 2 deletions crates/objc2/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,8 @@ encode_pointer_impls!(
);

// SAFETY: References and `NonNull` have a NULL niche
unsafe impl<'a, T: RefEncode + ?Sized> OptionEncode for &'a T {}
unsafe impl<'a, T: RefEncode + ?Sized> OptionEncode for &'a mut T {}
unsafe impl<T: RefEncode + ?Sized> OptionEncode for &T {}
unsafe impl<T: RefEncode + ?Sized> OptionEncode for &mut T {}
unsafe impl<T: RefEncode + ?Sized> OptionEncode for NonNull<T> {}

/// Helper for implementing [`Encode`]/[`RefEncode`] for function pointers
Expand Down
24 changes: 15 additions & 9 deletions crates/objc2/src/macros/declare_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,15 @@ macro_rules! declare_class {

// Anonymous block to hide the shared statics
const _: () = {
static mut __OBJC2_CLASS: $crate::__macro_helpers::MaybeUninit<&'static $crate::runtime::AnyClass> = $crate::__macro_helpers::MaybeUninit::uninit();
static mut __OBJC2_IVAR_OFFSET: $crate::__macro_helpers::MaybeUninit<$crate::__macro_helpers::isize> = $crate::__macro_helpers::MaybeUninit::uninit();
static mut __OBJC2_DROP_FLAG_OFFSET: $crate::__macro_helpers::MaybeUninit<$crate::__macro_helpers::isize> = $crate::__macro_helpers::MaybeUninit::uninit();
static __OBJC2_CLASS: $crate::__macro_helpers::SyncUnsafeCell<
$crate::__macro_helpers::MaybeUninit<&'static $crate::runtime::AnyClass>
> = $crate::__macro_helpers::SyncUnsafeCell::new($crate::__macro_helpers::MaybeUninit::uninit());
static __OBJC2_IVAR_OFFSET: $crate::__macro_helpers::SyncUnsafeCell<
$crate::__macro_helpers::MaybeUninit<$crate::__macro_helpers::isize>
> = $crate::__macro_helpers::SyncUnsafeCell::new($crate::__macro_helpers::MaybeUninit::uninit());
static __OBJC2_DROP_FLAG_OFFSET: $crate::__macro_helpers::SyncUnsafeCell<
$crate::__macro_helpers::MaybeUninit<$crate::__macro_helpers::isize>
> = $crate::__macro_helpers::SyncUnsafeCell::new($crate::__macro_helpers::MaybeUninit::uninit());

// Creation
unsafe impl ClassType for $for_class {
Expand Down Expand Up @@ -458,18 +464,18 @@ macro_rules! declare_class {
// SAFETY: Modification is ensured by `Once` to happen
// before any access to the variables.
unsafe {
__OBJC2_CLASS.write(__objc2_cls);
__OBJC2_CLASS.get().write($crate::__macro_helpers::MaybeUninit::new(__objc2_cls));
if <Self as $crate::__macro_helpers::DeclaredIvarsHelper>::HAS_IVARS {
__OBJC2_IVAR_OFFSET.write(__objc2_ivar_offset);
__OBJC2_IVAR_OFFSET.get().write($crate::__macro_helpers::MaybeUninit::new(__objc2_ivar_offset));
}
if <Self as $crate::__macro_helpers::DeclaredIvarsHelper>::HAS_DROP_FLAG {
__OBJC2_DROP_FLAG_OFFSET.write(__objc2_drop_flag_offset);
__OBJC2_DROP_FLAG_OFFSET.get().write($crate::__macro_helpers::MaybeUninit::new(__objc2_drop_flag_offset));
}
}
});

// SAFETY: We just registered the class, so is now available
unsafe { __OBJC2_CLASS.assume_init() }
unsafe { __OBJC2_CLASS.get().read().assume_init() }
}

#[inline]
Expand All @@ -492,7 +498,7 @@ macro_rules! declare_class {
if <Self as $crate::__macro_helpers::DeclaredIvarsHelper>::HAS_IVARS {
// SAFETY: Accessing the offset is guaranteed to only be
// done after the class has been initialized.
unsafe { __OBJC2_IVAR_OFFSET.assume_init() }
unsafe { __OBJC2_IVAR_OFFSET.get().read().assume_init() }
} else {
// Fall back to an offset of zero.
//
Expand All @@ -506,7 +512,7 @@ macro_rules! declare_class {
fn __drop_flag_offset() -> $crate::__macro_helpers::isize {
if <Self as $crate::__macro_helpers::DeclaredIvarsHelper>::HAS_DROP_FLAG {
// SAFETY: Same as above.
unsafe { __OBJC2_DROP_FLAG_OFFSET.assume_init() }
unsafe { __OBJC2_DROP_FLAG_OFFSET.get().read().assume_init() }
} else {
// Fall back to an offset of zero.
//
Expand Down
15 changes: 6 additions & 9 deletions crates/objc2/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,6 @@ macro_rules! __statics_sel {
/// Clang does this by marking `REF` with LLVM's
/// `externally_initialized`.
///
/// `static mut` is used so that we don't need to wrap the
/// `UnsafeCell` in something that implements `Sync`.
///
///
/// # Safety
///
Expand All @@ -452,8 +449,8 @@ macro_rules! __statics_sel {
link_section = "__OBJC,__message_refs,literal_pointers,no_dead_strip",
)]
#[export_name = $crate::__macro_helpers::concat!("\x01L_OBJC_SELECTOR_REFERENCES_", $hash)]
static mut REF: $crate::__macro_helpers::UnsafeCell<$crate::runtime::Sel> = unsafe {
$crate::__macro_helpers::UnsafeCell::new($crate::runtime::Sel::__internal_from_ptr(NAME_DATA.as_ptr()))
static REF: $crate::__macro_helpers::SyncUnsafeCell<$crate::runtime::Sel> = unsafe {
$crate::__macro_helpers::SyncUnsafeCell::new($crate::runtime::Sel::__internal_from_ptr(NAME_DATA.as_ptr()))
};

$crate::__statics_image_info!($hash);
Expand Down Expand Up @@ -512,8 +509,8 @@ macro_rules! __statics_class {
"\x01L_OBJC_CLASSLIST_REFERENCES_$_",
$hash,
)]
static mut REF: $crate::__macro_helpers::UnsafeCell<&$crate::runtime::AnyClass> = unsafe {
$crate::__macro_helpers::UnsafeCell::new(&CLASS)
static REF: $crate::__macro_helpers::SyncUnsafeCell<&$crate::runtime::AnyClass> = unsafe {
$crate::__macro_helpers::SyncUnsafeCell::new(&CLASS)
};

$crate::__statics_image_info!($hash);
Expand Down Expand Up @@ -544,9 +541,9 @@ macro_rules! __statics_class {
"\x01L_OBJC_CLASS_REFERENCES_",
$hash,
)]
static mut REF: $crate::__macro_helpers::UnsafeCell<&$crate::runtime::AnyClass> = unsafe {
static REF: $crate::__macro_helpers::SyncUnsafeCell<&$crate::runtime::AnyClass> = unsafe {
let ptr: *const $crate::runtime::AnyClass = NAME_DATA.as_ptr().cast();
$crate::__macro_helpers::UnsafeCell::new(&*ptr)
$crate::__macro_helpers::SyncUnsafeCell::new(&*ptr)
};

$crate::__statics_image_info!($hash);
Expand Down
12 changes: 6 additions & 6 deletions crates/objc2/src/runtime/message_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ unsafe impl<T: ?Sized + Message> MessageReceiver for NonNull<T> {
}
}

impl<'a, T: ?Sized + Message> private::Sealed for &'a T {}
unsafe impl<'a, T: ?Sized + Message> MessageReceiver for &'a T {
impl<T: ?Sized + Message> private::Sealed for &T {}
unsafe impl<T: ?Sized + Message> MessageReceiver for &T {
type __Inner = T;

#[inline]
Expand All @@ -520,13 +520,13 @@ unsafe impl<'a, T: ?Sized + Message> MessageReceiver for &'a T {
}
}

impl<'a> private::Sealed for &'a mut AnyObject {}
impl private::Sealed for &mut AnyObject {}
/// `&mut AnyObject` is allowed as mutable, for easier transition from `objc`,
/// even though it's basically always incorrect to hold `&mut AnyObject`.
///
/// Use `*mut AnyObject` instead if you know for certain you need mutability,
/// and cannot make do with interior mutability.
unsafe impl<'a> MessageReceiver for &'a mut AnyObject {
unsafe impl MessageReceiver for &mut AnyObject {
type __Inner = AnyObject;

#[inline]
Expand All @@ -545,8 +545,8 @@ unsafe impl MessageReceiver for *const AnyClass {
}
}

impl<'a> private::Sealed for &'a AnyClass {}
unsafe impl<'a> MessageReceiver for &'a AnyClass {
impl private::Sealed for &AnyClass {}
unsafe impl MessageReceiver for &AnyClass {
type __Inner = AnyClass;

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion crates/objc2/src/runtime/method_encoding_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a> MethodEncodingIter<'a> {
}
}

impl<'a> Iterator for MethodEncodingIter<'a> {
impl Iterator for MethodEncodingIter<'_> {
type Item = Result<(EncodingBox, Option<isize>), EncodingParseError>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion crates/objc2/src/runtime/method_implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod private {
/// This is a sealed trait that is implemented for a lot of `extern "C"`
/// function pointer types.
//
// Note: `Sized` is intentionally added to make the trait not object safe.
// Note: `Sized` is intentionally added to make the trait dyn-incompatible.
pub trait MethodImplementation: private::Sealed + Sized {
/// The callee type of the method.
type Callee: ?Sized + RefEncode;
Expand Down
18 changes: 9 additions & 9 deletions crates/objc2/src/top_level_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,25 +572,25 @@ unsafe impl<P: ?Sized + MainThreadOnly> MainThreadOnly for ProtocolObject<P> {}
/// [`dyn AllocAnyThread`]: AllocAnyThread
/// [`dyn MainThreadOnly`]: MainThreadOnly
pub trait ThreadKind: private::SealedThreadKind {
// To mark `ThreadKind` as not object safe for now.
// To mark `ThreadKind` as dyn-incompatible for now.
#[doc(hidden)]
const __NOT_OBJECT_SAFE: ();
const __DYN_INCOMPATIBLE: ();
}

impl<'a> private::SealedThreadKind for dyn AllocAnyThread + 'a {}
impl<'a> ThreadKind for dyn AllocAnyThread + 'a {
const __NOT_OBJECT_SAFE: () = ();
impl private::SealedThreadKind for dyn AllocAnyThread + '_ {}
impl ThreadKind for dyn AllocAnyThread + '_ {
const __DYN_INCOMPATIBLE: () = ();
}

impl<'a> private::SealedThreadKind for dyn MainThreadOnly + 'a {}
impl<'a> ThreadKind for dyn MainThreadOnly + 'a {
const __NOT_OBJECT_SAFE: () = ();
impl private::SealedThreadKind for dyn MainThreadOnly + '_ {}
impl ThreadKind for dyn MainThreadOnly + '_ {
const __DYN_INCOMPATIBLE: () = ();
}

#[cfg(test)]
mod tests {
use super::*;

#[allow(unused)]
fn object_safe(_: &dyn AllocAnyThread, _: &dyn MainThreadOnly) {}
fn dyn_compatible(_: &dyn AllocAnyThread, _: &dyn MainThreadOnly) {}
}
4 changes: 2 additions & 2 deletions crates/test-ui/ui/add_method_no_bool.stderr

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions crates/test-ui/ui/array_iter_invalid.stderr

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a46ab13

Please sign in to comment.