Skip to content

LocalKey::try_with error is incorrectly documented to be guaranteed #157889

Description

@LHolten

Location (URL)

https://doc.rust-lang.org/std/thread/struct.LocalKey.html#method.try_with

Summary

Currently it says:

If the key has been destroyed (which may happen if this is called in a destructor), this function will return an AccessError.

However I think it should say: "If the key has been destroyed (which may happen if this is called in a destructor), this function may return an AccessError."

Let me explain why I think this would be the correct documentation:

  • LocalKey::with clearly documents that it does not always panic when the destructor has run and it uses LocalKey::try_with internally. If LocalKey::try_with really did detect all destroyed thread locals, then LocalKey::with could always guaratee a panic.
  • The top level LocalKey docs seem to explain why previously destroyed thread locals would not always be possible to detect:

    On all platforms it’s possible for TLS to re-initialize other TLS slots during destruction.

It could be that I came to the wrong conclusion, but there is at least some inconsistency in the docs here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions