Skip to content

Commit

Permalink
Add alternate proposal with minimal impact on the compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Feb 1, 2018
1 parent 00c3756 commit 08c5053
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions text/0000-erfc-post-build-contexts.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,29 @@ these tools usually operate at a differeny layer of abstraction so it might not
A major drawback of this proposal is that it is very general, and perhaps too powerful. We're currently using the
more focused API in the eRFC, and may switch to this during experimentation if a pressing need crops up.

## Alternative procedural macro with minimal compiler changes

The above proposal can be made even more general, minimizing the impact on the compiler.

This assumes that `#![foo]` ("inner attribute") macros work on modules and on crates.

The idea is that the compiler defines no new proc macro surface, and instead simply exposes
a `--attribute` flag. This flag, like `-Zextra-plugins`, lets you attach a proc macro attribute
to the whole crate before compiling. (This flag actually generalizes a bunch of flags that the
compiler already has)

Test crates are now simply proc macro attributes:

```rust
#[proc_macro_attr(attributes(test, foo, bar))]
pub fn harness(crate: TokenStream) -> TokenStream {
// ...
}
```

The cargo functionality will basically compile the file with the right dependencies
and `--attribute=your_crate::harness`.

# Unresolved questions
[unresolved]: #unresolved-questions

Expand Down

0 comments on commit 08c5053

Please sign in to comment.