Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document what "thin pointers" are #41300

Open
droundy opened this issue Apr 14, 2017 · 10 comments
Open

document what "thin pointers" are #41300

droundy opened this issue Apr 14, 2017 · 10 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@droundy
Copy link
Contributor

droundy commented Apr 14, 2017

I got the following error message:

error: casting `*const T` as `usize` is invalid
  --> src/refset.rs:17:9
   |
17 |         (self.0 as *const T as usize).hash(state);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: cast through a thin pointer first

which was quite clear, except that there seems to be no documentation as to what a "thin" pointer is. I ended up through guesswork casting to a *const usize in between which made this work for me.

@Mark-Simulacrum Mark-Simulacrum added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Apr 14, 2017
@steveklabnik
Copy link
Member

/cc @rust-lang/lang ; I wonder what the official terminology here should be. I prefer the "single pointer"/"double pointer" language to the "thin pointer"/"fat pointer" stuff, but it seems to me that this diagnostic could use re-worked and possibly made even more clear. Thoughts?

also, re-tagging as compiler since I believe this is more of a diagnostic issue than a docs issue.

@steveklabnik steveklabnik added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels Apr 25, 2017
@hanna-kruppe
Copy link
Contributor

"single pointer"/"double pointer" language

That's not really accurate though, is it? Slices are (pointer, len), not two pointers. There's also the possibility of custom DSTs which would permit fat pointers larger than two words.

@withoutboats
Copy link
Contributor

I prefer the "single pointer"/"double pointer" language to the "thin pointer"/"fat pointer" stuff, but it seems to me that this diagnostic could use re-worked and possibly made even more clear.

I agree with rkruppe that 'double pointer' could be misleading, but think our language would be slightly more welcoming if we used 'wide pointer' in error messages instead of 'fat'.

@steveklabnik
Copy link
Member

not two pointers

When I've heard it, it was referring to "double the size", not "two pointers" though that confusion is certainly a good reason to not have it.

👍 for "pointer"/"wide pointer"

@eddyb
Copy link
Member

eddyb commented Apr 25, 2017

Would "non-wide pointer" make sense then?

@withoutboats
Copy link
Contributor

withoutboats commented Apr 25, 2017

Yea, I think in most cases "thin pointer" can probably just be "pointer," this error message (trying to cast wide pointer down) seems like the only one where its helpful to explicit mentioning the non-wideness of the pointer, based on a ripgrep.

"non-wide" or even just "regular" seems fine when you need to highlight the distinction of most pointers from wide pointers.

@nikomatsakis
Copy link
Contributor

In light of the custom DST proposal, I've come to think of all pointers as "wide pointers", it's sort of just a question of what their auxiliary data is ("thin" pointers would have metadata of type ()). I wonder if we can avoid the terminology altogether, somehow? But it's not obvious how to adapt the error message to this POV. I think of "casting to a thin pointer" as basically replacing the wide pointer metadata with ().

@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jul 27, 2017
@tlively
Copy link
Contributor

tlively commented Oct 10, 2017

I just ran into this issue and had no idea what was going on, so it would be great if this could be fixed.

(For anyone else confused about this thin pointer help message, you can fix it by adding an intermediate cast to some primitive pointer type like *const usize)

@ghost
Copy link

ghost commented Apr 18, 2019

I just ran across this issue after encountering the mentioned error message. I was thoroughly confused, and while the solution of casting to *const usize instead of just usize works, I have no idea why that is the case (I prefer to understand how things work rather than just copying a solution from somewhere). I would really appreciate some further documentation on what thin pointers vs wide pointers are, when they are used and why, specifically when dyn Any is involved.

@estebank estebank added the D-confusing Diagnostics: Confusing error or lint that should be reworked. label Oct 15, 2019
@QuineDot
Copy link

QuineDot commented Sep 3, 2021

In light of RFC 2580, perhaps this could be something like

error: casting `*const T` as `usize` is invalid
  --> src/refset.rs:17:9
   |
17 |         (self.0 as *const T as usize).hash(state);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: `*const T` may include non-zero sized metadata, such as a slice length or `dyn Trait` vtable
   = help: cast through a pointer that has no metadata first:
             (self.0 as *const T as *const () as usize).hash(state);

In non-generic cases, "non-zero sized metadata" could be replaced with something more specific. Post-stabilization, the hints could be updated to match the trait.

   = help: `*const T` may include non-zero sized metadata, such as a slice length or `dyn Trait` vtable
   = help: cast through a pointer that satisfies `Pointee<Metadata=()>` first:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

10 participants