archives of rust-dev@mozilla.org (2010-2015)
 help / color / mirror / Atom feed
* [rust-dev] Surpassing C in conditional compilation
@ 2015-01-19 21:23 Christopher Bergqvist
  0 siblings, 0 replies; only message in thread
From: Christopher Bergqvist @ 2015-01-19 21:23 UTC (permalink / raw)
  To: rust-dev

Hi Rust devs!

First of all, thank you for putting so much effort into creating this promising language!

I would be glad to hear your thoughts on some minor bikeshedding before the 1.0 release. From what I can see, the conditional compilation in Rust shares a weakness with the C preprocessor. The problem is lacking checks against misspelled identifiers, as in this example:

#[cfg(target_oss="dragon_fly")]
fn foo() { syntaxError }

Here, target_oss has an extra "s", and dragon_fly should not have the "_". However, the compiler will compile the code without notifying the programmer that anything is wrong. I propose that cfg-identifiers should be treated similarly to other identifiers, so that they can trigger unresolved errors.

One way I see to implement this for custom cfg identifiers specified on the command line is going from

$ rustc --cfg some_condition

to

$ rustc --cfg some_condition=true

And then the code would look like

#[cfg(some_condition=true)]
fn conditional_function() { }

Instead of just

#[cfg(possibly_correct_name)]
fn conditional_function() { }

Alone, this change would require the programmer to always specify all values of all custom cfg identifiers when building code that uses them. To avoid that, it would be good to be able to define default values of identifiers in .rs files. There could even be .rs files distributed with rustc which contain specifications of all built-in cfg identifiers (and possibly also lists of their allowed values).

(There's also the inconsistency in "=" vs "==" equality operators between cfg-expressions and regular Rust expressions, an inconsistency C does not share, but that is not a big concern).

Thanks for reading this far,
Chris

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-01-19 21:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-19 21:23 [rust-dev] Surpassing C in conditional compilation Christopher Bergqvist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox