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

Consider changing the way unevaluated constants are printed #61581

Open
oli-obk opened this issue Jun 6, 2019 · 3 comments
Open

Consider changing the way unevaluated constants are printed #61581

oli-obk opened this issue Jun 6, 2019 · 3 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) 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

@oli-obk
Copy link
Contributor

oli-obk commented Jun 6, 2019

cc #60742 (comment)

Right now when we encounter a ConstValue::Unevaluated during pretty printing, we fall back to printing the constant's source code or _ if that also fails. Alternative options are:

  • try to eagerly evaluate (and fall back to one of the following)
  • always print _
  • print something like {{unevaluated: {}}} where {} is the source code
  • print just {unevaluated} (seems useless for users, so maybe not a good idea)
@oli-obk oli-obk added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-const-generics Area: const generics (parameters and arguments) labels Jun 6, 2019
@varkor
Copy link
Member

varkor commented Jun 6, 2019

I think it would be ideal if we could print the unevaluated expression itself. (Though we might have to point out specifically that it's unevaluated in diagnostics if this proves confusing.)

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 6, 2019

that's what we are doing right now, but you end up with errors like expected 3 got 3usize. If we eagerly evaluated we'd even get expected 3usize got 3usize

These errors may just disappear if we manage to normalize before doing whatever causes the error.

@varkor
Copy link
Member

varkor commented Jun 6, 2019

Ah, I was specifically referring to the case when _ is printed at the moment, which has been encountered quite frequently with const generics.

I agree the cases when it does print the expression, and they look the same as what's expected is confusing, but these seem more indicative of existing issues, like normalisation, than printing. Maybe the diagnostics, rather than the pretty printing, could be adjusted for now to address this.

@jonas-schievink jonas-schievink added 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 Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) 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

No branches or pull requests

3 participants