-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Return value from const_trait_impl did not promote to constant? #69574
Comments
The result of a |
@ecstatic-morse const V: u8 = u8::const_default();
&V |
Sure, feel free to edit the text of this issue or open another issue etc, just whatever is helpful to the teams and work groups. (i don't really know what works the best.) It's not urgent at all since the workaround is so easy after the rule is learnt (just explicitly write an constant item, instead of expecting automatic promotion). |
We'd have to register code that can be promoted via an explicit constant somewhere where borrowck can access it again. All the ways that I can think of would make this either resource consuming in the happy path or very convoluted in the error reporting path. While I do agree it would be nice to have a better diagnostic, that seems to be little gain for a lot of effort for now. But going back to the original issue. This should indeed compile I think because you are promoting from inside a const fn where all the const rules need to apply anyway. I though we were promoting anything const inside const fn. Or are we just doing that inside constants? |
@oli-obk Just inside constants, since they always execute at compile-time. |
Ok, so basically, when a lifetime error occurs, we should rerun the promotion check with const rules enabled, and if they succeed, suggest to wrap it in a const block. |
The above comment is still needed and likely the best course of action.
|
I tried this code:
I expected to see this happen: This should pass compile if i'm not mistaken.
Instead, this happened: The const value promotion did not happen.
cc @ecstatic-morse @oli-obk
The text was updated successfully, but these errors were encountered: