Add some comments about _marker fields.

There is some non-obvious information required to understand them.
This commit is contained in:
Nicholas Nethercote 2022-05-16 09:36:52 +10:00
parent 9a785e0aa5
commit c2c505737f
3 changed files with 14 additions and 4 deletions

View File

@ -49,7 +49,9 @@ pub(super) fn new(handle_counters: &'static HandleCounters) -> Self {
#[repr(C)]
pub(crate) struct $oty {
handle: handle::Handle,
// Prevent Send and Sync impls
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
// way of doing this, but that requires unstable features.
// rust-analyzer uses this code and avoids unstable features.
_marker: PhantomData<*mut ()>,
}
@ -133,7 +135,9 @@ fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub(crate) struct $ity {
handle: handle::Handle,
// Prevent Send and Sync impls
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
// way of doing this, but that requires unstable features.
// rust-analyzer uses this code and avoids unstable features.
_marker: PhantomData<*mut ()>,
}

View File

@ -6,7 +6,11 @@
pub struct Closure<'a, A, R> {
call: unsafe extern "C" fn(*mut Env, A) -> R,
env: *mut Env,
// Ensure Closure is !Send and !Sync
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
// this, but that requires unstable features. rust-analyzer uses this code
// and avoids unstable features.
//
// The `'a` lifetime parameter represents the lifetime of `Env`.
_marker: PhantomData<*mut &'a mut ()>,
}

View File

@ -232,7 +232,9 @@ pub struct Bridge<'a> {
/// If 'true', always invoke the default panic hook
force_show_panics: bool,
// Prevent Send and Sync impls
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
// this, but that requires unstable features. rust-analyzer uses this code
// and avoids unstable features.
_marker: marker::PhantomData<*mut ()>,
}