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

Improve pretty printing of const raw pointers #65349

Open
BenLewis-Seequent opened this issue Oct 12, 2019 · 4 comments
Open

Improve pretty printing of const raw pointers #65349

BenLewis-Seequent opened this issue Oct 12, 2019 · 4 comments
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@BenLewis-Seequent
Copy link

#64986 changed the pretty-printing of const raw pointers to {pointer}. This can cause confusing diagnostics due to the lack of detail the printing of raw pointers provides, like the following:

error[E0308]: mismatched types
  --> $DIR/raw-ptr-const-param.rs:7:38
   |
LL |     let _: Const<{15 as *const _}> = Const::<{10 as *const _}>;
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{pointer}`, found `{pointer}`
   |
   = note: expected type `Const<{pointer}>`
              found type `Const<{pointer}>`
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 12, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 29, 2019
…mertj

Better pretty printing for const raw pointers

closes rust-lang#65349, hopefully.
Centril added a commit to Centril/rust that referenced this issue Oct 29, 2019
…mertj

Better pretty printing for const raw pointers

closes rust-lang#65349, hopefully.
@RalfJung
Copy link
Member

Woah people use raw pointers as const generic arguments and then feed them integers cast to raw pointers? That is so scary.^^

@varkor
Copy link
Member

varkor commented Oct 31, 2019

No-one's using pointers with const generics right now (I hope): but it does work, and diagnostics are something we would want to improve if we ever did consider stabilising this feature. It's more of a reminder.

@Phlosioneer
Copy link
Contributor

Phlosioneer commented Dec 1, 2019

Would it be possible to have a counter for whenever a const pointer is accessed, so that the above message would look something like:

error[E0308]: mismatched types
  --> $DIR/raw-ptr-const-param.rs:7:38
   |
LL |     let _: Const<{15 as *const _}> = Const::<{10 as *const _}>;
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{pointer#4}`, found `{pointer#89}`
   |
   = note: expected type `Const<{pointer#4}>`
              found type `Const<{pointer#89}>`

(numbers chosen arbitrarily here)

At least as a temporary solution. A future solution would hopefully add "note: {pointer#4} points to `15: usize`" and "note: {pointer#89} points to `10: usize`" (or whatever integer type it thinks of)

@varkor
Copy link
Member

varkor commented Sep 13, 2020

This should not be an issue with min_const_generics, which doesn't allow pointers as types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants