-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
An unusable constant should at least warn #47054
Comments
There is a trade-off here with compile times. In order to find out whether a constant can be used or not, you do have to const-evaluate it. This is a possibly expensive operation. If it is expensive, it will worsen compile times. IMO the best way of tackling this is to count the MIR steps spent, and after 1000 steps or so the evaluation stops and it doesn't emit anything. Not sure if miri has a feature for this... |
Example: the autogenerated code always contains a bunch of constants; depending on the parameters some of them are unusable, but it does not matter as they are not actually used in the code that is emitted for those parameters. |
Are constants being emitted? I've thought they only get evaluated at their usage site. |
@est31 You're absolutely correct in everything you said. However, to me this has the same "I compiled and it was fine; what do you mean there's a compilation error on use that's not the user's fault?!" vibe as monomorphization errors, which are also checked for eagerly. And, at least as long as it's a lint, presumably the expense wouldn't happen if the lint is allowed, giving a workaround. |
@scottmcm the lint is definitely a great idea, for the reasons you state. If an unusable const is being declared in a library, your code will fail to compile even though the library is at fault, that's no good experience. |
I created a PR (#50110), anyone feel like reviewing 50 test changes across 15 files? |
Warn on all erroneous constants fixes #49791 fixes #47054 @Zoxc this PR triggers the nondeterministic errors of #49950 (comment) really often (at least on stage1).
The following produces no warnings:
But any attempt to use the FOO const will give
error[E0080]: constant evaluation error
.It would be nice for it to at least warn. and perhaps start erring once the "error on use" case can be handled with a stable
const fn
.The text was updated successfully, but these errors were encountered: