Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upremove static_assert #1096
Conversation
lilyball
reviewed
Apr 28, 2015
| [issue]: https://github.com/rust-lang/rust/issues/6676 | ||
|
|
||
| So why not improve `static_assert`? With compile time function evaluation, the | ||
| idea of a ‘static assertion’ doesn’t need to have language semantics. Either |
This comment has been minimized.
This comment has been minimized.
lilyball
Apr 28, 2015
Contributor
I don't see how CTFE obviates the desire for static_assert. If anything, I think CTFE makes static_assert much more powerful. CTFE allows us to calculate things at compile-time, and static_assert then lets you abort compilation if a given CTFE expression doesn't have the expected value.
That said, with CTFE, I'd expect static_assert to take the form of a macro static_assert!(condition[, message]).
This comment has been minimized.
This comment has been minimized.
steveklabnik
Apr 28, 2015
Author
Member
I was under the assumption that in a macro, you could just panic, or use something like https://github.com/huonw/compile_msg 's compile_error, which would outright replace the current static_assert.
This comment has been minimized.
This comment has been minimized.
lilyball
Apr 28, 2015
Contributor
I don't know what the current thinking is on CTFE, but I'm a little skeptical that panicking is something that would be compatible with CTFE. Similarly, I don't know whether CTFE would be able to use syntax extensions like compile_error (as opposed to a syntax extension evaluating a CTFE, which is what my proposed static_assert!() would be).
This comment has been minimized.
This comment has been minimized.
lilyball
Apr 28, 2015
Contributor
I suppose with CTFE, this static_assert!() macro could be provided by a crate, although it seems like a reasonable candidate to bake into the language (e.g. because the standard libraries might want to use it).
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
P1start
Apr 29, 2015
Contributor
Ideally, assuming a CTFE where begin_unwind[_fmt] (and whatever other functions are needed for panic!) are const fns (throwing compile errors at runtime) then we could just use the regular assert! macro:
static _assert: () = assert!(FOO);
// Or, in a future Rust where statements are allowed at module-level:
assert!(FOO);
This comment has been minimized.
This comment has been minimized.
|
The current form of |
This comment has been minimized.
This comment has been minimized.
|
+1 |
This comment has been minimized.
This comment has been minimized.
|
As someone who uses |
msiemens
reviewed
Apr 29, 2015
|
|
||
| Throughout its life, `static_assert` has been... weird. Graydon suggested it | ||
| [in May of 2013][suggest], and it was | ||
| [implemented][https://github.com/rust-lang/rust/pull/6670] shortly after. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ben0x539
commented
Apr 29, 2015
|
alternative: provide a macro |
This comment has been minimized.
This comment has been minimized.
|
The “want” to remove static_assert is intense here. It infects compiler all the way to trans. If we’re keeping it, I’d rather see this implemented within bounds of CTFE somehow. |
nrc
assigned
steveklabnik
Apr 30, 2015
This comment has been minimized.
This comment has been minimized.
|
@nrc given that I'm the author, I probably shouldn't shepard? |
This comment has been minimized.
This comment has been minimized.
|
@pythonesque what's the use case? When I implemented this I planned on usnig it to assert that sizes of things were the same but constant expressions aren't powerful enough. As the original designer and implementor, |
This comment has been minimized.
This comment has been minimized.
|
@cmr I use it to assert that |
This comment has been minimized.
This comment has been minimized.
|
I'm in favour of removing this and just using |
This comment has been minimized.
This comment has been minimized.
ssokolow
commented
May 7, 2015
|
|
This comment has been minimized.
This comment has been minimized.
|
No tests running at all seems like an orthogonal problem that should be solved anyway. :) In any case, replacing the |
This comment has been minimized.
This comment has been minimized.
ssokolow
commented
May 7, 2015
|
Wait... the |
This comment has been minimized.
This comment has been minimized.
|
I distinctly remember writing a patch that explains this, but I cannot find
it in the testing guide now :(
Yes, rustdoc is only able to test libraries, not binaries.
|
This comment has been minimized.
This comment has been minimized.
|
rust-lang/rust#24508 <- hmmmmmm
|
This comment has been minimized.
This comment has been minimized.
|
oh! it's in http://doc.rust-lang.org/nightly/book/documentation.html#running-documentation-tests
but not in the testing guide. that's an oversight. I'll fix that now.
|
This comment has been minimized.
This comment has been minimized.
|
wooo reading github first thing in the morning. I should drink more coffee.
It's true that _rustdoc_ cannot test binary crates, but #test doesn't
work either? I'm not aware of that.
|
This comment has been minimized.
This comment has been minimized.
|
@ssokolow hm, a fn main() {
println!("Hello, world!");
}
#[test]
fn foo() {}(If you're still having problems I'm happy to help, but we should take it to stackoverflow or users rather than here.) |
This comment has been minimized.
This comment has been minimized.
|
Note: I have created a replacement lint-plugin: https://crates.io/crates/static_assert So now there's zero reason for this to stay in the compiler. Usage example: #![feature(plugin, custom_attribute)]
#![plugin(static_assert_)]
fn main() {
#[static_assert_]
const TEST: bool = false;
}I haven't figured out yet how to silence the "unused" warnings, but I'm working on it. Also the next step is to create a macro that automatically creates a temporary constant + adds the attribute (maybe even the Note2: once Edit: I just noticed the original was on static fields not on constants... so it's not a drop-in replacement. sorry about that. |
SimonSapin
added a commit
to servo/string-cache
that referenced
this pull request
May 11, 2015
SimonSapin
added a commit
to servo/string-cache
that referenced
this pull request
May 11, 2015
This comment has been minimized.
This comment has been minimized.
|
FWIW, I’ve replaced one usage of |
nrc
added
the
T-lang
label
May 15, 2015
This comment has been minimized.
This comment has been minimized.
|
Hear ye, hear ye. This RFC is now in final comment period until June 2nd. |
nikomatsakis
added
the
final-comment-period
label
May 26, 2015
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
ssokolow
commented
May 27, 2015
|
@SimonSapin Unless I missed an announcement that compiler plugins will work in stable channel, I'd hardly call it zero reason. |
This comment has been minimized.
This comment has been minimized.
|
@ssokolow NB. |
This comment has been minimized.
This comment has been minimized.
ssokolow
commented
May 27, 2015
|
Ahh. That makes sense. It can get a bit difficult to keep track of which features I'm not currently using are stable. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I think I agree with @huonw that, in practice, adding a |
This comment has been minimized.
This comment has been minimized.
|
I'm fine with removing |
This comment has been minimized.
This comment has been minimized.
|
Based on the comment thread, we've decided to accept this RFC to remove --- Language Subteam |
nikomatsakis
merged commit c385c9b
into
rust-lang:master
Jun 2, 2015
This comment has been minimized.
This comment has been minimized.
|
I will rebase my implementation PR later today or tomorrow.
|
steveklabnik commentedApr 28, 2015
rendered