about summary refs log tree commit diff
path: root/src/libsyntax/ext/expand.rs
AgeCommit message (Collapse)AuthorLines
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
2014-07-08test harness cleanupJohn Clements-27/+20
2014-07-08added test for method arg hygieneJohn Clements-0/+13
2014-07-08std: Rename the `ToStr` trait to `ToString`, and `to_str` to `to_string`.Richo Healey-6/+6
[breaking-change]
2014-07-05rustc: Remove CrateId and all related supportAlex Crichton-6/+5
This commit removes all support in the compiler for the #[crate_id] attribute and all of its derivative infrastructure. A list of the functionality removed is: * The #[crate_id] attribute no longer exists * There is no longer the concept of a version of a crate * Version numbers are no longer appended to symbol names * The --crate-id command line option has been removed To migrate forward, rename #[crate_id] to #[crate_name] and only the name of the crate itself should be mentioned. The version/path of the old crate id should be removed. For a transitionary state, the #[crate_id] attribute is still accepted if the #[crate_name] is not present, but it is warned about if it is the only identifier present. RFC: 0035-remove-crate-id [breaking-change]
2014-07-04implement hygiene for ExprFnBlock and ExprProcJohn Clements-1/+15
2014-07-04added test cases for closure arg hygieneJohn Clements-0/+22
2014-07-04comments onlyJohn Clements-3/+2
2014-07-04hygiene for item fn argsJohn Clements-7/+49
also, introduce fn_decl_arg_bindings and expand_and_rename abstractions
2014-07-04comments & test cases for IdentRenamersJohn Clements-11/+63
2014-07-04use PatIdentRenamer for match bindingsJohn Clements-10/+5
2014-07-04comments onlyJohn Clements-3/+3
2014-07-04new_mark -> apply_mark, new_rename -> apply_renameJohn Clements-4/+4
2014-07-04add PatIdentRenamerJohn Clements-6/+37
2014-07-04move RenameList to mtwt, add new_renames abstractionJohn Clements-5/+2
2014-07-04comments, whitespace, rename NameFinderContext to PatIdentFinderJohn Clements-19/+15
2014-07-03simplify and uncomment item-fn-arg hygiene unit testJohn Clements-9/+6
2014-07-03Fix spelling errors.Joseph Crail-1/+1
2014-07-03Simplify PatIdent to contain an Ident rather than a PathJohn Clements-14/+2
Rationale: for what appear to be historical reasons only, the PatIdent contains a Path rather than an Ident. This means that there are many places in the code where an ident is artificially promoted to a path, and---much more problematically--- a bunch of elements from a path are simply thrown away, which seems like an invitation to some really nasty bugs. This commit replaces the Path in a PatIdent with a SpannedIdent, which just contains an ident and a span.
2014-06-27adjust fold to fold over interpolated items/exprs/etc.John Clements-2/+2
Closes #15221
2014-06-27added unit and standalone test for 15221, extra debugging outputJohn Clements-5/+26
2014-06-27remove trailing whitespaceJohn Clements-1/+1
2014-06-27hygiene for match-bound vars now implementedJohn Clements-24/+33
Closes #9384
2014-06-27improve match test case to include guardJohn Clements-4/+4