@@ -380,7 +380,7 @@ pub(crate) struct Inner {
380
380
#[ must_use = "once a span has been entered, it should be exited" ]
381
381
pub struct Entered < ' a > {
382
382
span : & ' a Span ,
383
- _not_send : PhantomData < * mut ( ) > ,
383
+ _not_send : PhantomData < crate :: stdlib :: sync :: MutexGuard < ' static , ( ) > > ,
384
384
}
385
385
386
386
/// `log` target for all span lifecycle (creation/enter/exit/close) records.
@@ -1235,24 +1235,6 @@ impl Clone for Inner {
1235
1235
1236
1236
// ===== impl Entered =====
1237
1237
1238
- /// # Safety
1239
- ///
1240
- /// Technically, `Entered` _can_ implement both `Send` *and* `Sync` safely. It
1241
- /// doesn't, because it has a `PhantomData<*mut ()>` field, specifically added
1242
- /// in order to make it `!Send`.
1243
- ///
1244
- /// Sending an `Entered` guard between threads cannot cause memory unsafety.
1245
- /// However, it *would* result in incorrect behavior, so we add a
1246
- /// `PhantomData<*mut ()>` to prevent it from being sent between threads. This
1247
- /// is because it must be *dropped* on the same thread that it was created;
1248
- /// otherwise, the span will never be exited on the thread where it was entered,
1249
- /// and it will attempt to exit the span on a thread that may never have entered
1250
- /// it. However, we still want them to be `Sync` so that a struct holding an
1251
- /// `Entered` guard can be `Sync`.
1252
- ///
1253
- /// Thus, this is totally safe.
1254
- unsafe impl < ' a > Sync for Entered < ' a > { }
1255
-
1256
1238
impl < ' a > Drop for Entered < ' a > {
1257
1239
#[ inline]
1258
1240
fn drop ( & mut self ) {
@@ -1313,4 +1295,5 @@ mod test {
1313
1295
1314
1296
trait AssertSync : Sync { }
1315
1297
impl AssertSync for Span { }
1298
+ impl < ' a > AssertSync for Entered < ' a > { }
1316
1299
}
0 commit comments