mozilla/rust — pull request #4035 by brson (2012-11-25 01:45:10+00:00)
Title: Remove the crate language

r? @graydon, @nikomatsakis

Working towards #2176

This series completely removes the special surface language for .rc files. It uses several hacks required until the next snapshot.

After this is completed .rc files will be parsed exactly the same as .rs files and companion mods will no longer exist, either at the crate level or directory level.

There's not a whole lot to review here, as it's just rewriting the crate files to use features compatible with the new model, but it is a big change.

There are two notable side-effects of this change:

1) The int-template and iter-trait hacks used a latent property of our directory companion mods to 'merge' the contents of two different files into a single crate. In lieu of item macros this will be supported by a new parser hack that uses a `#[merge = "path/to/file.rs"]` attribute.

2) There will no longer be any in-language notion of directory structure. Through ongoing discussions it's not obvious what the right solution to this is. In the meantime, crates can use `#[path = "path/to/file.rs"]` to impose any directory structure they want. I think this itself is a decent compromise, gives us room to experiment with the correct patterns here.

In the medium-term, the rust repo itself will prefer the following pattern to create directory structure:

rustc.rc:

```
#[path = "front/mod.rs"]
mod front;
#[path = "middle/mod.rs"]
mod middle;
#[path = "back/mod.rs"]
mod back;
```

front/mod.rs:

```
mod core_inject;
mod test;
```

Modules that are stored in directories will use a `mod.rs` file *inside* the directory (vs. today's code where the mod file is *outside* the directory).

Transitional ugliness:

* core, std, syntax, and rustc are all using a massive hack to force stage0 to use one crate file and the others to use a different one. Files that begin with `// DIVERT` are automatically parsed from a different file called `alternate_crate.rc`. This allows stage0 to continue using it's directory modules while stage1+ use the above described strategy.

* There's a lot of usage of the new `#[merge]` attribute, but these are transitional except for the ones in core that implement iter-trait, etc.