about summary refs log tree commit diff
path: root/src/libsyntax/ext/format.rs
AgeCommit message (Collapse)AuthorLines
2014-05-08libsyntax: Remove uses of `~str` from libsyntax, and fix falloutPatrick Walton-16/+16
2014-05-06librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, exceptPatrick Walton-1/+1
for `~str`/`~[]`. Note that `~self` still remains, since I forgot to add support for `Box<self>` before the snapshot. How to update your code: * Instead of `~EXPR`, you should write `box EXPR`. * Instead of `~TYPE`, you should write `Box<Type>`. * Instead of `~PATTERN`, you should write `box PATTERN`. [breaking-change]
2014-05-04Remove two useless comparisonsVirgile Andreani-1/+1
according to the updated type_limits lint.
2014-05-02syntax: store char literals/tokens as `char`s rather than u32s.Huon Wilson-1/+1
Clearly storing them as `char` is semantically nicer, but this also fixes a bug whereby `quote_expr!(cx, 'a')` wasn't working, because the code created by quotation was not matching the actual AST definitions.
2014-04-18Update the rest of the compiler with ~[T] changesAlex Crichton-3/+2
2014-04-16syntax: unify all MacResult's into a single trait.Huon Wilson-5/+5
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).
2014-04-10std,syntax: make std::fmt::parse use `Vec`s.Huon Wilson-4/+4
2014-03-20Removing imports of std::vec_ng::VecAlex Crichton-1/+0
It's now in the prelude.
2014-03-20rename std::vec_ng -> std::vecDaniel Micay-1/+1
Closes #12771
2014-03-20rename std::vec -> std::sliceDaniel Micay-2/+2
Closes #12702
2014-03-17De-@ ParseSess uses.Eduard Burtescu-3/+3
2014-03-12Changed lists of lifetimes in ast and ty to use Vec instead of OptVec.Felix S. Klock II-4/+3
There is a broader revision (that does this across the board) pending in #12675, but that is awaiting the arrival of more data (to decide whether to keep OptVec alive by using a non-Vec internally). For this code, the representation of lifetime lists needs to be the same in both ScopeChain and in the ast and ty structures. So it seemed cleanest to just use `vec_ng::Vec`, now that it has a cheaper empty representation than the current `vec` code.
2014-03-02Expand string literals and exprs inside of macrosSteven Fackler-4/+1
A couple of syntax extensions manually expanded expressions, but it wasn't done universally, most noticably inside of asm!(). There's also a bit of random cleanup.
2014-03-01libsyntax: Fix errors arising from the automated `~[T]` conversionPatrick Walton-14/+19
2014-03-01libsyntax: Mechanically change `~[T]` to `Vec<T>`Patrick Walton-87/+74
2014-02-28syntax: Expand format!() deterministicallyAlex Crichton-12/+24
Previously, format!("{a}{b}", a=foo(), b=bar()) has foo() and bar() run in a nondeterminisc order. This is clearly a non-desirable property, so this commit uses iteration over a list instead of iteration over a hash map to provide deterministic code generation of these format arguments.
2014-02-23Move std::{trie, hashmap} to libcollectionsAlex Crichton-1/+2
These two containers are indeed collections, so their place is in libcollections, not in libstd. There will always be a hash map as part of the standard distribution of Rust, but by moving it out of the standard library it makes libstd that much more portable to more platforms and environments. This conveniently also removes the stuttering of 'std::hashmap::HashMap', although 'collections::HashMap' is only one character shorter.
2014-02-22Represent lifetimes as Names instead of IdentsEdward Wang-2/+2
Closes #7743.
2014-02-19auto merge of #12349 : edwardw/rust/debug-expansion, r=huonwbors-6/+40
Currently, the format_args! macro and its downstream macros in turn expand to series of let statements, one for each of its arguments, and then the invocation of the macro function. If one or more of the arguments are RefCell's, the enclosing statement for the temporary of the let is the let itself, which leads to scope problem. This patch changes let's to a match expression. Closes #12239.
2014-02-19Change the format_args! macro expansion for temporariesEdward Wang-6/+40
Currently, the format_args! macro and its downstream macros in turn expand to series of let statements, one for each of its arguments, and then the invocation of the macro function. If one or more of the arguments are RefCell's, the enclosing statement for the temporary of the let is the let itself, which leads to scope problem. This patch changes let's to a match expression. Closes #12239.
2014-02-18Avoid returning original macro if expansion fails.Douglas Young-2/+2
Closes #11692. Instead of returning the original expression, a dummy expression (with identical span) is returned. This prevents infinite loops of failed expansions as well as odd double error messages in certain situations.
2014-02-14Refactored ast_map and friends, mainly to have Paths without storing them.Eduard Burtescu-1/+1
2014-02-11libsyntax -- fix unsafe sharing in closuresNiko Matsakis-1/+0
2014-02-11syntax/ext/format -- rewrite conflicting closures into methodsNiko Matsakis-116/+127
2014-02-08syntax: split out the parsing and the formatting part of format_args!().Huon Wilson-74/+92
2014-02-06Remove std::conditionAlex Crichton-11/+14
This has been a long time coming. Conditions in rust were initially envisioned as being a good alternative to error code return pattern. The idea is that all errors are fatal-by-default, and you can opt-in to handling the error by registering an error handler. While sounding nice, conditions ended up having some unforseen shortcomings: * Actually handling an error has some very awkward syntax: let mut result = None; let mut answer = None; io::io_error::cond.trap(|e| { result = Some(e) }).inside(|| { answer = Some(some_io_operation()); }); match result { Some(err) => { /* hit an I/O error */ } None => { let answer = answer.unwrap(); /* deal with the result of I/O */ } } This pattern can certainly use functions like io::result, but at its core actually handling conditions is fairly difficult * The "zero value" of a function is often confusing. One of the main ideas behind using conditions was to change the signature of I/O functions. Instead of read_be_u32() returning a result, it returned a u32. Errors were notified via a condition, and if you caught the condition you understood that the "zero value" returned is actually a garbage value. These zero values are often difficult to understand, however. One case of this is the read_bytes() function. The function takes an integer length of the amount of bytes to read, and returns an array of that size. The array may actually be shorter, however, if an error occurred. Another case is fs::stat(). The theoretical "zero value" is a blank stat struct, but it's a little awkward to create and return a zero'd out stat struct on a call to stat(). In general, the return value of functions that can raise error are much more natural when using a Result as opposed to an always-usable zero-value. * Conditions impose a necessary runtime requirement on *all* I/O. In theory I/O is as simple as calling read() and write(), but using conditions imposed the restriction that a rust local task was required if you wanted to catch errors with I/O. While certainly an surmountable difficulty, this was always a bit of a thorn in the side of conditions. * Functions raising conditions are not always clear that they are raising conditions. This suffers a similar problem to exceptions where you don't actually know whether a function raises a condition or not. The documentation likely explains, but if someone retroactively adds a condition to a function there's nothing forcing upstream users to acknowledge a new point of task failure. * Libaries using I/O are not guaranteed to correctly raise on conditions when an error occurs. In developing various I/O libraries, it's much easier to just return `None` from a read rather than raising an error. The silent contract of "don't raise on EOF" was a little difficult to understand and threw a wrench into the answer of the question "when do I raise a condition?" Many of these difficulties can be overcome through documentation, examples, and general practice. In the end, all of these difficulties added together ended up being too overwhelming and improving various aspects didn't end up helping that much. A result-based I/O error handling strategy also has shortcomings, but the cognitive burden is much smaller. The tooling necessary to make this strategy as usable as conditions were is much smaller than the tooling necessary for conditions. Perhaps conditions may manifest themselves as a future entity, but for now we're going to remove them from the standard library. Closes #9795 Closes #8968
2014-02-02std::fmt: prepare to convert the formatting traits to methods, and workHuon Wilson-7/+5
around the lack of UFCS. The further work is pending a snapshot, to avoid putting #[cfg(stage0)] attributes on all the traits and duplicating them.
2014-02-02std: rename fmt::Default to `Show`.Huon Wilson-16/+16
This is a better name with which to have a #[deriving] mode. Decision in: https://github.com/mozilla/rust/wiki/Meeting-weekly-2014-01-28
2014-02-02librustc: Fix merge fallout.Patrick Walton-44/+58
2014-02-02libsyntax: De-`@str` literal strings in the ASTPatrick Walton-6/+11
2014-02-02libsyntax: Introduce an `InternedString` type to reduce `@str` in thePatrick Walton-5/+11
compiler and use it for attributes
2014-01-22Add LowerExp 'e' and UpperExp 'E' format traits/specifiersSiegeLord-0/+2
2014-01-19auto merge of #11644 : huonw/rust/less-fatality, r=cmrbors-2/+5
This means that compilation continues for longer, and so we can see more errors per compile. This is mildly more user-friendly because it stops users having to run rustc n times to see n macro errors: just run it once to see all of them.
2014-01-17auto merge of #11585 : nikomatsakis/rust/issue-3511-rvalue-lifetimes, r=pcwaltonbors-4/+11
Major changes: - Define temporary scopes in a syntax-based way that basically defaults to the innermost statement or conditional block, except for in a `let` initializer, where we default to the innermost block. Rules are documented in the code, but not in the manual (yet). See new test run-pass/cleanup-value-scopes.rs for examples. - Refactors Datum to better define cleanup roles. - Refactor cleanup scopes to not be tied to basic blocks, permitting us to have a very large number of scopes (one per AST node). - Introduce nascent documentation in trans/doc.rs covering datums and cleanup in a more comprehensive way. r? @pcwalton
2014-01-18syntax::ext: replace span_fatal with span_err in many places.Huon Wilson-2/+5
This means that compilation continues for longer, and so we can see more errors per compile. This is mildly more user-friendly because it stops users having to run rustc n times to see n macro errors: just run it once to see all of them.
2014-01-16Load macros from external modulesSteven Fackler-1/+1
2014-01-15Issue #3511 - Rationalize temporary lifetimes.Niko Matsakis-4/+11
Major changes: - Define temporary scopes in a syntax-based way that basically defaults to the innermost statement or conditional block, except for in a `let` initializer, where we default to the innermost block. Rules are documented in the code, but not in the manual (yet). See new test run-pass/cleanup-value-scopes.rs for examples. - Refactors Datum to better define cleanup roles. - Refactor cleanup scopes to not be tied to basic blocks, permitting us to have a very large number of scopes (one per AST node). - Introduce nascent documentation in trans/doc.rs covering datums and cleanup in a more comprehensive way.
2014-01-09libsyntax: Renamed types, traits and enum variants to CamelCase.Eduard Burtescu-8/+8
2014-01-03auto merge of #11149 : alexcrichton/rust/remove-either, r=brsonbors-24/+27
Had to change some stuff in typeck to bootstrap (getting methods in fmt off of Either), but other than that not so painful. Closes #9157
2014-01-03Remove std::eitherAlex Crichton-24/+27
2014-01-02libsyntax: De-`@mut` `Parser::span`Patrick Walton-2/+2
2014-01-02libsyntax: De-`@mut` `token` in the parserPatrick Walton-5/+5
2014-01-02libsyntax: Make the parser mutablePatrick Walton-5/+5
2013-12-29Start passing around &mut ExtCtxtSteven Fackler-7/+8
2013-12-28Stop using @ExtCtxtSteven Fackler-4/+4
2013-12-17Remove obsolete mutability from ast::TySeo Sanghyeon-1/+1
2013-12-08Add dead-code warning passKiet Tran-1/+6
2013-12-01Box Block, fn_decl, variant and Ty in the AST, as they were inflating ↵Eduard Burtescu-3/+4
critical enum sizes.
2013-11-28Register new snapshotsAlex Crichton-2/+2
2013-11-26libsyntax: Remove all non-`proc` `do` syntax.Patrick Walton-3/+3