-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Implement static_assert attribute #6670
Conversation
Nice. Could this be implemented as a macro à la Boost's StaticAssert? |
I don't believe so, but I'm not sure. Macros run very early in the compilation process, before there's enough information to actually do the assertion. I'm also not sure if macros can expand into items with attributes, which is the only non-invasive way to implement this. Ideally it wouldn't be an attribute though. It's really nasty to have bools floating around in your statics just for compiletime assertions. But it's the only way to implement it on the existing language (afaik). Although if |
Not sure whether you meant this with your last sentence: how about a macro that generates the current solution?
expanding to
|
Like I said, I'm not sure that it is possible to expand a macro into an item with attributes, and not sure if it's possible inside of functions. If so, great! Generating a non-conflicting name is going to be the hard part I think. I've opened #6676. By my last sentence I mean if when |
@cmr: expanding to |
At that point I'd much rather special case it than add stuff to the AST, it's bad enough as it is without phantom mods. |
@huonw: would it be undesireable or hard to make Rust support anonymous modules as in |
if x.slice(0, x.len()) == "static_assert" { | ||
let v = ccx.const_values.get_copy(&item.id); | ||
unsafe { | ||
warn!("doin' it! %?", v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this warn! call?
This verifies that a static item evaluates to true, at compile time.
This verifies that a static item evaluates to true, at compile time.
…1995 Add `manual_bits` lint Closes rust-lang#6670 --- changelog: new lint: [`manual_bits`]
This verifies that a static item evaluates to true, at compile time.