about summary refs log tree commit diff
path: root/src/libsyntax/ext/format.rs
AgeCommit message (Collapse)AuthorLines
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
2013-11-08Generalize AST and ty::Generics to accept multiple lifetimes.Niko Matsakis-3/+4
2013-10-31Implement a concat!() format extensionAlex Crichton-2/+4
This extension can be used to concatenate string literals at compile time. C has this useful ability when placing string literals lexically next to one another, but this needs to be handled at the syntax extension level to recursively expand macros. The major use case for this is something like: macro_rules! mylog( ($fmt:expr $($arg:tt)*) => { error2!(concat!(file!(), ":", line!(), " - ", $fmt) $($arg)*); }) Where the mylog macro will automatically prepend the filename/line number to the beginning of every log message.
2013-10-15Build a few extra features into format! parsingAlex Crichton-4/+17
* Allow named parameters to specify width/precision * Intepret the format string '0$' as "width is the 0th argument" instead of thinking the lone '0' was the sign-aware-zero-padding flag. To get both you'd need to put '00$' which makes more sense if you want both to happen. Closes #9669
2013-10-09option: rewrite the API to use compositionDaniel Micay-1/+1
2013-10-08add new enum ast::StrStyle as field to ast::lit_strBenjamin Herr-2/+2
For the benefit of the pretty printer we want to keep track of how string literals in the ast were originally represented in the source code. This commit changes parser functions so they don't extract strings from the token stream without at least also returning what style of string literal it was. This is stored in the resulting ast node for string literals, obviously, for the package id in `extern mod = r"package id"` view items, for the inline asm in `asm!()` invocations. For `asm!()`'s other arguments or for `extern "Rust" fn()` items, I just the style of string, because it seemed disproportionally cumbersome to thread that information through the string processing that happens with those string literals, given the limited advantage raw string literals would provide in these positions. The other syntax extensions don't seem to store passed string literals in the ast, so they also discard the style of strings they parse.
2013-10-01Migrate users of 'loop' to 'continue'Alex Crichton-3/+3
Closes #9467
2013-10-01Change the format! statics to be all-capsAlex Crichton-12/+16
This lets them get past the non_uppercase_statics lint mode (if it's turned on) Closes #9631
2013-09-30syntax: Remove usage of fmt!Alex Crichton-29/+29
2013-09-27Remove the notion of an "unknown format"Alex Crichton-11/+8
As mentioned in #9456, the format! syntax extension would previously consider an empty format as a 'Unknown' format which could then also get coerced into a different style of format on another argument. This is unusual behavior because `{}` is a very common format and if you have `{0} {0:?}` you wouldn't expect them both to be coereced to the `Poly` formatter. This commit removes this coercion, but still retains the requirement that each argument has exactly one format specified for it (an empty format now counts as well). Perhaps at a later date we can add support for multiple formats of one argument, but this puts us in at least a backwards-compatible situation if we decide to do that.
2013-09-20Implement a web backend for rustdoc_ngAlex Crichton-1/+1
This large commit implements and `html` output option for rustdoc_ng. The executable has been altered to be invoked as "rustdoc_ng html <crate>" and it will dump everything into the local "doc" directory. JSON can still be generated by changing 'html' to 'json'. This also fixes a number of bugs in rustdoc_ng relating to comment stripping, along with some other various issues that I found along the way. The `make doc` command has been altered to generate the new documentation into the `doc/ng/$(CRATE)` directories.
2013-09-18Allow trailing commas in format!Alex Crichton-0/+1
This is more consistent with other parts of the language and it also makes it easier to use in situations where format string is massive.
2013-09-15Reduce the amount of complexity in format!Alex Crichton-0/+756
This renames the syntax-extension file to format from ifmt, and it also reduces the amount of complexity inside by defining all other macros in terms of format_args!