solc42
November 13, 2022, 11:31am
1
Hello, everyone.
I don't know is it ok to post such strange request here, but I known there are many people who commit in rust repos, so wanted to ask experienced people for help.
The issue is about rust reference terms for "pointer"/"non-pointer" types:
opened 11:18AM - 13 Nov 22 UTC
## Please don't rush with answer =)
Hello, everyone.
First of all, I do real… ize, 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](https://doc.rust-lang.org/reference/types.html) section, it's clear that
```
Pointer types:
- References
- Raw pointers
- Function pointers
```
Okey.
Then if one comes to [10.1.13. Pointer types](https://doc.rust-lang.org/reference/types/pointer.html) 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](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-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](https://doc.rust-lang.org/reference/types/pointer.html), 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](https://doc.rust-lang.org/std/ops/trait.Deref.html#) 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:
- https://github.com/rust-lang/rust/issues/72335
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
- can we 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 problem 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.
I did reflect myself before bothering with an issue, but while googling for an answer found that I'am not only one with confusion, so decided to start an issue.
PS if it is not the right place/form to request for help, sorry in advance.
system
Closed
February 11, 2023, 11:32am
2
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.