rust: add `assert_sync` function
PATCH 1/1 rust: add `assert_sync` function
Adds a new file compile_assert.rs for asserts during compile time and add the assert_sync function to this file.
This will be used in miscdevice to avoid regression in case a : Send bound falsely gets dropped in the future.
---
For now I've only added the function.
Some things that might make sense to do as well:
- Move static_assert into compile_assert.rs.
- Add assert_sync to prelude.
- Add assert_send as well.
- Use these asserts in various places around the kernel. (I'm not sure where it would make sense)
--- rust/kernel/compile_assert.rs | 24 ++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 2 files changed, 25 insertions(+)
rust/kernel/compile_assert.rs new file +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Compile-time asserts. + +/// Asserts that the given type is [`Sync`]. This check is done at compile time and does nothing +/// at runtime. +/// +/// Note that this is only intended to avoid regressions and for sanity checks. +/// +/// # Examples +/// ``` +/// # use kernel::compile_assert::assert_sync; +/// # use kernel::types::NotThreadSafe; +/// +/// +/// // Do the assertion in a const block to make sure it won't be executed at runtime. +/// const _:() = { +/// assert_sync::<i32>(); // Succeeds because `i32` is Sync +/// // assert_sync::<NotThreadSafe>(); // Fails because `NotThreadSafe` is not `Sync`. +/// }; +/// +/// ``` +#[inline(always)] +pub const fn assert_sync <T : ?Sized +Sync >() {}
rust/kernel/lib.rs +1 -0
@@ -56,6 +56,7 @@pub mod block;#[doc(hidden)] pub mod build_assert; +pub mod compile_assert;pub mod cred;pub mod device;pub mod device_id;
---
base-commit: 7a17bbc1d952057898cb0739e60665908fbb8c72
change-id: 20250607-assert_sync-62fddc5a0adc
Best regards,
Signature · 1 line
Christian Schrefl <[email protected]>
Benno Lossin
reviewerQuoted 9 lines · Christian Schrefl
Adds a new file
compile_assert.rsfor asserts during compile time and add theassert_syncfunction to this file.This will be used in
miscdeviceto avoid regression in case a: Sendbound falsely gets dropped in the future.
Thanks!
Quoted 5 lines
---
For now I've only added the function.Some things that might make sense to do as well:
- Movestatic_assertintocompile_assert.rs.
Sounds reasonable.
Quoted 1 line
- Add
assert_syncto prelude.
I don't think we need to do that. At least not yet.
Quoted 1 line
- Add
assert_sendas well.
Sounds like a good idea.
Quoted 20 lines
- Use these asserts in various places around the kernel. (I'm not sure where it would make sense)
--- rust/kernel/compile_assert.rs | 24 ++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 2 files changed, 25 insertions(+)rust/kernel/compile_assert.rs new file +7
-0@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Compile-time asserts. + +/// Asserts that the given type is [`Sync`]. This check is done at compile time and does nothing +/// at runtime. +///
rust/kernel/compile_assert.rs line 17
Quoted 10 lines
rust/kernel/compile_assert.rs new file +10
-0+/// Note that this is only intended to avoid regressions and for sanity checks. +/// +/// # Examples +/// ``` +/// # use kernel::compile_assert::assert_sync; +/// # use kernel::types::NotThreadSafe; +/// +/// +/// // Do the assertion in a const block to make sure it won't be executed at runtime. +/// const _:() = {
s/_:()/_: ()/
rust/kernel/compile_assert.rs line 19
Quoted 2 lines
rust/kernel/compile_assert.rs new file +2
-0+/// assert_sync::<i32>(); // Succeeds because `i32` is Sync +/// // assert_sync::<NotThreadSafe>(); // Fails because `NotThreadSafe` is not `Sync`.
Can you split this into two examples and mark the failing one with compile_fail?
We also could provide a macro similar to [1].
[1]: https://docs.rs/static_assertions/latest/static_assertions/
---
Cheers,
Benno
Quoted 23 lines
rust/kernel/compile_assert.rs new file +5
-0+/// }; +/// +/// ``` +#[inline(always)] +pub const fn assert_sync <T : ?Sized +Sync >() {}rust/kernel/lib.rs +1
-1@@ -56,6 +56,7 @@pub mod block;#[doc(hidden)] pub mod build_assert; +pub mod compile_assert;pub mod cred;pub mod device;pub mod device_id; ---base-commit:
7a17bbc1d952057898cb0739e60665908fbb8c72
change-id: 20250607-assert_sync-62fddc5a0adcBest regards,
Quoted 16 lines · Benno Lossin
Quoted 9 lines · Christian Schrefl
Adds a new file
compile_assert.rsfor asserts during compile time and add theassert_syncfunction to this file.This will be used in
miscdeviceto avoid regression in case a: Sendbound falsely gets dropped in the future.Thanks!
Quoted 3 lines
---
For now I've only added the function.
Quoted 8 lines
Quoted 2 lines
Some things that might make sense to do as well:
- Movestatic_assertintocompile_assert.rs.Sounds reasonable.
Quoted 1 line
- Add
assert_syncto prelude.I don't think we need to do that. At least not yet.
Alright
Quoted 3 lines
Quoted 1 line
- Add
assert_sendas well.Sounds like a good idea.
Should I already add this in V2 for this series?
Quoted 25 lines
Quoted 25 lines
- Use these asserts in various places around the kernel. (I'm not sure where it would make sense)
--- rust/kernel/compile_assert.rs | 24 ++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 2 files changed, 25 insertions(+)rust/kernel/compile_assert.rs new file +11
-0@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Compile-time asserts. + +/// Asserts that the given type is [`Sync`]. This check is done at compile time and does nothing +/// at runtime. +/// +/// Note that this is only intended to avoid regressions and for sanity checks. +/// +/// # Examples +/// ```
Quoted 8 lines
rust/kernel/compile_assert.rs line 17
Quoted 6 lines
rust/kernel/compile_assert.rs new file +6
-0+/// # use kernel::compile_assert::assert_sync; +/// # use kernel::types::NotThreadSafe; +/// +/// +/// // Do the assertion in a const block to make sure it won't be executed at runtime. +/// const _:() = { s/_:()/_: ()/
Fixed.
Quoted 6 lines
rust/kernel/compile_assert.rs line 19
Quoted 3 lines
rust/kernel/compile_assert.rs new file +2
-0+/// assert_sync::<i32>(); // Succeeds because `i32` is Sync +/// // assert_sync::<NotThreadSafe>(); // Fails because `NotThreadSafe` is not `Sync`. Can you split this into two examples and mark the failing one with
compile_fail?
I've tried it with compile_fail and it didn't work, I think that's not supported in (kernel) doc tests yet.
Quoted 4 lines
We also could provide a macro similar to [1].
[1]: https://docs.rs/static_assertions/latest/static_assertions/
You mean the assert_impl_*! macros?
That might make sense, with macros we would not need to write a const block to ensure its not executed at runtime (although it's probably optimized out anyways). It would also mean that we won't need a assert for every Trait, which seems nice. So a macro sounds pretty good to me.
Cheers
Christian
rust/kernel/compile_assert.rs line 6
Quoted 3 lines · Christian Schrefl
rust/kernel/compile_assert.rs new file +2
-0+/// Asserts that the given type is [`Sync`]. This check is done at compile time and does nothing +/// at runtime.
I would split the second sentence into its own paragraph, so that the "short description" isn't long.
Quoted 1 line
+/// Note that this is only intended to avoid regressions and for sanity checks.
Hmm... I am not sure about this sentence. A macro may want to call this to ensure something that is required for safety, for instance. Is that the "sanity check" part? In any case, it sounds like the sentence could be read as "this is not reliable for "other" things apart from just sanity checks", which may be confusing.
Could we perhaps clarify?
Review
Quoted 2 lines
(quoted diff) +2
-0+/// # Examples +/// ```
Please add a newline between these.
Review
Quoted 2 lines
(quoted diff) +2
-0+/// +///
These newlines should be removed, otherwise they will be rendered.
rust/kernel/compile_assert.rs line 18
Quoted 3 lines
rust/kernel/compile_assert.rs new file +3
-0+/// // Do the assertion in a const block to make sure it won't be executed at runtime. +/// const _:() = { +/// assert_sync::<i32>(); // Succeeds because `i32` is Sync
Sync and please use a period at the end. Also, I would suggest following our usual style and putting it at the top, i.e.
// Succeeds because `i32` is `Sync`.
assert_sync::<i32>();Review
Quoted 2 lines
(quoted diff) +2
-0+/// +/// ```
This one can be removed too.
Cheers,
Miguel
Quoted 2 lines · Christian Schrefl
Should I already add this in V2 for this series?
I would do that in a separate patch (possibly in this series, or later on).
Quoted 2 lines
I've tried it with
compile_failand it didn't work, I think that's not supported in (kernel) doc tests yet.
Yeah, it isn't -- please leave a normal comment to indicate it, so that we can replace it with the real annotation in the future.
Quoted 3 lines
That might make sense, with macros we would not need to write a const block to ensure its not executed at runtime (although it's probably optimized out anyways). It would also mean that
There is nothing to execute, no? It is #[inline(always)], and even if that wasn't enough, we always build with optimizations enabled.
But yeah, if needed, we may want to have macro(s) like that.
Thanks!
Cheers,
Miguel
Benno Lossin
reviewerQuoted 7 lines · Christian Schrefl
Quoted 4 lines · Benno Lossin
Quoted 1 line · Christian Schrefl
- Add
assert_sendas well.Sounds like a good idea.
Should I already add this in V2 for this series?
If you want to then sure, but we can also wait until we have a use-case. Also, let's finish the discussion about the macro idea below.
Quoted 8 lines
Quoted 5 lines
rust/kernel/compile_assert.rs line 19
Quoted 2 lines
rust/kernel/compile_assert.rs new file +2
-0+/// assert_sync::<i32>(); // Succeeds because `i32` is Sync +/// // assert_sync::<NotThreadSafe>(); // Fails because `NotThreadSafe` is not `Sync`. Can you split this into two examples and mark the failing one with
compile_fail?I've tried it with
compile_failand it didn't work, I think that's not supported in (kernel) doc tests yet.
Hmm, I thought that this worked... @Miguel any idea?
Quoted 5 lines
Quoted 3 lines
We also could provide a macro similar to [1].
[1]: https://docs.rs/static_assertions/latest/static_assertions/
You mean the
assert_impl_*!macros?
Yes, but the others might also be useful from time to time.
Quoted 3 lines
That might make sense, with macros we would not need to write a const block to ensure its not executed at runtime (although it's probably optimized out anyways).
It 100% will be optimized out.
Quoted 2 lines
It would also mean that we won't need a assert for every Trait, which seems nice. So a macro sounds pretty good to me.
It depends, the macro impl needs to define its own function, which might be inefficient if one uses it a lot. But there is no way to be generic over traits, so there is no other way.
Let's see what the others think.
---
Cheers,
Benno
Quoted 36 lines · Benno Lossin
Quoted 7 lines · Christian Schrefl
Quoted 4 lines · Benno Lossin
Quoted 1 line · Christian Schrefl
- Add
assert_sendas well.Sounds like a good idea.
Should I already add this in V2 for this series?
If you want to then sure, but we can also wait until we have a use-case. Also, let's finish the discussion about the macro idea below.
Quoted 8 lines
Quoted 5 lines
rust/kernel/compile_assert.rs line 19
Quoted 2 lines
rust/kernel/compile_assert.rs new file +2
-0+/// assert_sync::<i32>(); // Succeeds because `i32` is Sync +/// // assert_sync::<NotThreadSafe>(); // Fails because `NotThreadSafe` is not `Sync`. Can you split this into two examples and mark the failing one with
compile_fail?I've tried it with
compile_failand it didn't work, I think that's not supported in (kernel) doc tests yet.Hmm, I thought that this worked... @Miguel any idea?
Quoted 5 lines
Quoted 3 lines
We also could provide a macro similar to [1].
[1]: https://docs.rs/static_assertions/latest/static_assertions/
You mean the
assert_impl_*!macros?Yes, but the others might also be useful from time to time.
Quoted 3 lines
Quoted 1 line
That might make sense, with macros we would not need to write
a const block to ensure its not executed at runtime (although it's probably optimized out anyways).
It 100% will be optimized out.
Quoted 8 lines
Quoted 2 lines
It would also mean that we won't need a assert for every Trait, which seems nice. So a macro sounds pretty good to me.
It depends, the macro impl needs to define its own function, which might be inefficient if one uses it a lot. But there is no way to be generic over traits, so there is no other way.
Let's see what the others think.
The error messages in the macro are slightly worse:
error[E0277]: *mut () cannot be shared between threads safely
--> rust/kernel/compile_assert.rs:40:18
|
40 | assert_impl_all!(NotThreadSafe: Sync); // Fails because `NotThreadSafe` is not `Sync`
| ^^^^^^^^^^^^^ `*mut ()` cannot be shared between threads safely
|
= help: within `PhantomData<*mut ()>`, the trait `Sync` is not implemented for `*mut ()`, which is required by `PhantomData<*mut ()>: Sync`
note: required because it appears within the type `PhantomData<*mut ()>`
--> /home/chrisi/.rustup/toolchains/1.78-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/marker.rs:740:12
|
740 | pub struct PhantomData<T: ?Sized>;
| ^^^^^^^^^^^
note: required by a bound in `assert_impl`
--> rust/kernel/compile_assert.rs:34:48
|
34 | const fn assert_impl<T: ?Sized $(+ $trait)+>() {}
| ^^^^^^ required by this bound in `assert_impl`...
40 | assert_impl_all!(NotThreadSafe: Sync); // Fails because NotThreadSafe is not Sync
| ------------------------------------- in this macro invocation
= note: this error originates in the macro assert_impl_all (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 1 previous error
compared to the function:
error[E0277]: *mut () cannot be shared between threads safely
--> rust/kernel/compile_assert.rs:28:31
|
28 | const _: () = { assert_sync::<NotThreadSafe>() };
| ^^^^^^^^^^^^^ `*mut ()` cannot be shared between threads safely
|
= help: within `PhantomData<*mut ()>`, the trait `Sync` is not implemented for `*mut ()`, which is required by `PhantomData<*mut ()>: Sync`
note: required because it appears within the type `PhantomData<*mut ()>`
--> /home/chrisi/.rustup/toolchains/1.78-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/marker.rs:740:12
|
740 | pub struct PhantomData<T: ?Sized>;
| ^^^^^^^^^^^
note: required by a bound in `assert_sync`
--> rust/kernel/compile_assert.rs:26:38
|
26 | pub const fn assert_sync<T: ?Sized + Sync>() {}
| ^^^^ required by this bound in `assert_sync`I guess I'll keep it as a function for now.
Cheers
Christian
Quoted 8 lines · Miguel Ojeda
rust/kernel/compile_assert.rs line 6
Quoted 3 lines · Christian Schrefl
rust/kernel/compile_assert.rs new file +2
-0+/// Asserts that the given type is [`Sync`]. This check is done at compile time and does nothing +/// at runtime. I would split the second sentence into its own paragraph, so that the "short description" isn't long.
Alright.
Quoted 10 lines
Quoted 2 lines
+/// Note that this is only intended to avoid regressions and for sanity checks.
Hmm... I am not sure about this sentence. A macro may want to call this to ensure something that is required for safety, for instance. Is that the "sanity check" part? In any case, it sounds like the sentence could be read as "this is not reliable for "other" things apart from just sanity checks", which may be confusing.
Could we perhaps clarify?
I added this because for some reason I was convinced that it would be possible to cause post-monomorphization errors with this, but I not realize that's not a thing. I guess I'll just drop this sentence.
Quoted 16 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+/// # Examples +/// ```Please add a newline between these.>
Review
Quoted 2 lines
(quoted diff) +2
-0+/// +///These newlines should be removed, otherwise they will be rendered.
rust/kernel/compile_assert.rs line 18
Quoted 3 lines
rust/kernel/compile_assert.rs new file +3
-0+/// // Do the assertion in a const block to make sure it won't be executed at runtime. +/// const _:() = { +/// assert_sync::<i32>(); // Succeeds because `i32` is Sync
Syncand please use a period at the end. Also, I would suggest following our usual style and putting it at the top, i.e.
Quoted 7 lines
// Succeeds because `i32` is `Sync`. assert_sync::<i32>();Review
Quoted 2 lines
(quoted diff) +2
-0+/// +/// ```This one can be removed too.
Fixed these
Cheers
Christian
Benno Lossin
reviewerQuoted 91 lines · Christian Schrefl
Quoted 36 lines · Benno Lossin
Quoted 7 lines · Christian Schrefl
Quoted 4 lines · Benno Lossin
Quoted 1 line · Christian Schrefl
- Add
assert_sendas well.Sounds like a good idea.
Should I already add this in V2 for this series?
If you want to then sure, but we can also wait until we have a use-case. Also, let's finish the discussion about the macro idea below.
Quoted 8 lines
Quoted 5 lines
rust/kernel/compile_assert.rs line 19
Quoted 2 lines
rust/kernel/compile_assert.rs new file +2
-0+/// assert_sync::<i32>(); // Succeeds because `i32` is Sync +/// // assert_sync::<NotThreadSafe>(); // Fails because `NotThreadSafe` is not `Sync`. Can you split this into two examples and mark the failing one with
compile_fail?I've tried it with
compile_failand it didn't work, I think that's not supported in (kernel) doc tests yet.Hmm, I thought that this worked... @Miguel any idea?
Quoted 5 lines
Quoted 3 lines
We also could provide a macro similar to [1].
[1]: https://docs.rs/static_assertions/latest/static_assertions/
You mean the
assert_impl_*!macros?Yes, but the others might also be useful from time to time.
Quoted 3 lines
Quoted 1 line
That might make sense, with macros we would not need to write
a const block to ensure its not executed at runtime (although it's probably optimized out anyways).
It 100% will be optimized out.
Quoted 8 lines
Quoted 2 lines
It would also mean that we won't need a assert for every Trait, which seems nice. So a macro sounds pretty good to me.
It depends, the macro impl needs to define its own function, which might be inefficient if one uses it a lot. But there is no way to be generic over traits, so there is no other way.
Let's see what the others think.
The error messages in the macro are slightly worse:
error[E0277]:*mut ()cannot be shared between threads safely
-->rust/kernel/compile_assert.rs:40:18| 40 | assert_impl_all!(NotThreadSafe: Sync); // Fails because `NotThreadSafe` is not `Sync` | ^^^^^^^^^^^^^ `*mut ()` cannot be shared between threads safely | = help: within `PhantomData<*mut ()>`, the trait `Sync` is not implemented for `*mut ()`, which is required by `PhantomData<*mut ()>: Sync` note: required because it appears within the type `PhantomData<*mut ()>` --> /home/chrisi/.rustup/toolchains/1.78-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/marker.rs:740:12 | 740 | pub struct PhantomData<T: ?Sized>; | ^^^^^^^^^^^ note: required by a bound in `assert_impl` --> rust/kernel/compile_assert.rs:34:48 | 34 | const fn assert_impl<T: ?Sized $(+ $trait)+>() {} | ^^^^^^ required by this bound in `assert_impl`...
40 | assert_impl_all!(NotThreadSafe: Sync); // Fails becauseNotThreadSafeis notSync
| ------------------------------------- in this macro invocation
= note: this error originates in the macroassert_impl_all(in Nightly builds, run with -Z macro-backtrace for more info)error: aborting due to 1 previous error
compared to the function:
error[E0277]:
*mut ()cannot be shared between threads safely
-->rust/kernel/compile_assert.rs:28:31| 28 | const _: () = { assert_sync::<NotThreadSafe>() }; | ^^^^^^^^^^^^^ `*mut ()` cannot be shared between threads safely | = help: within `PhantomData<*mut ()>`, the trait `Sync` is not implemented for `*mut ()`, which is required by `PhantomData<*mut ()>: Sync` note: required because it appears within the type `PhantomData<*mut ()>` --> /home/chrisi/.rustup/toolchains/1.78-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/marker.rs:740:12 | 740 | pub struct PhantomData<T: ?Sized>; | ^^^^^^^^^^^ note: required by a bound in `assert_sync` --> rust/kernel/compile_assert.rs:26:38 | 26 | pub const fn assert_sync<T: ?Sized + Sync>() {} | ^^^^ required by this bound in `assert_sync`
Quoted 1 line
I guess I'll keep it as a function for now.
Can we improve this by using a proc-macro instead and manipulating the span? I honestly don't think the error is too bad.
---
Cheers,
Benno
Quoted 92 lines · Benno Lossin
Quoted 91 lines · Christian Schrefl
Quoted 36 lines · Benno Lossin
Quoted 7 lines · Christian Schrefl
Quoted 4 lines · Benno Lossin
Quoted 1 line · Christian Schrefl
- Add
assert_sendas well.Sounds like a good idea.
Should I already add this in V2 for this series?
If you want to then sure, but we can also wait until we have a use-case. Also, let's finish the discussion about the macro idea below.
Quoted 8 lines
Quoted 5 lines
rust/kernel/compile_assert.rs line 19
Quoted 2 lines
rust/kernel/compile_assert.rs new file +2
-0+/// assert_sync::<i32>(); // Succeeds because `i32` is Sync +/// // assert_sync::<NotThreadSafe>(); // Fails because `NotThreadSafe` is not `Sync`. Can you split this into two examples and mark the failing one with
compile_fail?I've tried it with
compile_failand it didn't work, I think that's not supported in (kernel) doc tests yet.Hmm, I thought that this worked... @Miguel any idea?
Quoted 5 lines
Quoted 3 lines
We also could provide a macro similar to [1].
[1]: https://docs.rs/static_assertions/latest/static_assertions/
You mean the
assert_impl_*!macros?Yes, but the others might also be useful from time to time.
Quoted 3 lines
Quoted 1 line
That might make sense, with macros we would not need to write
a const block to ensure its not executed at runtime (although it's probably optimized out anyways).
It 100% will be optimized out.
Quoted 8 lines
Quoted 2 lines
It would also mean that we won't need a assert for every Trait, which seems nice. So a macro sounds pretty good to me.
It depends, the macro impl needs to define its own function, which might be inefficient if one uses it a lot. But there is no way to be generic over traits, so there is no other way.
Let's see what the others think.
The error messages in the macro are slightly worse:
error[E0277]:*mut ()cannot be shared between threads safely
-->rust/kernel/compile_assert.rs:40:18| 40 | assert_impl_all!(NotThreadSafe: Sync); // Fails because `NotThreadSafe` is not `Sync` | ^^^^^^^^^^^^^ `*mut ()` cannot be shared between threads safely | = help: within `PhantomData<*mut ()>`, the trait `Sync` is not implemented for `*mut ()`, which is required by `PhantomData<*mut ()>: Sync` note: required because it appears within the type `PhantomData<*mut ()>` --> /home/chrisi/.rustup/toolchains/1.78-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/marker.rs:740:12 | 740 | pub struct PhantomData<T: ?Sized>; | ^^^^^^^^^^^ note: required by a bound in `assert_impl` --> rust/kernel/compile_assert.rs:34:48 | 34 | const fn assert_impl<T: ?Sized $(+ $trait)+>() {} | ^^^^^^ required by this bound in `assert_impl`...
40 | assert_impl_all!(NotThreadSafe: Sync); // Fails becauseNotThreadSafeis notSync
| ------------------------------------- in this macro invocation
= note: this error originates in the macroassert_impl_all(in Nightly builds, run with -Z macro-backtrace for more info)error: aborting due to 1 previous error
compared to the function:
error[E0277]:
*mut ()cannot be shared between threads safely
-->rust/kernel/compile_assert.rs:28:31| 28 | const _: () = { assert_sync::<NotThreadSafe>() }; | ^^^^^^^^^^^^^ `*mut ()` cannot be shared between threads safely | = help: within `PhantomData<*mut ()>`, the trait `Sync` is not implemented for `*mut ()`, which is required by `PhantomData<*mut ()>: Sync` note: required because it appears within the type `PhantomData<*mut ()>` --> /home/chrisi/.rustup/toolchains/1.78-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/marker.rs:740:12 | 740 | pub struct PhantomData<T: ?Sized>; | ^^^^^^^^^^^ note: required by a bound in `assert_sync` --> rust/kernel/compile_assert.rs:26:38 | 26 | pub const fn assert_sync<T: ?Sized + Sync>() {} | ^^^^ required by this bound in `assert_sync`
Quoted 4 lines
Quoted 1 line
I guess I'll keep it as a function for now.
Can we improve this by using a proc-macro instead and manipulating the span? I honestly don't think the error is too bad.
I don't see any point in paying the compile time hit for a proc macro.
The Error is not that bad, just a bit worse. I just don't really see the point since this is only really need for marker traits and realistically only for Send and Sync. Also the macro would create a function definition for every invocation which would be a (very) small compile time hit. So I think that we should just add the Send and Sync functions for now and reconsider changing to a macro once/if more than these two is actually needed.
Cheers
Christian.
Benno Lossin
reviewerQuoted 9 lines · Christian Schrefl
I don't see any point in paying the compile time hit for a proc macro.
The Error is not that bad, just a bit worse. I just don't really see the point since this is only really need for marker traits and realistically only for
SendandSync. Also the macro would create a function definition for every invocation which would be a (very) small compile time hit. So I think that we should just add theSendandSyncfunctions for now and reconsider changing to a macro once/if more than these two is actually needed.
Sounds good.
---
Cheers,
Benno