summary refs log tree commit diff
path: root/src/libsyntax/ext/expand.rs
AgeCommit message (Collapse)AuthorLines
2014-10-01Limit recursion depth for macro expansions, closes #17628Florian Hahn-0/+2
2014-09-30Update after the fall out from the syntax::ptr changesJakub Wieczorek-30/+36
2014-09-30Update based on PR feedbackKevin Ballard-20/+16
2014-09-30Produce a better error for irrefutable `if let` patternsKevin Ballard-1/+1
Modify ast::ExprMatch to include a new value of type ast::MatchSource, making it easy to tell whether the match was written literally or produced via desugaring. This allows us to customize error messages appropriately.
2014-09-30Desugar 'if let' into the appropriate 'match'Kevin Ballard-1/+90
2014-09-26Hide the quote_*! macros when the feature gate is offKeegan McAllister-22/+21
This makes it easier to experiment with improved quasiquoting as an ordinary plugin library. The list of quote macros in feature_gate.rs was already out of sync; this commit also prevents that problem in the future.
2014-09-20auto merge of #17319 : kmcallister/rust/method-macro-bt, r=pcwaltonbors-1/+4
We were leaving these on the stack, causing spurious backtraces.
2014-09-19rollup merge of #17338 : nick29581/variants-namespaceAlex Crichton-3/+3
2014-09-19Add enum variants to the type namespaceNick Cameron-3/+3
Change to resolve and update compiler and libs for uses. [breaking-change] Enum variants are now in both the value and type namespaces. This means that if you have a variant with the same name as a type in scope in a module, you will get a name clash and thus an error. The solution is to either rename the type or the variant.
2014-09-18syntax: use an index in CodeMap instead of Gc for ExpnInfo.Eduard Burtescu-22/+5
2014-09-17Pop the expansion context after expanding a method macroKeegan McAllister-1/+4
We were leaving these on the stack, causing spurious backtraces. I've confirmed that this test fails without the fix.
2014-09-16Fallout from renamingAaron Turon-13/+13
2014-09-14syntax: tests: fix fallout from using ptr::P.Eduard Burtescu-1/+2
2014-09-14syntax: fix fallout from using ptr::P.Eduard Burtescu-288/+288
2014-09-13auto merge of #17162 : sfackler/rust/decorator-traits, r=huonwbors-5/+4
The other extension types already worked this way and it can be useful to track some state along with the extension. I also removed the `BasicMacroExpander` and `BasicIdentMacroExpander` since the span inside of them was never used. The expander function types now directly implement the relevant trait.
2014-09-12Track the visited AST's lifetime throughout Visitor.Eduard Burtescu-4/+4
2014-09-12Remove largely unused context from Visitor.Eduard Burtescu-23/+22
2014-09-10Change ItemModifier and ItemDecorator to traitsSteven Fackler-5/+4
For convenience, the traits are implemented for the respective bare functions. Change code from this: ```rust ItemDecorator(some_function) // or ItemModifier(some_other_function) ``` to ```rust ItemDecorator(box some_function) // or ItemModifier(box some_other_function) ``` [breaking-change]
2014-08-29Add support for labeled while loops.Pythoner6-0/+6
2014-08-27Implement generalized object and type parameter bounds (Fixes #16462)Niko Matsakis-89/+102
2014-08-13librustc: Parse, but do not fully turn on, the `ref` keyword forPatrick Walton-2/+4
by-reference upvars. This partially implements RFC 38. A snapshot will be needed to turn this on, because stage0 cannot yet parse the keyword. Part of #12381.
2014-07-31auto merge of #15999 : Kimundi/rust/fix_folder, r=nikomatsakisbors-6/+6
Note: This PR is motivated by an attempt to write an custom syntax extension that tried to use `syntax::fold`, and that could only do so by fixing bugs in it and copying out private functions. --- Refactored `syntax::fold` Prior to this, the code there had a few issues: - Default implementations inconsistenly either had the prefix `noop_` or not. - Some default methods where implemented in terms of a public noop function for user code to call, others where implemented directly on the trait and did not allow users of the trait to reuse the code. - Some of the default implementations where private, and thus not reusable for other implementors. - There where some bugs where default implemntations called other default implementations directly, rather than to the underlying Folder, with the result of some ast nodes never being visted even if the user implemented that method. (For example, the current Folder never folded struct fields) This commit solves this situation somewhat radically by making __all__ `fold_...` functions in the module into Folder methods, and implementing them all in terms of public `noop_...` functions for other implementors to call out to. Some public functions had to be renamed to fit the new system, so this is a breaking change. --- Also added a few trait implementations to `ast` types
2014-07-29libsyntax: Don't ICE on macro invocation in count expr of fixed array type.Luqman Aden-2/+5
2014-07-29Refactored syntax::fold.Marvin Löbel-6/+6
Prior to this, the code there had a few issues: - Default implementations inconsistently either had the prefix `noop_` or not. - Some default methods where implemented in terms of a public noop function for user code to call, others where implemented directly on the trait and did not allow users of the trait to reuse the code. - Some of the default implementations where private, and thus not reusable for other implementors. - There where some bugs where default implementations called other default implementations directly, rather than to the underlying Folder, with the result of some AST nodes never being visited even if the user implemented that method. (For example, the current Folder never folded struct fields) This commit solves this situation somewhat radically by making _all_ `fold_...` functions in the module into Folder methods, and implementing them all in terms of public `noop_...` functions for other implementors to call out to. Some public functions had to be renamed to fit the new system, so this is a breaking change. [breaking-change]
2014-07-24librustc: Stop desugaring `for` expressions and translate them directly.Patrick Walton-97/+7
This makes edge cases in which the `Iterator` trait was not in scope and/or `Option` or its variants were not in scope work properly. This breaks code that looks like: struct MyStruct { ... } impl MyStruct { fn next(&mut self) -> Option<int> { ... } } for x in MyStruct { ... } { ... } Change ad-hoc `next` methods like the above to implementations of the `Iterator` trait. For example: impl Iterator<int> for MyStruct { fn next(&mut self) -> Option<int> { ... } } Closes #15392. [breaking-change]
2014-07-22Refactoring: Only use `MacroExpander` for expanding outside ofMarvin Löbel-11/+1
`syntax::ext::expand`
2014-07-21Moved `syntax::ext::base::SyntaxEnv` into `syntax::ext::base::ExtCtx`Marvin Löbel-184/+194
2014-07-21repair macro docsJohn Clements-3/+3
In f1ad425199b0d89dab275a8c8f6f29a73d316f70, I changed the handling of macros, to prevent macro invocations from occurring in fully expanded source. Instead, I added a side table. It contained only the spans of the macros, because this was the only information required in order to make macro export work. However, librustdoc was also affected by this change, since it extracts macro information in a similar way. As a result of the earlier change, exported macros were no longer documented. In order to repair this, I've adjusted the side table to contain whole items, rather than just the spans.
2014-07-18librustc: Implement unboxed closures with mutable receiversPatrick Walton-1/+9
2014-07-18auto merge of #15725 : aochagavia/rust/vec, r=alexcrichtonbors-1/+1
* Deprecated `to_owned` in favor of `to_vec` * Deprecated `into_owned` in favor of `into_vec` [breaking-change]
2014-07-17librustc: Remove cross-borrowing of `Box<T>` to `&T` from the language,Patrick Walton-12/+14
except where trait objects are involved. Part of issue #15349, though I'm leaving it open for trait objects. Cross borrowing for trait objects remains because it is needed until we have DST. This will break code like: fn foo(x: &int) { ... } let a = box 3i; foo(a); Change this code to: fn foo(x: &int) { ... } let a = box 3i; foo(&*a); [breaking-change]
2014-07-17Rename functions in the CloneableVector traitAdolfo Ochagavía-1/+1
* Deprecated `to_owned` in favor of `to_vec` * Deprecated `into_owned` in favor of `into_vec` [breaking-change]
2014-07-13macro expansion for methodsJohn Clements-25/+47
Closes #4621
2014-07-13expansion abstractionJohn Clements-144/+114
2014-07-13remove no-stmt checkJohn Clements-4/+0
nothing wrong with a statement expanding into 0 stmts, that I can see.
2014-07-13macro method unit test case fixJohn Clements-2/+2
2014-07-13refactor Method definition to make space for macrosJohn Clements-12/+16
This change propagates to many locations, but because of the Macro Exterminator (or, more properly, the invariant that it protects), macro invocations can't occur downstream of expansion. This means that in librustc and librustdoc, extracting the desired field can simply assume that it can't be a macro invocation. Functions in ast_util abstract over this check.
2014-07-12auto merge of #15601 : jbclements/rust/disable-default-macro-behavior, ↵bors-5/+30
r=alexcrichton Our AST definition can include macro invocations, which can expand into all kinds of things. Macro invocations are expanded away during expansion time, and the rest of the compiler doesn't have to deal with them. However, we have no way of enforcing this. This patch adds two protective mechanisms. First, it adds a (quick) explicit check that ensures there are no macro invocations remaining in the AST after expansion. Second, it updates the visit and fold mechanisms so that by default, they will not traverse macro invocations. It's easy enough to add this, if desired (it's documented in the source, and examples appear, e.g. in the IdentFinder. Along the way, I also consulted with @sfackler to refactor the macro export mechanism so that it stores macro text spans in a side table, rather than leaving them in the AST.
2014-07-11add Macro ExterminatorJohn Clements-0/+19
the Macro Exterminator ensures that there are no macro invocations in an AST. This should help make later passes confident that there aren't hidden items, methods, expressions, etc.
2014-07-11make walk/visit_mac opt-in onlyJohn Clements-1/+6
macros can expand into arbitrary items, exprs, etc. This means that using a default walker or folder on an AST before macro expansion is complete will miss things (the things that the macros expand into). As a partial fence against this, this commit moves the default traversal of macros into a separate procedure, and makes the default trait implementation signal an error. This means that Folders and Visitors can traverse macros if they want to, but they need to explicitly add an impl that calls the walk_mac or fold_mac procedure This should prevent problems down the road.
2014-07-11use side table to store exported macrosJohn Clements-4/+5
Per discussion with @sfackler, refactored the expander to change the way that exported macros are collected. Specifically, a crate now contains a side table of spans that exported macros go into. This has two benefits. First, the encoder doesn't need to scan through the expanded crate in order to discover exported macros. Second, the expander can drop all expanded macros from the crate, with the pleasant result that a fully expanded crate contains no macro invocations (which include macro definitions).
2014-07-11Add scaffolding for assigning alpha-numeric codes to rustc diagnosticsJakub Wieczorek-2/+2
2014-07-09Fix all the test falloutCorey Richardson-5/+5
2014-07-09syntax: doc comments all the thingsCorey Richardson-5/+5
2014-07-08carry self ident forward through re-parsingJohn Clements-2/+15
formerly, the self identifier was being discarded during parsing, which stymies hygiene. The best fix here seems to be to attach a self identifier to ExplicitSelf_, a change that rippled through the rest of the compiler, but without any obvious damage.
2014-07-08macro literals should be compared by name onlyJohn Clements-0/+8
2014-07-08implement hygiene for method argsJohn Clements-0/+25
2014-07-08test case for expansion of method macroJohn Clements-2/+13
2014-07-08introducing let-syntaxJohn Clements-0/+18
The let-syntax expander is different in that it doesn't apply a mark to its token trees before expansion. This is used for macro_rules, and it's because macro_rules is essentially MTWT's let-syntax. You don't want to mark before expand sees let-syntax, because there's no "after" syntax to mark again. In some sense, the cleaner approach might be to introduce a new AST node that macro_rules expands into; this would make it clearer that the expansion of a macro is distinct from the addition of a new macro binding. This should work for now, though...
2014-07-08self arg macro test caseJohn Clements-0/+13