rust-lang / rust-lang/rust

Weak::as_ptr claims it can return null, which is impossible

Open
#158,950 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-docs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Current documentation as of 1.96.1:

Returns a raw pointer to the object T pointed to by this Weak.

The pointer is valid only if there are some strong references. The pointer may be dangling, unaligned or even null otherwise.

Weak is internally represented by NonNull (and therefore is subject to niche optimization), so a null pointer cannot be returned. Flipping this to guarantee the returned pointer is non null would be useful as there are no NonNull variants of as_ptr and into_ptr yet.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Weak::as_ptr documentation quoted in the issue and inspect how Weak's NonNull representation affects its pointer guarantees. Determine whether the documentation should guarantee a non-null result or whether the API design needs further discussion; done means the documented contract accurately matches the supported behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.