Subpar documentation for ptr-to-ref conversion methods #124669
Open
Description
opened on May 3, 2024
While trying to merge #122492, some issues with the existing documentation became apparent.
The methods in question
-
<*const T>::as_ref
-
<*mut T>::as_ref
-
<*mut T>::as_mut
-
<*const T>::as_ref_unchecked
1 -
<*mut T>::as_ref_unchecked
1 -
<*mut T>::as_mut_unchecked
1 -
<*const T>::as_uninit_ref
2 -
<*mut T>::as_uninit_ref
2 -
<*mut T>::as_uninit_mut
2
The problems
- The overarching pain-point is that big parts of documentation are repeated for all (or at least the most) of the methods, which makes it difficult to keep the wording in sync.
Documentation
- Generally subpar wording (probably due to these docs' being a patchwork of many separate changes). But also specifically:
- Imprecise wording around
UnsafeCell
-
Needlessly scary wording around the output's lifetimeOr not?
Doctests
-
Currently, they do printing instead of asserting. This should probably be changed to assertions.(Fixed in docs(core): make more const_ptr doctests assert instead of printing #126210) - The assertions that we want should reflect the API being tested. (For example, we probably want an assertion that null pointer gets converted to
None
foras_ref
, but no such assertion foras_ref_unchecked
is possible.) - Currently some asserts are hidden. Why?
Moving forward
Feel free to voice your opinions/wishes/suggestions/questions regarding this issue or to submit PRs addressing any of the problems above (not necessarily all at once). Also, doctests can probably be worked on independently from the documentation itself.
Beep-Boop
@rustbot label +A-docs +A-doctests +C-discussion +C-enhancement +E-help-wanted
And now footnotes:
Footnotes
-
Not yet stabilized (Tracking Issue for raw-pointer-to-reference conversion methods #122034) ↩ ↩2 ↩3
-
Not yet stabilized (Tracking Issue for pointer methods returning
MaybeUninit<T>
#75402) ↩ ↩2 ↩3
Metadata
Assignees
Labels
Area: documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation tests, run by rustdocCategory: Discussion or questions that doesn't represent real issues.Category: An issue proposing an enhancement or a PR with one.Call for participation: Help is requested to fix this issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Projects
Status
Done
Activity