mozilla/rust — pull request #8182 by alexcrichton (2013-08-01 07:15:56+00:00)
Title: Add initial support for a new formatting syntax

This pull request is the initial framework necessary for the advent of a new
string formatting system which will eventually replace `fmt!`. There's certainly
a lot of stuff going on here, so here's a bit of a summary:

This entire implementation is based off of the discussions had on the mailing
lists at:
* https://mail.mozilla.org/pipermail/rust-dev/2013-July/004961.html
* https://mail.mozilla.org/pipermail/rust-dev/2013-July/004999.html

It should be noted that this is not ready to actually replace the `fmt!` macro.
This request simply lays all of the groundwork to implement this new system.
The largest missing component is that all formatting specifiers are ignored.
Additionally, I'd like to take some time to bikeshed the format modifier syntax
after researching it a bit more.

Some notable points of the implementation
* The [parser](https://github.com/alexcrichton/rust/blob/4a428d89423a43e7f46eac4cf16cd23c6dcd4b1a/src/libstd/fmt/ct.rs) is non-trivial
* it attempted to use conditions, but then #8179 struck
* The [sprintf function](https://github.com/alexcrichton/rust/blob/4a428d89423a43e7f46eac4cf16cd23c6dcd4b1a/src/libstd/fmt/mod.rs) is still flagged as `unsafe`
* The [syntax extension](https://github.com/alexcrichton/rust/blob/4a428d89423a43e7f46eac4cf16cd23c6dcd4b1a/src/libsyntax/ext/ifmt.rs) was written from scratch and has all of the compile-time checks the parser can't have
* A [new pass was added](https://github.com/alexcrichton/rust/blob/4a428d89423a43e7f46eac4cf16cd23c6dcd4b1a/src/librustc/middle/fmt.rs) to collect format traits into a local map
* The list of format traits are emitted to libraries so they [can be loaded](https://github.com/alexcrichton/rust/blob/4a428d89423a43e7f46eac4cf16cd23c6dcd4b1a/src/librustc/metadata/decoder.rs#L490) later on
* A [new expression](https://github.com/alexcrichton/rust/blob/4a428d89423a43e7f46eac4cf16cd23c6dcd4b1a/src/libsyntax/ast.rs#L509-L510) was added. The reasoning behind this is that macro expansion happens before crate resolution, and the list of formatting traits aren't known until after external crate resolution.

Testing wise, I've included
* parser unit tests
* runtime unit tests
* run-pass tests for all the new functionality
* lots of compile-fail tests

Note that all of the code links will become stale as I rebase, but I don't
think that anything major will be changing at this point. The best examples can
be found in the run-pass test, although there's probably a number of cases that
I've missed!

I also realize that this is very large, although I couldn't figure out a really
good way of splitting it up. If there are suggestions of how to make this a bit
more manageable, than I'd definitely take the time to split things up.