You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
unused function is not monomorphized, so post-mono lints do not show up (in particular affects associated and inline consts) #106617
Hi lang (and maybe @RalfJung)! I'll miss the meeting on Tuesday, but I figured I'd nominate this since the feature is in FCP now, and this looks breaking to fix.
Do we expect that inline consts in non-generic unused private functions aren't evaluated?
It's not documented when a non-generic associated will evaluated, but it sounds rather inconsistent if it's not also evaluated at monomorphization time.
It's not documented when a non-generic associated will evaluated, but it sounds rather inconsistent if it's not also evaluated at monomorphization time.
Learning something new every day, really.
But back to my case, I think my code in OP translate to
Asking to evaluate inline consts in an unused generic function is meaningless, since we can't know the generic parameters.
We could in principle add a special case that applies only to monomorphic functions like your original example. That would not have any direct relation to inline consts though, it affects associated consts just as much.
Asking to evaluate inline consts in an unused generic function is meaningless, since we can't know the generic parameters.
Yes, I agree this is meaningless.
We could in principle add a special case that applies only to monomorphic functions like your original example. That would not have any direct relation to inline consts though, it affects associated consts just as much.
@nbdd0121 gave a pretty good reason why it's handled like this. It's the combined behavior surprised me, but it's understandable.
I'm ok with either way, compile or not. Actually I would prefer less special cases (if we consider it one).
changed the title [-]inline_const does not evaluate in unused function[/-][+]unused function is not monomorphized, so post-mono lints only show up in debug builds (in particular affects associated and inline consts)[/+]on May 17, 2023
changed the title [-]unused function is not monomorphized, so post-mono lints only show up in debug builds (in particular affects associated and inline consts)[/-][+]unused function is not monomorphized, so post-mono lints do not show up (in particular affects associated and inline consts)[/+]on May 17, 2023
Activity
scottmcm commentedon Jan 9, 2023
Hi lang (and maybe @RalfJung)! I'll miss the meeting on Tuesday, but I figured I'd nominate this since the feature is in FCP now, and this looks breaking to fix.
Do we expect that inline consts in non-generic unused private functions aren't evaluated?
nbdd0121 commentedon Jan 9, 2023
This is intentional, as the same behaviour is true for associated consts.
The use is not collected and evaluated if not monomorphized.
zirconium-n commentedon Jan 9, 2023
Actually I won't expect this would compile either. 😕
Are you sure this is intentional, instead of some accidental behavior?
nbdd0121 commentedon Jan 9, 2023
It's documented that they are not evaluated if not used, and generic associated consts are evaluated at mono (https://doc.rust-lang.org/beta/reference/items/associated-items.html#associated-constants).
It's not documented when a non-generic associated will evaluated, but it sounds rather inconsistent if it's not also evaluated at monomorphization time.
zirconium-n commentedon Jan 9, 2023
Learning something new every day, really.
But back to my case, I think my code in OP translate to
which throws a compile time error.
nbdd0121 commentedon Jan 9, 2023
No, const blocks are handled similar to associated consts as opposed to const items. The latter cannot use generics.
RalfJung commentedon Jan 9, 2023
The problem is that could can write code like this
Asking to evaluate inline consts in an unused generic function is meaningless, since we can't know the generic parameters.
We could in principle add a special case that applies only to monomorphic functions like your original example. That would not have any direct relation to inline consts though, it affects associated consts just as much.
zirconium-n commentedon Jan 11, 2023
Yes, I agree this is meaningless.
@nbdd0121 gave a pretty good reason why it's handled like this. It's the combined behavior surprised me, but it's understandable.
I'm ok with either way, compile or not. Actually I would prefer less special cases (if we consider it one).
nbdd0121 commentedon Jan 11, 2023
There is a
-C link-dead-codeoption to force non-generic functions being monomorphized.lukas-code commentedon Feb 9, 2023
For what it's worth, the behavior of
inline_consthere matches overflowing generics: playgroundtmandry commentedon Feb 14, 2023
Deferring discussion for now to the design meeting in rust-lang/lang-team#195.
@rustbot label: -I-lang-nominated
[-]inline_const does not evaluate in unused function[/-][+]unused function is not monomorphized, so post-mono lints only show up in debug builds (in particular affects associated and inline consts)[/+][-]unused function is not monomorphized, so post-mono lints only show up in debug builds (in particular affects associated and inline consts)[/-][+]unused function is not monomorphized, so post-mono lints do not show up (in particular affects associated and inline consts)[/+]RalfJung commentedon May 25, 2023
Closing in favor of #107503 which is basically the same underlying issue.