rust-lang / rust-lang/reference

Clarification for terms 'pointer' and 'non-pointer'

Open
#1,298 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.6k
Forks
607
PR merge metrics
PR metrics pending

Description

Please don't rush with answer =)

Hello, everyone.

First of all, I do realize, that this question may look trivial for an experienced rust user, but for newcomer it does not look clear. Even more I've found very similar clarification issue merged few years ago to rust-lang repo(link below).

So the problem seems to exist.

General term for pointer type does not look clear

The first point is that doc reference, to be honest, is a bit confusing about strict definition about what a pointer type is.

If one comes to reference 10. Type system -> 10.1 Types section, it's clear that

Pointer types:
    - References
    - Raw pointers
    - Function pointers

Okey.

Then if one comes to 10.1.13. Pointer types then, according to section names, pointer types are:

    - References
    - Raw pointers
    - Smart Pointers

So it does not match - nothing about function pointers now, but we have smart pointers.

Now to illustration.

Explanation of dereference operator

Reading the 8.2.4. Operator expressions -> dereference operator section there is branching:

  1. When applied to a pointer ...
  2. On non-pointer types ...

The documentation here contains explicit reference to 10.1.13. Pointer types, so in "applied to a pointer", pointer seems to be one of those:

  • References
  • Raw pointers
  • Smart Pointers

Then comes part (2) for non-pointer:

On non-pointer types *x is equivalent to *std::ops::Deref::deref(&x) in an immutable place <...>

and non-pointer seems to be about negotiation of pointer, thus about "nor reference nor raw pointer nor smart pointer".

But it is confusing, because doc for trait Deref clearly states that

Deref should only be implemented for smart pointers to avoid confusion.

so non-pointer(thus smart pointer does not match) is illustrated via Deref::deref, and at the same time Deref documentation states that it was designed specifically to accommodate smart pointers.

I would not event bother with an issue, but while googling for clarification for myself, found that there was a similar situation:

And documentation for trait is now more clean. But not the reference.

Summing up

  • is it possible to make reference definition or some kind of distinction for what exactly term pointer type and non-pointer type mean in documentation, or specify explicitly if context matters
  • is it possible clarify the dereference operator documentation? I could make a PR with same clarification phrase https://github.com/rust-lang/rust/issues/72335, but seems the confusion is a bit more general, cause not only the negotiation part in dereference operator is confusing, but the pointer type/non-pointer type phrase itself.

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

Review the Reference's Types, Pointer types, and dereference operator sections alongside the std::ops::Deref documentation and the linked rust-lang/rust issue. Identify where “pointer,” “non-pointer,” and smart pointer terminology diverges, then clarify the definitions and context in the relevant documentation. Done means the sections use consistent terms and explain the dereference behavior without the reported ambiguity.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.