rust-lang / rust-lang/rust

Footgun with Rc::assume_init and related methods

Open
#131,861 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Location

I came across https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.assume_init recently, and spotted a footgun that I think ought to be called out:

Summary

The safety section does not clarify whether multiple Rcs are allowed to exist when assume_init is called. If they are, then whether Drop is called on the inner value will depend on the drop order of those Rcs. In the case of Arc this might well be non-deterministic.

IMO, the documentation should specify whether this is allowed, and if so should point out that callers must take care around this potential issue.

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 std::rc::Rc::assume_init documentation linked in the issue, then compare its safety section with related Rc and Arc methods. Done means the documentation clearly states whether multiple Rc or Arc values may exist at the call and explains the resulting Drop-order concern if applicable.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.