Skip to content

Commit d247e7f

Browse files
authored
sync: document that const_new() is not instrumented (#6002)
1 parent 65e7715 commit d247e7f

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

tokio/src/sync/mutex.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,21 @@ impl<T: ?Sized> Mutex<T> {
371371

372372
/// Creates a new lock in an unlocked state ready for use.
373373
///
374+
/// When using the `tracing` [unstable feature], a `Mutex` created with
375+
/// `const_new` will not be instrumented. As such, it will not be visible
376+
/// in [`tokio-console`]. Instead, [`Mutex::new`] should be used to create
377+
/// an instrumented object if that is needed.
378+
///
374379
/// # Examples
375380
///
376381
/// ```
377382
/// use tokio::sync::Mutex;
378383
///
379384
/// static LOCK: Mutex<i32> = Mutex::const_new(5);
380385
/// ```
386+
///
387+
/// [`tokio-console`]: https://github.com/tokio-rs/console
388+
/// [unstable feature]: crate#unstable-features
381389
#[cfg(not(all(loom, test)))]
382390
pub const fn const_new(t: T) -> Self
383391
where

tokio/src/sync/notify.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,21 @@ impl Notify {
436436

437437
/// Create a new `Notify`, initialized without a permit.
438438
///
439+
/// When using the `tracing` [unstable feature], a `Notify` created with
440+
/// `const_new` will not be instrumented. As such, it will not be visible
441+
/// in [`tokio-console`]. Instead, [`Notify::new`] should be used to create
442+
/// an instrumented object if that is needed.
443+
///
439444
/// # Examples
440445
///
441446
/// ```
442447
/// use tokio::sync::Notify;
443448
///
444449
/// static NOTIFY: Notify = Notify::const_new();
445450
/// ```
451+
///
452+
/// [`tokio-console`]: https://github.com/tokio-rs/console
453+
/// [unstable feature]: crate#unstable-features
446454
#[cfg(not(all(loom, test)))]
447455
pub const fn const_new() -> Notify {
448456
Notify {

tokio/src/sync/once_cell.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ impl<T> OnceCell<T> {
153153
///
154154
/// # Example
155155
///
156+
/// When using the `tracing` [unstable feature], a `OnceCell` created with
157+
/// `const_new_with` will not be instrumented. As such, it will not be
158+
/// visible in [`tokio-console`]. Instead, [`OnceCell::new_with`] should be
159+
/// used to create an instrumented object if that is needed.
160+
///
156161
/// ```
157162
/// use tokio::sync::OnceCell;
158163
///
@@ -170,6 +175,9 @@ impl<T> OnceCell<T> {
170175
/// assert_eq!(*result, 1);
171176
/// }
172177
/// ```
178+
///
179+
/// [`tokio-console`]: https://github.com/tokio-rs/console
180+
/// [unstable feature]: crate#unstable-features
173181
#[cfg(not(all(loom, test)))]
174182
pub const fn const_new_with(value: T) -> Self {
175183
OnceCell {
@@ -184,6 +192,11 @@ impl<T> OnceCell<T> {
184192
/// Equivalent to `OnceCell::new`, except that it can be used in static
185193
/// variables.
186194
///
195+
/// When using the `tracing` [unstable feature], a `OnceCell` created with
196+
/// `const_new` will not be instrumented. As such, it will not be visible
197+
/// in [`tokio-console`]. Instead, [`OnceCell::new`] should be used to
198+
/// create an instrumented object if that is needed.
199+
///
187200
/// # Example
188201
///
189202
/// ```
@@ -203,6 +216,9 @@ impl<T> OnceCell<T> {
203216
/// assert_eq!(*result, 2);
204217
/// }
205218
/// ```
219+
///
220+
/// [`tokio-console`]: https://github.com/tokio-rs/console
221+
/// [unstable feature]: crate#unstable-features
206222
#[cfg(not(all(loom, test)))]
207223
pub const fn const_new() -> Self {
208224
OnceCell {

tokio/src/sync/rwlock.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,21 @@ impl<T: ?Sized> RwLock<T> {
327327

328328
/// Creates a new instance of an `RwLock<T>` which is unlocked.
329329
///
330+
/// When using the `tracing` [unstable feature], a `RwLock` created with
331+
/// `const_new` will not be instrumented. As such, it will not be visible
332+
/// in [`tokio-console`]. Instead, [`RwLock::new`] should be used to create
333+
/// an instrumented object if that is needed.
334+
///
330335
/// # Examples
331336
///
332337
/// ```
333338
/// use tokio::sync::RwLock;
334339
///
335340
/// static LOCK: RwLock<i32> = RwLock::const_new(5);
336341
/// ```
342+
///
343+
/// [`tokio-console`]: https://github.com/tokio-rs/console
344+
/// [unstable feature]: crate#unstable-features
337345
#[cfg(not(all(loom, test)))]
338346
pub const fn const_new(value: T) -> RwLock<T>
339347
where

tokio/src/sync/semaphore.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,21 @@ impl Semaphore {
194194

195195
/// Creates a new semaphore with the initial number of permits.
196196
///
197+
/// When using the `tracing` [unstable feature], a `Semaphore` created with
198+
/// `const_new` will not be instrumented. As such, it will not be visible
199+
/// in [`tokio-console`]. Instead, [`Semaphore::new`] should be used to
200+
/// create an instrumented object if that is needed.
201+
///
197202
/// # Examples
198203
///
199204
/// ```
200205
/// use tokio::sync::Semaphore;
201206
///
202207
/// static SEM: Semaphore = Semaphore::const_new(10);
203208
/// ```
209+
///
210+
/// [`tokio-console`]: https://github.com/tokio-rs/console
211+
/// [unstable feature]: crate#unstable-features
204212
#[cfg(not(all(loom, test)))]
205213
pub const fn const_new(permits: usize) -> Self {
206214
Self {

0 commit comments

Comments
 (0)