-
Notifications
You must be signed in to change notification settings - Fork 59
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
Are (non-free) generic constants guaranteed to be evaluated? #409
Comments
This code is equivalent to an assert at the beginning of the function, so it definitely will never be callable without a panic, i.e. as far as protecting the This isn't really an unsafe code question though, it's probably t-lang. |
Okay sounds good, thanks! It makes sense to me too that it would be guaranteed, but I'll ask t-lang just to be sure 🙂 |
We guarantee that every constant mentioned syntactically within a function that executes at runtime, has been previously executed at compiletime. So I agree with @digama0. I don't know if and where we document that guarantee, though. |
Closing in favor of rust-lang/rust#112090. |
Thanks to this suggestion by @gootorov, we're considering doing something like the following in zerocopy:
The nightly reference guarantees that "free constants are always evaluated at compile time." However, that's not quite what we have here - we evaluate the constant
REF_TRANSMUTABLE_INTO
but assign it to a runtime variable (let _: () = ...
). If we replacedlet _
withconst _
, that would be a free constant, but it would never compile (even when we wanted it to) because a constant in a function body isn't allowed to reference types which are generic in that context.What I want to know is: Is this constant guaranteed to be evaluated so long as
transmute_ref_into
is used?The text was updated successfully, but these errors were encountered: