Skip to content

Commit c2c5057

Browse files
committed
Add some comments about _marker fields.
There is some non-obvious information required to understand them.
1 parent 9a785e0 commit c2c5057

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

library/proc_macro/src/bridge/client.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ macro_rules! define_handles {
4949
#[repr(C)]
5050
pub(crate) struct $oty {
5151
handle: handle::Handle,
52-
// Prevent Send and Sync impls
52+
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
53+
// way of doing this, but that requires unstable features.
54+
// rust-analyzer uses this code and avoids unstable features.
5355
_marker: PhantomData<*mut ()>,
5456
}
5557

@@ -133,7 +135,9 @@ macro_rules! define_handles {
133135
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
134136
pub(crate) struct $ity {
135137
handle: handle::Handle,
136-
// Prevent Send and Sync impls
138+
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
139+
// way of doing this, but that requires unstable features.
140+
// rust-analyzer uses this code and avoids unstable features.
137141
_marker: PhantomData<*mut ()>,
138142
}
139143

library/proc_macro/src/bridge/closure.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ use std::marker::PhantomData;
66
pub struct Closure<'a, A, R> {
77
call: unsafe extern "C" fn(*mut Env, A) -> R,
88
env: *mut Env,
9-
// Ensure Closure is !Send and !Sync
9+
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
10+
// this, but that requires unstable features. rust-analyzer uses this code
11+
// and avoids unstable features.
12+
//
13+
// The `'a` lifetime parameter represents the lifetime of `Env`.
1014
_marker: PhantomData<*mut &'a mut ()>,
1115
}
1216

library/proc_macro/src/bridge/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ pub struct Bridge<'a> {
232232
/// If 'true', always invoke the default panic hook
233233
force_show_panics: bool,
234234

235-
// Prevent Send and Sync impls
235+
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
236+
// this, but that requires unstable features. rust-analyzer uses this code
237+
// and avoids unstable features.
236238
_marker: marker::PhantomData<*mut ()>,
237239
}
238240

0 commit comments

Comments
 (0)