Skip to content

Commit 3b3ad3c

Browse files
committed
Use common macro helpers
1 parent ee3c19e commit 3b3ad3c

File tree

8 files changed

+29
-35
lines changed

8 files changed

+29
-35
lines changed

objc2/src/__macro_helpers.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ use crate::{Message, MessageArguments, MessageReceiver};
66
pub use crate::cache::CachedClass;
77
pub use crate::cache::CachedSel;
88

9+
pub use core::borrow::{Borrow, BorrowMut};
910
pub use core::cell::UnsafeCell;
11+
pub use core::convert::{AsMut, AsRef};
12+
pub use core::ops::{Deref, DerefMut};
1013
pub use core::option::Option::{self, None, Some};
1114
pub use core::primitive::{bool, str, u8};
1215
pub use core::{compile_error, concat, panic, stringify};
1316
#[cfg(feature = "objc2-proc-macros")]
1417
pub use objc2_proc_macros::__hash_idents;
18+
// TODO: Use `core::cell::LazyCell`
19+
pub use std::sync::Once;
1520

1621
// Common selectors.
1722
//

objc2/src/macros/ns_string.rs renamed to objc2/src/foundation/__ns_string.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ macro_rules! __ns_string_inner {
354354
// The full UTF-16 contents along with the written length.
355355
const UTF16_FULL: (&[u16; $inp.len()], usize) = {
356356
let mut out = [0u16; $inp.len()];
357-
let mut iter = $crate::__string_macro::EncodeUtf16Iter::new($inp);
357+
let mut iter = $crate::foundation::__ns_string::EncodeUtf16Iter::new($inp);
358358
let mut written = 0;
359359

360360
while let Some((state, chars)) = iter.next() {
@@ -395,17 +395,17 @@ macro_rules! __ns_string_inner {
395395
// The section is the same as what clang sets, see:
396396
// https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/CodeGen/CodeGenModule.cpp#L5243
397397
#[link_section = "__DATA,__cfstring"]
398-
static CFSTRING: $crate::__string_macro::CFConstString = unsafe {
399-
if $crate::__string_macro::is_ascii_no_nul($inp) {
398+
static CFSTRING: $crate::foundation::__ns_string::CFConstString = unsafe {
399+
if $crate::foundation::__ns_string::is_ascii_no_nul($inp) {
400400
// This is technically an optimization (UTF-16 strings are
401401
// always valid), but it's a fairly important one!
402-
$crate::__string_macro::CFConstString::new_ascii(
403-
&$crate::__string_macro::__CFConstantStringClassReference,
402+
$crate::foundation::__ns_string::CFConstString::new_ascii(
403+
&$crate::foundation::__ns_string::__CFConstantStringClassReference,
404404
&ASCII,
405405
)
406406
} else {
407-
$crate::__string_macro::CFConstString::new_utf16(
408-
&$crate::__string_macro::__CFConstantStringClassReference,
407+
$crate::foundation::__ns_string::CFConstString::new_utf16(
408+
&$crate::foundation::__ns_string::__CFConstantStringClassReference,
409409
&UTF16,
410410
)
411411
}
@@ -418,7 +418,7 @@ macro_rules! __ns_string_inner {
418418
#[macro_export]
419419
macro_rules! __ns_string_inner {
420420
($inp:ident) => {{
421-
use $crate::__string_macro::CachedNSString;
421+
use $crate::foundation::__ns_string::CachedNSString;
422422
static CACHED_NSSTRING: CachedNSString = CachedNSString::new();
423423
CACHED_NSSTRING.get($inp)
424424
}};
@@ -508,7 +508,7 @@ mod tests {
508508
"\0",
509509
"\0\x01\x02\x03\x04\x05\x06\x07\x08\x09",
510510
// "\u{feff}", // TODO
511-
include_str!("ns_string.rs"),
511+
include_str!("__ns_string.rs"),
512512
}
513513
}
514514

objc2/src/foundation/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ extern "C" {}
6262
#[link(name = "gnustep-base", kind = "dylib")]
6363
extern "C" {}
6464

65+
#[doc(hidden)]
66+
pub mod __ns_string;
6567
mod array;
6668
mod attributed_string;
6769
mod comparison_result;

objc2/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,6 @@ mod test_utils;
219219
#[cfg(feature = "malloc")]
220220
mod verify;
221221

222-
// Hack to make foundation work for now
223-
#[doc(hidden)]
224-
pub extern crate core as __core;
225-
#[doc(hidden)]
226-
pub extern crate std as __std;
227-
#[doc(hidden)]
228-
#[cfg(feature = "foundation")]
229-
pub use self::macros::ns_string as __string_macro;
230-
231222
// Hack to make doctests work
232223
#[cfg(all(feature = "apple", feature = "unstable-static-class"))]
233224
#[link(name = "Foundation", kind = "framework")]

objc2/src/macros.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
mod declare_class;
22
mod extern_class;
3-
#[doc(hidden)]
4-
#[cfg(feature = "foundation")]
5-
pub mod ns_string;
63

74
/// Gets a reference to a [`Class`] from the given name.
85
///

objc2/src/macros/declare_class.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,7 @@ macro_rules! declare_class {
511511
)]
512512
// TODO: Allow users to configure this?
513513
$v fn class() -> &'static $crate::runtime::Class {
514-
// TODO: Use `core::cell::LazyCell`
515-
use $crate::__std::sync::Once;
514+
use $crate::__macro_helpers::Once;
516515

517516
use $crate::declare::ClassBuilder;
518517
use $crate::runtime::{Class, Protocol};

objc2/src/macros/extern_class.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ macro_rules! extern_class {
127127
macro_rules! __impl_as_ref_borrow {
128128
($name:ident<$($t:ident $(: $b:ident)?),*>,) => {};
129129
($name:ident<$($t:ident $(: $b:ident)?),*>, $item:ty, $($tail:ty,)*) => {
130-
impl<$($t $(: $b)?),*> $crate::__core::convert::AsRef<$item> for $name<$($t),*> {
130+
impl<$($t $(: $b)?),*> $crate::__macro_helpers::AsRef<$item> for $name<$($t),*> {
131131
#[inline]
132132
fn as_ref(&self) -> &$item {
133133
// Triggers Deref coercion depending on return type
134134
&*self
135135
}
136136
}
137137

138-
impl<$($t $(: $b)?),*> $crate::__core::convert::AsMut<$item> for $name<$($t),*> {
138+
impl<$($t $(: $b)?),*> $crate::__macro_helpers::AsMut<$item> for $name<$($t),*> {
139139
#[inline]
140140
fn as_mut(&mut self) -> &mut $item {
141141
// Triggers DerefMut coercion depending on return type
@@ -149,15 +149,15 @@ macro_rules! __impl_as_ref_borrow {
149149
// In particular, `Eq`, `Ord` and `Hash` all give the same results
150150
// after borrow.
151151

152-
impl<$($t $(: $b)?),*> $crate::__core::borrow::Borrow<$item> for $name<$($t),*> {
152+
impl<$($t $(: $b)?),*> $crate::__macro_helpers::Borrow<$item> for $name<$($t),*> {
153153
#[inline]
154154
fn borrow(&self) -> &$item {
155155
// Triggers Deref coercion depending on return type
156156
&*self
157157
}
158158
}
159159

160-
impl<$($t $(: $b)?),*> $crate::__core::borrow::BorrowMut<$item> for $name<$($t),*> {
160+
impl<$($t $(: $b)?),*> $crate::__macro_helpers::BorrowMut<$item> for $name<$($t),*> {
161161
#[inline]
162162
fn borrow_mut(&mut self) -> &mut $item {
163163
// Triggers Deref coercion depending on return type
@@ -253,7 +253,7 @@ macro_rules! __inner_extern_class {
253253
// Note that you can easily have two different variables pointing to
254254
// the same object, `x: &T` and `y: &T::Target`, and this would be
255255
// perfectly safe!
256-
impl<$($t $(: $b)?),*> $crate::__core::ops::Deref for $name<$($t),*> {
256+
impl<$($t $(: $b)?),*> $crate::__macro_helpers::Deref for $name<$($t),*> {
257257
type Target = $superclass;
258258

259259
#[inline]
@@ -273,21 +273,21 @@ macro_rules! __inner_extern_class {
273273
// But `&mut NSMutableString` -> `&mut NSString` safe, since the
274274
// `NSCopying` implementation of `NSMutableString` is used, and that
275275
// is guaranteed to return a different object.
276-
impl<$($t $(: $b)?),*> $crate::__core::ops::DerefMut for $name<$($t),*> {
276+
impl<$($t $(: $b)?),*> $crate::__macro_helpers::DerefMut for $name<$($t),*> {
277277
#[inline]
278278
fn deref_mut(&mut self) -> &mut Self::Target {
279279
&mut self.__inner
280280
}
281281
}
282282

283-
impl<$($t $(: $b)?),*> $crate::__core::convert::AsRef<Self> for $name<$($t),*> {
283+
impl<$($t $(: $b)?),*> $crate::__macro_helpers::AsRef<Self> for $name<$($t),*> {
284284
#[inline]
285285
fn as_ref(&self) -> &Self {
286286
self
287287
}
288288
}
289289

290-
impl<$($t $(: $b)?),*> $crate::__core::convert::AsMut<Self> for $name<$($t),*> {
290+
impl<$($t $(: $b)?),*> $crate::__macro_helpers::AsMut<Self> for $name<$($t),*> {
291291
#[inline]
292292
fn as_mut(&mut self) -> &mut Self {
293293
self

test-ui/ui/nsvalue_f32_not_eq.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0277]: the trait bound `f32: std::cmp::Eq` is not satisfied
1+
error[E0277]: the trait bound `f32: Eq` is not satisfied
22
--> ui/nsvalue_f32_not_eq.rs
33
|
44
| needs_eq::<NSValue<f32>>();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `f32`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq` is not implemented for `f32`
66
|
7-
= help: the following other types implement trait `std::cmp::Eq`:
7+
= help: the following other types implement trait `Eq`:
88
i128
99
i16
1010
i32
@@ -14,7 +14,7 @@ error[E0277]: the trait bound `f32: std::cmp::Eq` is not satisfied
1414
u128
1515
u16
1616
and 4 others
17-
= note: required because of the requirements on the impl of `std::cmp::Eq` for `NSValue<f32>`
17+
= note: required because of the requirements on the impl of `Eq` for `NSValue<f32>`
1818
note: required by a bound in `needs_eq`
1919
--> ui/nsvalue_f32_not_eq.rs
2020
|

0 commit comments

Comments
 (0)