Skip to content

Commit 57cfcb4

Browse files
committed
Add alternate proposal with minimal impact on the compiler
1 parent 8af46d5 commit 57cfcb4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

text/0000-erfc-post-build-contexts.md

+23
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,29 @@ these tools usually operate at a differeny layer of abstraction so it might not
269269
A major drawback of this proposal is that it is very general, and perhaps too powerful. We're currently using the
270270
more focused API in the eRFC, and may switch to this during experimentation if a pressing need crops up.
271271

272+
## Alternative procedural macro with minimal compiler changes
273+
274+
The above proposal can be made even more general, minimizing the impact on the compiler.
275+
276+
This assumes that `#![foo]` ("inner attribute") macros work on modules and on crates.
277+
278+
The idea is that the compiler defines no new proc macro surface, and instead simply exposes
279+
a `--attribute` flag. This flag, like `-Zextra-plugins`, lets you attach a proc macro attribute
280+
to the whole crate before compiling. (This flag actually generalizes a bunch of flags that the
281+
compiler already has)
282+
283+
Test crates are now simply proc macro attributes:
284+
285+
```rust
286+
#[proc_macro_attr(attributes(test, foo, bar))]
287+
pub fn harness(crate: TokenStream) -> TokenStream {
288+
// ...
289+
}
290+
```
291+
292+
The cargo functionality will basically compile the file with the right dependencies
293+
and `--attribute=your_crate::harness`.
294+
272295
# Unresolved questions
273296
[unresolved]: #unresolved-questions
274297

0 commit comments

Comments
 (0)