about summary refs log tree commit diff
path: root/src/libsyntax/ext
AgeCommit message (Collapse)AuthorLines
2015-07-12syntax: Allow semi tokens after macro ty/pathAlex Crichton-1/+1
This commit expands the follow set of the `ty` and `path` macro fragments to include the semicolon token as well. A semicolon is already allowed after these tokens, so it's currently a little too restrictive to not have a semicolon allowed. For example: extern { fn foo() -> i32; // semicolon after type } fn main() { struct Foo; Foo; // semicolon after path }
2015-07-10Change some instances of .connect() to .join()Wesley Wiser-2/+2
2015-07-10Auto merge of #26907 - nrc:save-fns, r=brsonbors-3/+4
r? @huonw
2015-07-09Use vec![elt; n] where possibleUlrik Sverdrup-2/+1
The common pattern `iter::repeat(elt).take(n).collect::<Vec<_>>()` is exactly equivalent to `vec![elt; n]`, do this replacement in the whole tree. (Actually, vec![] is smart enough to only call clone n - 1 times, while the former solution would call clone n times, and this fact is virtually irrelevant in practice.)
2015-07-09save-analysis: API-ify pathsNick Cameron-1/+1
2015-07-09Fix a bug where macros in expression position don't have expansion inidices ↵Nick Cameron-3/+4
in their spans
2015-06-18Auto merge of #26347 - nagisa:macro-exp, r=nrcbors-19/+26
r? @nrc, because breakage was caused by https://github.com/rust-lang/rust/pull/25318
2015-06-16Remove superfluous variableSimonas Kazlauskas-2/+0
2015-06-16Fix file!(), line!() and column!() macrosSimonas Kazlauskas-19/+28
These used to return wrong results in case they were expanded inside compiler’s iternal syntax sugar (closures, if-let) expansions Fixes #26322
2015-06-14Replaced a comment mentioning a fixed issueMarkus Westerlind-3/+5
Replaced it with a comment mentioning the rationale for checking the discriminants first.
2015-06-13Utilize discriminant_value for more efficient derivingMarkus-39/+85
The new code generated for deriving on enums looks something like this: ```rust let __self0_vi = unsafe { std::intrinsics::discriminant_value(&self) } as i32; let __self1_vi = unsafe { std::intrinsics::discriminant_value(&__arg1) } as i32; let __self2_vi = unsafe { std::intrinsics::discriminant_value(&__arg2) } as i32; /// if __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... { match (...) { (Variant1, Variant1, ...) => Body1 (Variant2, Variant2, ...) => Body2, ... _ => ::core::intrinsics::unreachable() } } else { ... // catch-all remainder can inspect above variant index values. } ``` This helps massively for C-like enums since they will be compiled as a single comparison giving observed speedups of up to 8x. For more complex enums the speedup is more difficult to measure but it should not be slower to generate code this way regardless.
2015-06-11Conver reborrows to .iter() calls where appropriateJoshua Landau-1/+1
2015-06-10Removed many pointless calls to *iter() and iter_mut()Joshua Landau-17/+17
2015-06-07change some statics to constantsOliver 'ker' Schneider-0/+1
2015-05-27Auto merge of #25713 - Stebalien:pattern, r=alexcrichtonbors-0/+1
Needed to support: ```rust match X { pattern if Y ... } for pattern in Y {} ``` IMO, this shouldn't require an RFC because it can't interfere with any future language changes (because `pattern if` and `pattern in` are already legal in rust) and can't cause any ambiguity.
2015-05-24Auto merge of #25609 - nikomatsakis:const-fn, r=pnkfelixbors-2/+6
This is a port of @eddyb's `const-fn` branch. I rebased it, tweaked a few things, and added tests as well as a feature gate. The set of tests is still pretty rudimentary, I'd appreciate suggestions on new tests to write. Also, a double-check that the feature-gate covers all necessary cases. One question: currently, the feature-gate allows the *use* of const functions from stable code, just not the definition. This seems to fit our usual strategy, and implies that we might (perhaps) allow some constant functions in libstd someday, even before stabilizing const-fn, if we were willing to commit to the existence of const fns but found some details of their impl unsatisfactory. r? @pnkfelix
2015-05-22Allow patterns to be followed by if and in.Steven Allen-0/+1
Needed to support: match X { pattern if Y ... } for pattern in Y {}
2015-05-22Let MultiItemDecorator take `&Annotatable` (fixes #25683)Manish Goregaokar-34/+34
2015-05-21Make various fixes:Niko Matsakis-0/+1
- add feature gate - add basic tests - adjust parser to eliminate conflict between `const fn` and associated constants - allow `const fn` in traits/trait-impls, but forbid later in type check - correct some merge conflicts
2015-05-21syntax: parse `const fn` for free functions and inherent methods.Eduard Burtescu-2/+5
2015-05-17Make #[derive(Debug)] work with unsized fieldsSteven Fackler-5/+11
Closes #25394
2015-05-17Allow #[derive()] to generate unsafe methodsManish Goregaokar-1/+23
2015-05-17Auto merge of #25387 - eddyb:syn-file-loader, r=nikomatsakisbors-5/+5
This allows compiling entire crates from memory or preprocessing source files before they are tokenized. Minor API refactoring included, which is a [breaking-change] for libsyntax users: * `ParseSess::{next_node_id, reserve_node_ids}` moved to rustc's `Session` * `new_parse_sess` -> `ParseSess::new` * `new_parse_sess_special_handler` -> `ParseSess::with_span_handler` * `mk_span_handler` -> `SpanHandler::new` * `default_handler` -> `Handler::new` * `mk_handler` -> `Handler::with_emitter` * `string_to_filemap(sess source, path)` -> `sess.codemap().new_filemap(path, source)`
2015-05-16Auto merge of #25444 - nikomatsakis:macro-tt-fix, r=pnkfelixbors-34/+78
Permit token trees, identifiers, and blocks to be following by sequences. Fixes #25436. r? @pnkfelix
2015-05-15Permit token trees, identifiers, and blocks to be following byNiko Matsakis-34/+78
sequences. Fixes #25436.
2015-05-15syntax: Unquoting some statements requires trailing semicolonsErick Tryzelaar-3/+11
2015-05-15syntax: Add unquoting ast::{Generics,WhereClause}Erick Tryzelaar-0/+12
2015-05-14syntax: replace sess.span_diagnostic.cm with sess.codemap().Eduard Burtescu-1/+1
2015-05-14syntax: refactor (Span)Handler and ParseSess constructors to be methods.Eduard Burtescu-4/+4
2015-05-13Auto merge of #25318 - nrc:for-expn, r=sfacklerbors-9/+42
r? @sfackler
2015-05-13Merge branch 'master' into mulit-decorNick Cameron-3/+3
2015-05-12RebasingNick Cameron-17/+17
2015-05-12Merge branch 'master' intoNick Cameron-34/+42
2015-05-12Proper spans for for loop expansionNick Cameron-9/+42
2015-05-11Auto merge of #25085 - carols10cents:remove-old-tilde, r=steveklabnikbors-3/+3
There were still some mentions of `~[T]` and `~T`, mostly in comments and debugging statements. I tried to do my best to preserve meaning, but I might have gotten some wrong-- I'm happy to fix anything :)
2015-05-09Rollup merge of #25216 - barosl:no-more-task, r=ManishearthManish Goregaokar-1/+1
I've found that there are still huge amounts of occurrences of `task`s in the documentation. This PR tries to eliminate all of them in favor of `thread`.
2015-05-09Squeeze the last bits of `task`s in documentation in favor of `thread`Barosl Lee-1/+1
An automated script was run against the `.rs` and `.md` files, subsituting every occurrence of `task` with `thread`. In the `.rs` files, only the texts in the comment blocks were affected.
2015-05-08Fallout from fixing Issue 25199.Felix S. Klock II-3/+4
There are two interesting kinds of breakage illustrated here: 1. `Box<Trait>` in many contexts is treated as `Box<Trait + 'static>`, due to [RFC 599]. However, in a type like `&'a Box<Trait>`, the `Box<Trait>` type will be expanded to `Box<Trait + 'a>`, again due to [RFC 599]. This, combined with the fix to Issue 25199, leads to a borrowck problem due the combination of this function signature (in src/libstd/net/parser.rs): ```rust fn read_or<T>(&mut self, parsers: &mut [Box<FnMut(&mut Parser) -> Option<T>>]) -> Option<T>; ``` with this call site (again in src/libstd/net/parser.rs): ```rust fn read_ip_addr(&mut self) -> Option<IpAddr> { let ipv4_addr = |p: &mut Parser| p.read_ipv4_addr().map(|v4| IpAddr::V4(v4)); let ipv6_addr = |p: &mut Parser| p.read_ipv6_addr().map(|v6| IpAddr::V6(v6)); self.read_or(&mut [Box::new(ipv4_addr), Box::new(ipv6_addr)]) } ``` yielding borrowck errors like: ``` parser.rs:265:27: 265:69 error: borrowed value does not live long enough parser.rs:265 self.read_or(&mut [Box::new(ipv4_addr), Box::new(ipv6_addr)]) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` (full log at: https://gist.github.com/pnkfelix/e2e80f1a71580f5d3103 ) The issue here is perhaps subtle: the `parsers` argument is inferred to be taking a slice of boxed objects with the implicit lifetime bound attached to the `self` parameter to `read_or`. Meanwhile, the fix to Issue 25199 (added in a forth-coming commit) is forcing us to assume that each boxed object may have a destructor that could refer to state of that lifetime, and *therefore* that inferred lifetime is required to outlive the boxed object itself. In this case, the relevant boxed object here is not going to make any such references; I believe it is just an artifact of how the expression was built that it is not assigned type: `Box<FnMut(&mut Parser) -> Option<T> + 'static>`. (i.e., mucking with the expression is probably one way to fix this problem). But the other way to fix it, adopted here, is to change the `read_or` method type to force make the (presumably-intended) `'static` bound explicit on the boxed `FnMut` object. (Note: this is still just the *first* example of breakage.) 2. In `macro_rules.rs`, the `TTMacroExpander` trait defines a method with signature: ```rust fn expand<'cx>(&self, cx: &'cx mut ExtCtxt, ...) -> Box<MacResult+'cx>; ``` taking a `&'cx mut ExtCtxt` as an argument and returning a `Box<MacResult'cx>`. The fix to Issue 25199 (added in aforementioned forth-coming commit) assumes that a value of type `Box<MacResult+'cx>` may, in its destructor, refer to a reference of lifetime `'cx`; thus the `'cx` lifetime is forced to outlive the returned value. Meanwhile, within `expand.rs`, the old code was doing: ```rust match expander.expand(fld.cx, ...).make_pat() { ... => immutable borrow of fld.cx ... } ``` The problem is that the `'cx` lifetime, inferred for the `expander.expand` call, has now been extended so that it has to outlive the temporary R-value returned by `expanded.expand`. But call is also reborrowing `fld.cx` *mutably*, which means that this reborrow must end before any immutable borrow of `fld.cx`; but there is one of those within the match body. (Note that the temporary R-values for the input expression to `match` all live as long as the whole `match` expression itself (see Issue #3511 and PR #11585). To address this, I moved the construction of the pat value into its own `let`-statement, so that the `Box<MacResult>` will only live for as long as the initializing expression for the `let`-statement, and thus allow the subsequent immutable borrow within the `match`. [RFC 599]: https://github.com/rust-lang/rfcs/blob/master/text/0599-default-object-bound.md
2015-05-03Update old uses of ~ in comments and debugging statementsCarol Nichols-3/+3
2015-05-02Rename AstBuilder::expr_int -> AstBuilder::expr_isizeManish Goregaokar-5/+8
2015-05-01Get tests passingNick Cameron-2/+3
2015-05-01Give access to field attributes in ext::derivingManish Goregaokar-29/+33
2015-04-30Merge branch 'master' into mulit-decorNick Cameron-236/+129
2015-04-30WIP refactor expansion of decorators and move derive to MultiDecoratorNick Cameron-277/+299
2015-04-25Interpolate AST nodes in quasiquote.Geoffry Song-235/+128
This changes the `ToTokens` implementations for expressions, statements, etc. with almost-trivial ones that produce `Interpolated(*Nt(...))` pseudo-tokens. In this way, quasiquote now works the same way as macros do: already-parsed AST fragments are used as-is, not reparsed. The `ToSource` trait is removed. Quasiquote no longer involves pretty-printing at all, which removes the need for the `encode_with_hygiene` hack. All associated machinery is removed. A new `Nonterminal` is added, NtArm, which the parser now interpolates. This is just for quasiquote, not macros (although it could be in the future). `ToTokens` is no longer implemented for `Arg` (although this could be added again) and `Generics` (which I don't think makes sense). This breaks any compiler extensions that relied on the ability of `ToTokens` to turn AST fragments back into inspectable token trees. For this reason, this closes #16987. As such, this is a [breaking-change]. Fixes #16472. Fixes #15962. Fixes #17397. Fixes #16617.
2015-04-25Rebasing and making MulitDecorators workNick Cameron-29/+11
2015-04-25Merge branch 'syntax' of https://github.com/aochagavia/rust into mulit-decorNick Cameron-11/+99
Conflicts: src/librustc/plugin/registry.rs src/libsyntax/ext/base.rs src/libsyntax/ext/cfg_attr.rs src/libsyntax/ext/deriving/mod.rs src/libsyntax/ext/expand.rs src/libsyntax/print/pprust.rs src/test/auxiliary/macro_crate_test.rs
2015-04-24Change name of unit test sub-module to "tests".Johannes Oertel-1/+1
Changes the style guidelines regarding unit tests to recommend using a sub-module named "tests" instead of "test" for unit tests as "test" might clash with imports of libtest.
2015-04-21syntax: Replace [].tail with the stable [1..] syntaxErick Tryzelaar-1/+1
2015-04-21syntax: Remove uses of #[feature(slice_patterns)]Erick Tryzelaar-20/+19