diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-04-15 22:00:14 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-04-16 17:53:27 +1000 |
| commit | 99dd5911a1026da0a374b697e4a0407a631eb388 (patch) | |
| tree | 4e88a1416f3c7336e83d2c1797aa0de76d8ca84b /src/libsyntax/ext/cfg.rs | |
| parent | 168b2d1a3f4569706fe4f9a2baee04e37f85d297 (diff) | |
| download | rust-99dd5911a1026da0a374b697e4a0407a631eb388.tar.gz rust-99dd5911a1026da0a374b697e4a0407a631eb388.zip | |
syntax: unify all MacResult's into a single trait.
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).
Diffstat (limited to 'src/libsyntax/ext/cfg.rs')
| -rw-r--r-- | src/libsyntax/ext/cfg.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libsyntax/ext/cfg.rs b/src/libsyntax/ext/cfg.rs index d83a386554e..8cd899738bf 100644 --- a/src/libsyntax/ext/cfg.rs +++ b/src/libsyntax/ext/cfg.rs @@ -26,7 +26,7 @@ use parse::token::InternedString; use parse::token; use parse; -pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { +pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> ~base::MacResult { let mut p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.iter() @@ -47,5 +47,5 @@ pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::M let matches_cfg = attr::test_cfg(cx.cfg().as_slice(), in_cfg.iter().map(|&x| x)); let e = cx.expr_bool(sp, matches_cfg); - MRExpr(e) + MacExpr::new(e) } |
