]> git.lizzy.rs Git - rust.git/commit
auto merge of #13527 : huonw/rust/macro-expander-trait, r=sfackler
authorbors <bors@rust-lang.org>
Wed, 16 Apr 2014 09:16:30 +0000 (02:16 -0700)
committerbors <bors@rust-lang.org>
Wed, 16 Apr 2014 09:16:30 +0000 (02:16 -0700)
commit61f788c772a1e0cefb19c54f12fbf42a65464334
tree1cf3913195cf28e65f44460c5861ffc1cd7514b3
parente33228727e97e3abb95ca91f6b6049f8682db7d0
parent99dd5911a1026da0a374b697e4a0407a631eb388
auto merge of #13527 : huonw/rust/macro-expander-trait, r=sfackler

There's now one unified way to return things from a macro, instead of
being able to choose the `AnyMacro` trait or the `MRItem`/`MRExpr`
variants of the `MacResult` enum. This does simplify the logic handling
the expansions, but the biggest value of this is it makes macros in (for
example) type position easier to implement, as there's this single thing
to modify.

By my measurements (using `-Z time-passes` on libstd and librustc etc.),
this appears to have little-to-no impact on expansion speed. There are
presumably larger costs than the small number of extra allocations and
virtual calls this adds (notably, all `macro_rules!`-defined macros have
not changed in behaviour, since they had to use the `AnyMacro` trait
anyway).

---

Summary of changes for dynamic syntax extension maintainers:

- `MacResult` is now a trait, and is returned as `~MacResult`
- `MRExpr` & `MRItem` are now `MacExpr::new` and `MacItem:new` respectively (which return `~MacResult`s)
- `MacResult::dummy_...` is `DummyResult::any` or `DummyResult::expr`