Skip to content

Commit a46ab13

Browse files
committed
Update nightly Rust version
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.
1 parent 72bd716 commit a46ab13

File tree

49 files changed

+373
-333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+373
-333
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ env:
5555
# END AUTOMATICALLY GENERATED
5656

5757
# The current nightly Rust version. Keep this synced with `rust-toolchain.toml`
58-
CURRENT_NIGHTLY: nightly-2024-09-05
58+
CURRENT_NIGHTLY: nightly-2024-11-14
5959
# Various features that we'd usually want to test with
6060
#
6161
# Note: The `exception` feature is not enabled here, since it requires

crates/block2/src/stack.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ where
7171
}
7272

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

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

449-
impl<'f, A, R, Closure: Clone> Clone for StackBlock<'f, A, R, Closure> {
449+
impl<A, R, Closure: Clone> Clone for StackBlock<'_, A, R, Closure> {
450450
#[inline]
451451
fn clone(&self) -> Self {
452452
Self {
@@ -457,7 +457,7 @@ impl<'f, A, R, Closure: Clone> Clone for StackBlock<'f, A, R, Closure> {
457457
}
458458
}
459459

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

462462
impl<'f, A, R, Closure> Deref for StackBlock<'f, A, R, Closure>
463463
where
@@ -481,7 +481,7 @@ where
481481
}
482482
}
483483

484-
impl<'f, A, R, Closure> fmt::Debug for StackBlock<'f, A, R, Closure> {
484+
impl<A, R, Closure> fmt::Debug for StackBlock<'_, A, R, Closure> {
485485
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
486486
let mut f = f.debug_struct("StackBlock");
487487
debug_block_header(&self.header, &mut f);

crates/header-translator/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl<'de> Deserialize<'de> for Counterpart {
337337

338338
struct CounterpartVisitor;
339339

340-
impl<'de> de::Visitor<'de> for CounterpartVisitor {
340+
impl de::Visitor<'_> for CounterpartVisitor {
341341
type Value = Counterpart;
342342

343343
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {

crates/header-translator/src/id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub enum LocationLibrary<'location, 'config> {
5959
},
6060
}
6161

62-
impl<'location, 'config> LocationLibrary<'location, 'config> {
62+
impl<'config> LocationLibrary<'_, 'config> {
6363
pub fn krate(&self) -> Option<(&'config str, bool)> {
6464
match self {
6565
Self::System => None,

crates/objc2/src/__macro_helpers/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod module_info;
2323
mod msg_send;
2424
mod msg_send_retained;
2525
mod os_version;
26+
mod sync_unsafe_cell;
2627
mod writeback;
2728

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

4547
/// Disallow using this passed in value in const and statics for forwards
4648
/// compatibility (this function is not a `const` function).

crates/objc2/src/__macro_helpers/msg_send.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<T: MessageReceiver> MsgSend for T {
162162
}
163163
}
164164

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

168168
#[inline]

crates/objc2/src/__macro_helpers/msg_send_retained.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl<'a> MsgSendIdFailed<'a> for New {
464464
}
465465
}
466466

467-
impl<'a> MsgSendIdFailed<'a> for Alloc {
467+
impl MsgSendIdFailed<'_> for Alloc {
468468
type Args = ();
469469

470470
#[cold]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use core::cell::UnsafeCell;
2+
3+
#[repr(transparent)]
4+
#[derive(Debug)]
5+
pub struct SyncUnsafeCell<T: ?Sized> {
6+
value: UnsafeCell<T>,
7+
}
8+
9+
// SAFETY: This type is used for making `static`s which contain `UnsafeCell`.
10+
// The user upholds that such usage is correct.
11+
unsafe impl<T: ?Sized + Sync> Sync for SyncUnsafeCell<T> {}
12+
13+
impl<T> SyncUnsafeCell<T> {
14+
#[inline]
15+
pub const fn new(value: T) -> Self {
16+
Self {
17+
value: UnsafeCell::new(value),
18+
}
19+
}
20+
21+
#[inline]
22+
pub fn into_inner(self) -> T {
23+
self.value.into_inner()
24+
}
25+
}
26+
27+
impl<T: ?Sized> SyncUnsafeCell<T> {
28+
#[inline]
29+
pub const fn get(&self) -> *mut T {
30+
self.value.get()
31+
}
32+
}

crates/objc2/src/encode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@ encode_pointer_impls!(
817817
);
818818

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

824824
/// Helper for implementing [`Encode`]/[`RefEncode`] for function pointers

crates/objc2/src/macros/declare_class.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,15 @@ macro_rules! declare_class {
425425

426426
// Anonymous block to hide the shared statics
427427
const _: () = {
428-
static mut __OBJC2_CLASS: $crate::__macro_helpers::MaybeUninit<&'static $crate::runtime::AnyClass> = $crate::__macro_helpers::MaybeUninit::uninit();
429-
static mut __OBJC2_IVAR_OFFSET: $crate::__macro_helpers::MaybeUninit<$crate::__macro_helpers::isize> = $crate::__macro_helpers::MaybeUninit::uninit();
430-
static mut __OBJC2_DROP_FLAG_OFFSET: $crate::__macro_helpers::MaybeUninit<$crate::__macro_helpers::isize> = $crate::__macro_helpers::MaybeUninit::uninit();
428+
static __OBJC2_CLASS: $crate::__macro_helpers::SyncUnsafeCell<
429+
$crate::__macro_helpers::MaybeUninit<&'static $crate::runtime::AnyClass>
430+
> = $crate::__macro_helpers::SyncUnsafeCell::new($crate::__macro_helpers::MaybeUninit::uninit());
431+
static __OBJC2_IVAR_OFFSET: $crate::__macro_helpers::SyncUnsafeCell<
432+
$crate::__macro_helpers::MaybeUninit<$crate::__macro_helpers::isize>
433+
> = $crate::__macro_helpers::SyncUnsafeCell::new($crate::__macro_helpers::MaybeUninit::uninit());
434+
static __OBJC2_DROP_FLAG_OFFSET: $crate::__macro_helpers::SyncUnsafeCell<
435+
$crate::__macro_helpers::MaybeUninit<$crate::__macro_helpers::isize>
436+
> = $crate::__macro_helpers::SyncUnsafeCell::new($crate::__macro_helpers::MaybeUninit::uninit());
431437

432438
// Creation
433439
unsafe impl ClassType for $for_class {
@@ -458,18 +464,18 @@ macro_rules! declare_class {
458464
// SAFETY: Modification is ensured by `Once` to happen
459465
// before any access to the variables.
460466
unsafe {
461-
__OBJC2_CLASS.write(__objc2_cls);
467+
__OBJC2_CLASS.get().write($crate::__macro_helpers::MaybeUninit::new(__objc2_cls));
462468
if <Self as $crate::__macro_helpers::DeclaredIvarsHelper>::HAS_IVARS {
463-
__OBJC2_IVAR_OFFSET.write(__objc2_ivar_offset);
469+
__OBJC2_IVAR_OFFSET.get().write($crate::__macro_helpers::MaybeUninit::new(__objc2_ivar_offset));
464470
}
465471
if <Self as $crate::__macro_helpers::DeclaredIvarsHelper>::HAS_DROP_FLAG {
466-
__OBJC2_DROP_FLAG_OFFSET.write(__objc2_drop_flag_offset);
472+
__OBJC2_DROP_FLAG_OFFSET.get().write($crate::__macro_helpers::MaybeUninit::new(__objc2_drop_flag_offset));
467473
}
468474
}
469475
});
470476

471477
// SAFETY: We just registered the class, so is now available
472-
unsafe { __OBJC2_CLASS.assume_init() }
478+
unsafe { __OBJC2_CLASS.get().read().assume_init() }
473479
}
474480

475481
#[inline]
@@ -492,7 +498,7 @@ macro_rules! declare_class {
492498
if <Self as $crate::__macro_helpers::DeclaredIvarsHelper>::HAS_IVARS {
493499
// SAFETY: Accessing the offset is guaranteed to only be
494500
// done after the class has been initialized.
495-
unsafe { __OBJC2_IVAR_OFFSET.assume_init() }
501+
unsafe { __OBJC2_IVAR_OFFSET.get().read().assume_init() }
496502
} else {
497503
// Fall back to an offset of zero.
498504
//
@@ -506,7 +512,7 @@ macro_rules! declare_class {
506512
fn __drop_flag_offset() -> $crate::__macro_helpers::isize {
507513
if <Self as $crate::__macro_helpers::DeclaredIvarsHelper>::HAS_DROP_FLAG {
508514
// SAFETY: Same as above.
509-
unsafe { __OBJC2_DROP_FLAG_OFFSET.assume_init() }
515+
unsafe { __OBJC2_DROP_FLAG_OFFSET.get().read().assume_init() }
510516
} else {
511517
// Fall back to an offset of zero.
512518
//

0 commit comments

Comments
 (0)