rust-lang / rust-lang/rust

Need an explicit part for requirements which can not be checked by compiler in trait docs

Open
#128,926 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Location

Trait std::borrow::Borrow,

screenshot
Summary

Many traits require something more just their associated functions and types. Like trait Send requires that type are safe to tranferred between threads, Eq requires this relation is an equivalent relation and Ord need to be consistent with PartialOrd.

These requirements share a common characteristic: they cannot be fully verified by the compiler through the implementations of their associated trait methods and types. Programmers must take additional effort to ensure correctness. Similar to how the Safety and Panic sections in function or method documentation specifically describe the requirements for a function or method to work correctly, I propose that trait documentation also include a dedicated "requirements" section to outline these aspects that cannot be fully verified by the compiler.

For example, trait Borrow requires that

Eq, Ord and Hash must be equivalent for borrowed and owned values

which can not be checked by compiler. However, these points were buried in the second-to-last paragraph of the document description and were not highlighted.

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 documentation for trait std::borrow::Borrow and compare its requirements with the existing Safety and Panic sections in function or method documentation. Determine how a dedicated trait requirements section would be defined and applied to the Borrow documentation, with the non-compiler-checkable equivalence requirements clearly represented as the completion criterion.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.