version = "0.8.4"
dependencies = [
"diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
- "env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
- "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_derive 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"strings 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "syntex_errors 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "syntex_syntax 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_errors 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_syntax 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
[[package]]
name = "bitflags"
-version = "0.8.2"
+version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
[[package]]
name = "env_logger"
-version = "0.4.2"
+version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "extprim"
+version = "1.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "getopts"
version = "0.2.14"
[[package]]
name = "log"
-version = "0.3.7"
+version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[[package]]
+name = "rand"
+version = "0.3.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "regex"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "rustc-serialize"
-version = "0.3.24"
+name = "rustc_version"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "semver"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "semver-parser"
+version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
-version = "1.0.7"
+version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
-version = "1.0.7"
+version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_derive_internals 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive_internals 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive_internals"
-version = "0.15.0"
+version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
"dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
[[package]]
name = "syntex_errors"
-version = "0.58.1"
+version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
- "syntex_pos 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_pos 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syntex_pos"
-version = "0.58.1"
+version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syntex_syntax"
-version = "0.58.1"
+version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
- "syntex_errors 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "syntex_pos 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "extprim 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_errors 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_pos 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "serde 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[[package]]
+name = "unicode-xid"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "unreachable"
version = "0.1.1"
[metadata]
"checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699"
-"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
+"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0a515461b6c8c08419850ced27bc29e86166dcdcde8fbe76f8b1f0589bb49472"
"checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90"
-"checksum env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e3856f1697098606fc6cb97a93de88ca3f3bc35bb878c725920e6e82ecf05e83"
+"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b"
+"checksum extprim 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d9f92dbf3843b6b56a224bce6aacd734feea193013d6ee1e18f03dcb36a93911"
"checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685"
"checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)" = "e7eb6b826bfc1fdea7935d46556250d1799b7fe2d9f7951071f4291710665e3e"
-"checksum log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5141eca02775a762cc6cd564d8d2c50f67c0ea3a372cbf1c51592b3e029e10ad"
+"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b"
"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
+"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b"
"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db"
-"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
-"checksum serde 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c0c3d79316a6051231925504f6ef893d45088e8823c77a8331a3dcf427ee9087"
-"checksum serde_derive 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0019cd5b9f0529a1a0e145a912e9a2d60c325c58f7f260fc36c71976e9d76aee"
-"checksum serde_derive_internals 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "021c338d22c7e30f957a6ab7e388cb6098499dda9fd4ba1661ee074ca7a180d1"
+"checksum rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9743a7670d88d5d52950408ecdb7c71d8986251ab604d4689dd2ca25c9bca69"
+"checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537"
+"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
+"checksum serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f530d36fb84ec48fb7146936881f026cdbf4892028835fd9398475f82c1bb4"
+"checksum serde_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "10552fad5500771f3902d0c5ba187c5881942b811b7ba0d8fbbfbf84d80806d3"
+"checksum serde_derive_internals 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37aee4e0da52d801acfbc0cc219eb1eda7142112339726e427926a6f6ee65d3a"
"checksum serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "48b04779552e92037212c3615370f6bd57a40ebba7f20e554ff9f55e41a69a7b"
"checksum strings 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "da75d8bf2c4d210d63dd09581a041b036001f9f6e03d9b151dbff810fb7ba26a"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
-"checksum syntex_errors 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "867cc5c2d7140ae7eaad2ae9e8bf39cb18a67ca651b7834f88d46ca98faadb9c"
-"checksum syntex_pos 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13ad4762fe52abc9f4008e85c4fb1b1fe3aa91ccb99ff4826a439c7c598e1047"
-"checksum syntex_syntax 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6e0e4dbae163dd98989464c23dd503161b338790640e11537686f2ef0f25c791"
+"checksum syntex_errors 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0f769b93e132914e999edb13018e192bd5f0296c2886fb6d5473ee6e055acb1c"
+"checksum syntex_pos 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)" = "56c108cb745a38857097c1662a9d513594486acaf1d508831201fd122f83ba44"
+"checksum syntex_syntax 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a2c815f257bdfb6f8b8876bb2937438a5365f2884f268c312f864cd002abace6"
"checksum term 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d168af3930b369cfe245132550579d47dfd873d69470755a19c2c6568dbbd989"
"checksum thread-id 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8df7875b676fddfadffd96deea3b1124e5ede707d4884248931077518cf1f773"
"checksum thread_local 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c85048c6260d17cf486ceae3282d9fb6b90be220bf5b28c400f5485ffc29f0c7"
"checksum toml 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4cc5dbfb20a481e64b99eb7ae280859ec76730c7191570ba5edaa962394edb0a"
"checksum unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8083c594e02b8ae1654ae26f0ade5158b119bd88ad0e8227a5d8fcd72407946"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
+"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91"
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
term = "0.4"
strings = "0.1"
diff = "0.1"
-syntex_syntax = "0.58"
-syntex_errors = "0.58"
+syntex_syntax = "0.59"
+syntex_errors = "0.59"
log = "0.3"
env_logger = "0.4"
getopts = "0.2"
use Shape;
use rewrite::{Rewrite, RewriteContext};
-use utils::{wrap_str, first_line_width, last_line_width};
+use utils::{wrap_str, first_line_width, last_line_width, mk_sp};
use expr::rewrite_call;
use config::IndentStyle;
use macros::convert_try_mac;
use std::cmp::min;
use std::iter;
use syntax::{ast, ptr};
-use syntax::codemap::{mk_sp, Span};
+use syntax::codemap::Span;
pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -> Option<String> {
debug!("rewrite_chain {:?}", shape);
use string::{StringFormat, rewrite_string};
use utils::{extra_offset, last_line_width, wrap_str, binary_search, first_line_width,
semicolon_for_stmt, trimmed_last_line_width, left_most_sub_expr, stmt_expr,
- colon_spaces, contains_skip};
+ colon_spaces, contains_skip, mk_sp};
use visitor::FmtVisitor;
use config::{Config, IndentStyle, MultilineStyle, ControlBraceStyle, Style};
use comment::{FindUncommented, rewrite_comment, contains_comment, recover_comment_removed};
use macros::{rewrite_macro, MacroPosition};
use syntax::{ast, ptr};
-use syntax::codemap::{CodeMap, Span, BytePos, mk_sp};
+use syntax::codemap::{CodeMap, Span, BytePos};
use syntax::parse::classify;
impl Rewrite for ast::Expr {
context.config.max_width(),
shape)
}
+ ast::ExprKind::Catch(ref block) => {
+ if let rewrite @ Some(_) = try_one_line_block(context, shape, "do catch ", block) {
+ return rewrite;
+ }
+ // 9 = `do catch `
+ let budget = shape.width.checked_sub(9).unwrap_or(0);
+ Some(format!("{}{}",
+ "do catch ",
+ try_opt!(block.rewrite(&context, Shape::legacy(budget, shape.indent)))))
+ }
};
match (attr_rw, expr_rw) {
(Some(attr_str), Some(expr_str)) => {
}
}
+fn try_one_line_block(context: &RewriteContext,
+ shape: Shape,
+ prefix: &str,
+ block: &ast::Block)
+ -> Option<String> {
+ if is_simple_block(block, context.codemap) {
+ let expr_shape = Shape::legacy(shape.width - prefix.len(), shape.indent);
+ let expr_str = try_opt!(block.stmts[0].rewrite(context, expr_shape));
+ let result = format!("{}{{ {} }}", prefix, expr_str);
+ if result.len() <= shape.width && !result.contains('\n') {
+ return Some(result);
+ }
+ }
+ None
+}
+
pub fn rewrite_pair<LHS, RHS>(lhs: &LHS,
rhs: &RHS,
prefix: &str,
// means we must re-format.
let block_shape = shape.block().with_max_width(context.config);
let block_str = try_opt!(block.rewrite(&context, block_shape));
- Some(format!("{} {}",
- prefix,
- try_opt!(block_str.rewrite(context, block_shape))))
+ Some(format!("{} {}", prefix, block_str))
}
}
} else {
"unsafe ".to_owned()
};
-
- if is_simple_block(self, context.codemap) && prefix.len() < shape.width {
- let expr_str =
- self.stmts[0].rewrite(context,
- Shape::legacy(shape.width - prefix.len(),
- shape.indent));
- let expr_str = try_opt!(expr_str);
- let result = format!("{}{{ {} }}", prefix, expr_str);
- if result.len() <= shape.width && !result.contains('\n') {
- return Some(result);
- }
+ if let result @ Some(_) = try_one_line_block(context, shape, &prefix, self) {
+ return result;
}
-
prefix
}
ast::BlockCheckMode::Default => {
visitor.last_pos = self.span.lo;
-
String::new()
}
};
use Shape;
use utils;
-use syntax::codemap::{self, BytePos, Span};
+use syntax::codemap::{BytePos, Span};
use codemap::SpanUtils;
use lists::{write_list, itemize_list, ListItem, ListFormatting, SeparatorTactic, definitive_tactic};
use types::{rewrite_path, PathContext};
// Order the imports by view-path & other import path properties
ordered_use_items.sort_by(|a, b| compare_use_items(a.0, b.0).unwrap());
// First, output the span before the first import
- let prev_span_str = self.snippet(codemap::mk_sp(self.last_pos, pos_before_first_use_item));
+ let prev_span_str = self.snippet(utils::mk_sp(self.last_pos, pos_before_first_use_item));
// Look for purely trailing space at the start of the prefix snippet before a linefeed, or
// a prefix that's entirely horizontal whitespace.
let prefix_span_start = match prev_span_str.find('\n') {
Shape::legacy(self.config.max_width() - offset.width() - 1, offset)) {
Some(ref s) if s.is_empty() => {
// Format up to last newline
- let prev_span = codemap::mk_sp(self.last_pos, source!(self, span).lo);
+ let prev_span = utils::mk_sp(self.last_pos, source!(self, span).lo);
let span_end = match self.snippet(prev_span).rfind('\n') {
Some(offset) => self.last_pos + BytePos(offset as u32),
None => source!(self, span).lo,
use codemap::SpanUtils;
use utils::{format_mutability, format_visibility, contains_skip, end_typaram, wrap_str,
last_line_width, format_unsafety, trim_newlines, stmt_expr, semicolon_for_expr,
- trimmed_last_line_width, colon_spaces};
+ trimmed_last_line_width, colon_spaces, mk_sp};
use lists::{write_list, itemize_list, ListItem, ListFormatting, SeparatorTactic, list_helper,
DefinitiveListTactic, ListTactic, definitive_tactic, format_item_list};
use expr::{is_empty_block, is_simple_block_stmt, rewrite_assign_rhs};
use rewrite::{Rewrite, RewriteContext};
use config::{Config, IndentStyle, Density, ReturnIndent, BraceStyle, Style, TypeDensity};
-use syntax::{ast, abi, codemap, ptr, symbol};
-use syntax::codemap::{Span, BytePos, mk_sp};
+use syntax::{ast, abi, ptr, symbol};
+use syntax::codemap::{Span, BytePos};
use syntax::ast::ImplItem;
fn type_annotation_separator(config: &Config) -> &str {
let mut newline_brace = newline_for_brace(self.config, &generics.where_clause);
let context = self.get_context();
- let block_snippet = self.snippet(codemap::mk_sp(block.span.lo, block.span.hi));
+ let block_snippet = self.snippet(mk_sp(block.span.lo, block.span.hi));
let has_body = !block_snippet[1..block_snippet.len() - 1].trim().is_empty() ||
!context.config.fn_empty_single_line();
offset: Indent,
where_span_end: Option<BytePos>)
-> Option<String> {
- if let ast::ItemKind::Impl(_, _, ref generics, ref trait_ref, _, ref items) = item.node {
+ if let ast::ItemKind::Impl(_, _, _, ref generics, ref trait_ref, _, ref items) = item.node {
let mut result = String::new();
// First try to format the ref and type without a split at the 'for'.
let mut ref_and_type = try_opt!(format_impl_ref_and_type(context, item, offset, false));
offset: Indent,
split_at_for: bool)
-> Option<String> {
- if let ast::ItemKind::Impl(unsafety, polarity, ref generics, ref trait_ref, ref self_ty, _) =
- item.node {
+ if let ast::ItemKind::Impl(unsafety,
+ polarity,
+ _,
+ ref generics,
+ ref trait_ref,
+ ref self_ty,
+ _) = item.node {
let mut result = String::new();
result.push_str(&format_visibility(&item.vis));
use errors::{Handler, DiagnosticBuilder};
use errors::emitter::{ColorConfig, EmitterWriter};
use syntax::ast;
-use syntax::codemap::{mk_sp, CodeMap, Span};
+use syntax::codemap::{CodeMap, Span, FilePathMapping};
use syntax::parse::{self, ParseSess};
use strings::string_buffer::StringBuffer;
impl Spanned for ast::Arg {
fn span(&self) -> Span {
if items::is_named_arg(self) {
- mk_sp(self.pat.span.lo, self.ty.span.hi)
+ utils::mk_sp(self.pat.span.lo, self.ty.span.hi)
} else {
self.ty.span
}
if config.disable_all_formatting() {
return Ok((summary, FileMap::new(), FormatReport::new()));
}
- let codemap = Rc::new(CodeMap::new());
+ let codemap = Rc::new(CodeMap::new(FilePathMapping::empty()));
let tty_handler =
Handler::with_tty_emitter(ColorConfig::Auto, true, false, Some(codemap.clone()));
use std::cmp;
use std::iter::Peekable;
-use syntax::codemap::{self, CodeMap, BytePos};
+use syntax::codemap::{CodeMap, BytePos};
use {Indent, Shape};
use comment::{FindUncommented, rewrite_comment, find_comment_end};
use config::{Config, IndentStyle};
use rewrite::RewriteContext;
+use utils::mk_sp;
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
/// Formatting tactic for lists. This will be cast down to a
let mut new_lines = false;
// Pre-comment
let pre_snippet = self.codemap
- .span_to_snippet(codemap::mk_sp(self.prev_span_end, (self.get_lo)(&item)))
+ .span_to_snippet(mk_sp(self.prev_span_end, (self.get_lo)(&item)))
.unwrap();
let trimmed_pre_snippet = pre_snippet.trim();
let has_pre_comment = trimmed_pre_snippet.contains("//") ||
None => self.next_span_start,
};
let post_snippet = self.codemap
- .span_to_snippet(codemap::mk_sp((self.get_hi)(&item), next_start))
+ .span_to_snippet(mk_sp((self.get_hi)(&item), next_start))
.unwrap();
let comment_end = match self.inner.peek() {
// and those with brackets will be formatted as array literals.
use syntax::ast;
-use syntax::codemap::{mk_sp, BytePos};
+use syntax::codemap::BytePos;
use syntax::parse::token::Token;
-use syntax::parse::tts_to_parser;
+use syntax::parse::new_parser_from_tts;
+use syntax::tokenstream::TokenStream;
use syntax::symbol;
use syntax::util::ThinVec;
use rewrite::{Rewrite, RewriteContext};
use expr::{rewrite_call, rewrite_array, rewrite_pair};
use comment::{FindUncommented, contains_comment};
+use utils::mk_sp;
const FORCED_BRACKET_MACROS: &'static [&'static str] = &["vec!"];
original_style
};
- if mac.node.tts.is_empty() && !contains_comment(&context.snippet(mac.span)) {
+ let ts: TokenStream = mac.node.tts.clone().into();
+ if ts.is_empty() && !contains_comment(&context.snippet(mac.span)) {
return match style {
MacroStyle::Parens if position == MacroPosition::Item => {
Some(format!("{}();", macro_name))
};
}
- let mut parser = tts_to_parser(context.parse_session, mac.node.tts.clone());
+ let mut parser = new_parser_from_tts(context.parse_session, ts.trees().collect());
let mut expr_vec = Vec::new();
let mut vec_with_semi = false;
/// failed).
pub fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext) -> Option<ast::Expr> {
if &format!("{}", mac.node.path)[..] == "try" {
- let mut parser = tts_to_parser(context.parse_session, mac.node.tts.clone());
+ let ts: TokenStream = mac.node.tts.clone().into();
+ let mut parser = new_parser_from_tts(context.parse_session, ts.trees().collect());
Some(ast::Expr {
id: ast::NodeId::new(0), // dummy value
use config::WriteMode;
use visitor::FmtVisitor;
-use syntax::codemap::{self, BytePos, Span, Pos};
+use syntax::codemap::{BytePos, Span, Pos};
use comment::{CodeCharKind, CommentCodeSlices, rewrite_comment};
use Shape;
+use utils::mk_sp;
impl<'a> FmtVisitor<'a> {
fn output_at_start(&self) -> bool {
self.codemap.lookup_char_pos(end));
self.last_pos = end;
- let span = codemap::mk_sp(start, end);
+ let span = mk_sp(start, end);
self.write_snippet(span, &process_last_snippet);
}
use codemap::SpanUtils;
use config::{IndentStyle, MultilineStyle};
use rewrite::{Rewrite, RewriteContext};
-use utils::{wrap_str, format_mutability};
+use utils::{wrap_str, format_mutability, mk_sp};
use lists::{DefinitiveListTactic, SeparatorTactic, format_item_list, itemize_list, ListItem,
struct_lit_shape, struct_lit_tactic, shape_for_tactic, struct_lit_formatting,
write_list};
} else {
pats[pos + 1].span().lo
};
- let dot_span = codemap::mk_sp(prev, next);
+ let dot_span = mk_sp(prev, next);
let snippet = context.snippet(dot_span);
let lo = dot_span.lo + BytePos(snippet.find_uncommented("..").unwrap() as u32);
let span = Span {
lo: lo,
// 2 == "..".len()
hi: lo + BytePos(2),
- expn_id: codemap::NO_EXPANSION,
+ ctxt: codemap::NO_EXPANSION,
};
let dotdot = TuplePatField::Dotdot(span);
pat_vec.insert(pos, dotdot);
use codemap::SpanUtils;
use lists::{format_item_list, itemize_list, format_fn_args};
use rewrite::{Rewrite, RewriteContext};
-use utils::{extra_offset, format_mutability, colon_spaces, wrap_str};
+use utils::{extra_offset, format_mutability, colon_spaces, wrap_str, mk_sp};
use expr::{rewrite_unary_prefix, rewrite_pair, rewrite_tuple_type};
use config::TypeDensity;
.collect::<Vec<_>>();
let next_span_lo = param_list.last().unwrap().get_span().hi + BytePos(1);
- let list_lo = context
- .codemap
- .span_after(codemap::mk_sp(*span_lo, span_hi), "<");
+ let list_lo = context.codemap.span_after(mk_sp(*span_lo, span_hi), "<");
let separator = if path_context == PathContext::Expr {
"::"
} else {
it.rewrite(context, shape)
.map(|it_str| format!("impl {}", it_str))
}
+ ast::TyKind::Err |
ast::TyKind::Typeof(..) => unreachable!(),
}
}
use syntax::ast::{self, Visibility, Attribute, MetaItem, MetaItemKind, NestedMetaItem,
NestedMetaItemKind, Path};
-use syntax::codemap::BytePos;
+use syntax::codemap::{BytePos, Span, NO_EXPANSION};
use syntax::abi;
use Shape;
.next()
.expect("Non-global path in pub(restricted)?");
}
+ let is_keyword = |s: &str| s == "self" || s == "super";
+ let path = segments_iter.collect::<Vec<_>>().join("::");
+ let in_str = if is_keyword(&path) { "" } else { "in " };
- Cow::from(format!("pub({}) ", segments_iter.collect::<Vec<_>>().join("::")))
+ Cow::from(format!("pub({}{}) ", in_str, path))
}
}
}
#[inline]
pub fn contains_skip(attrs: &[Attribute]) -> bool {
- attrs.iter().any(|a| is_skip(&a.value))
+ attrs
+ .iter()
+ .any(|a| a.meta().map_or(false, |a| is_skip(&a)))
}
// Find the end of a TyParam
// Required as generated code spans aren't guaranteed to follow on from the last span.
macro_rules! source {
($this:ident, $sp: expr) => {
- $this.codemap.source_callsite($sp)
+ $sp.source_callsite()
+ }
+}
+
+pub fn mk_sp(lo: BytePos, hi: BytePos) -> Span {
+ Span {
+ lo,
+ hi,
+ ctxt: NO_EXPANSION,
}
}
use std::cmp;
use syntax::{ast, ptr, visit};
-use syntax::codemap::{self, CodeMap, Span, BytePos};
+use syntax::codemap::{CodeMap, Span, BytePos};
use syntax::parse::ParseSess;
use strings::string_buffer::StringBuffer;
use {Indent, Shape};
-use utils;
+use utils::{self, mk_sp};
use codemap::{LineRangeUtils, SpanUtils};
use comment::FindUncommented;
use config::Config;
use macros::{rewrite_macro, MacroPosition};
use items::{rewrite_static, rewrite_associated_type, rewrite_associated_impl_type,
rewrite_type_alias, format_impl, format_trait};
+use lists::{itemize_list, write_list, DefinitiveListTactic, ListFormatting, SeparatorTactic};
fn is_use_item(item: &ast::Item) -> bool {
match item.node {
Span {
lo: cmp::min(bound.lo, span.lo),
hi: cmp::max(bound.hi, span.hi),
- expn_id: span.expn_id,
+ ctxt: span.ctxt,
}
})
}
let mut unindent_comment = self.is_if_else_block && !b.stmts.is_empty();
if unindent_comment {
let end_pos = source!(self, b.span).hi - brace_compensation;
- let snippet = self.get_context()
- .snippet(codemap::mk_sp(self.last_pos, end_pos));
+ let snippet = self.get_context().snippet(mk_sp(self.last_pos, end_pos));
unindent_comment = snippet.contains("//") || snippet.contains("/*");
}
// FIXME: we should compress any newlines here to just one
defaultness,
abi,
vis,
- codemap::mk_sp(s.lo, b.span.lo),
+ mk_sp(s.lo, b.span.lo),
&b)
}
visit::FnKind::Method(ident, sig, vis, b) => {
defaultness,
sig.abi,
vis.unwrap_or(&ast::Visibility::Inherited),
- codemap::mk_sp(s.lo, b.span.lo),
+ mk_sp(s.lo, b.span.lo),
&b)
}
visit::FnKind::Closure(_) => unreachable!(),
ast::ItemKind::Union(..) => {
// FIXME(#1157): format union definitions.
}
+ ast::ItemKind::GlobalAsm(..) => {
+ let snippet = Some(self.snippet(item.span));
+ self.push_rewrite(item.span, snippet);
+ }
+ ast::ItemKind::MacroDef(..) => {
+ // FIXME(#1539): macros 2.0
+ let snippet = Some(self.snippet(item.span));
+ self.push_rewrite(item.span, snippet);
+ }
}
}
self.buffer.push_str(" {");
// Hackery to account for the closing }.
let mod_lo = self.codemap.span_after(source!(self, s), "{");
- let body_snippet =
- self.snippet(codemap::mk_sp(mod_lo, source!(self, m.inner).hi - BytePos(1)));
+ let body_snippet = self.snippet(mk_sp(mod_lo, source!(self, m.inner).hi - BytePos(1)));
let body_snippet = body_snippet.trim();
if body_snippet.is_empty() {
self.buffer.push_str("}");
}
}
+impl Rewrite for ast::NestedMetaItem {
+ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
+ match self.node {
+ ast::NestedMetaItemKind::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
+ ast::NestedMetaItemKind::Literal(..) => Some(context.snippet(self.span)),
+ }
+ }
+}
+
+impl Rewrite for ast::MetaItem {
+ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
+ Some(match self.node {
+ ast::MetaItemKind::Word => String::from(&*self.name.as_str()),
+ ast::MetaItemKind::List(ref list) => {
+ let name = self.name.as_str();
+ // 3 = `#[` and `(`, 2 = `]` and `)`
+ let item_shape = try_opt!(shape
+ .shrink_left(name.len() + 3)
+ .and_then(|s| s.sub_width(2)));
+ let items = itemize_list(context.codemap,
+ list.iter(),
+ ")",
+ |nested_meta_item| nested_meta_item.span.lo,
+ |nested_meta_item| nested_meta_item.span.hi,
+ |nested_meta_item| {
+ nested_meta_item.rewrite(context, item_shape)
+ },
+ self.span.lo,
+ self.span.hi);
+ let item_vec = items.collect::<Vec<_>>();
+ let fmt = ListFormatting {
+ tactic: DefinitiveListTactic::Mixed,
+ separator: ",",
+ trailing_separator: SeparatorTactic::Never,
+ shape: item_shape,
+ ends_with_newline: false,
+ config: context.config,
+ };
+ format!("{}({})", name, try_opt!(write_list(&item_vec, &fmt)))
+ }
+ ast::MetaItemKind::NameValue(ref literal) => {
+ let name = self.name.as_str();
+ let value = context.snippet(literal.span);
+ if &*name == "doc" && value.starts_with("///") {
+ let doc_shape = Shape {
+ width: cmp::min(shape.width, context.config.comment_width())
+ .checked_sub(shape.indent.width())
+ .unwrap_or(0),
+ ..shape
+ };
+ format!("{}",
+ try_opt!(rewrite_comment(&value,
+ false,
+ doc_shape,
+ context.config)))
+ } else {
+ format!("{} = {}", name, value)
+ }
+ }
+ })
+ }
+}
+
+impl Rewrite for ast::Attribute {
+ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
+ try_opt!(self.meta())
+ .rewrite(context, shape)
+ .map(|rw| if rw.starts_with("///") {
+ rw
+ } else {
+ format!("#[{}]", rw)
+ })
+ }
+}
+
impl<'a> Rewrite for [ast::Attribute] {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
let mut result = String::new();
let indent = shape.indent.to_string(context.config);
for (i, a) in self.iter().enumerate() {
- let mut a_str = context.snippet(a.span);
+ let a_str = try_opt!(a.rewrite(context, shape));
// Write comments and blank lines between attributes.
if i > 0 {
- let comment = context.snippet(codemap::mk_sp(self[i - 1].span.hi, a.span.lo));
+ let comment = context.snippet(mk_sp(self[i - 1].span.hi, a.span.lo));
// This particular horror show is to preserve line breaks in between doc
// comments. An alternative would be to force such line breaks to start
// with the usual doc comment token.
result.push_str(&indent);
}
- if a_str.starts_with("//") {
- a_str = try_opt!(rewrite_comment(&a_str,
- false,
- Shape::legacy(context.config.comment_width() -
- shape.indent.width(),
- shape.indent),
- context.config));
- }
-
// Write the attribute itself.
result.push_str(&a_str);
/// Blah blah bing.
fn f4(self) -> Cat {
}
+
+ // We want spaces around `=`
+ #[cfg(feature="nightly")]
+ fn f5(self) -> Monkey {}
+}
+
+// #984
+struct Foo {
+ # [ derive ( Clone , PartialEq , Debug , Deserialize , Serialize ) ]
+ foo: usize,
}
--- /dev/null
+#![feature(catch_expr)]
+
+fn main() {
+ let x = do catch {
+ foo()?
+ };
+
+ let x = do catch /* Invisible comment */ { foo()? };
+
+ let x = do catch {
+ unsafe { foo()? }
+ };
+
+ let y = match (do catch {
+ foo()?
+ }) {
+ _ => (),
+ };
+
+ do catch {
+ foo()?;
+ };
+
+ do catch {
+ // Regular do catch block
+ };
+}
// TODO make Dict "structlike" AKA name the two values.
Dict(&'i [u8], BTreeMap<&'i [u8], Bencoding<'i>>),
}
+
+// #1261
+pub enum CoreResourceMsg {
+ SetCookieForUrl(
+ ServoUrl,
+ #[serde(deserialize_with = "::hyper_serde::deserialize",
+ serialize_with = "::hyper_serde::serialize")]
+ Cookie,
+ CookieSource
+ ),
+}
WriteData(Writer<D>),
}
-pub( ::global:: path :: to::some_mod ) enum WriteState<D> {
+pub(in ::global:: path :: to::some_mod ) enum WriteState<D> {
WriteId {
id: U64Writer,
size: U64Writer,
WriteData(Writer<D>),
}
-pub( local:: path :: to::some_mod ) enum WriteState<D> {
+pub( in local:: path :: to::some_mod ) enum WriteState<D> {
WriteId {
id: U64Writer,
size: U64Writer,
fn main() {
do_something();
}
+
+// #1462
+struct Foo {
+ foo: usize,
+ #[cfg(feature="include-bar")]
+ bar: usize,
+}
+
+fn new_foo() -> Foo {
+ Foo {
+ foo: 0,
+ #[cfg(feature="include-bar")]
+ bar: 0,
+ }
+}
// tooooooooooooooooooooooooooooooo loooooooooooong.
/// Blah blah bing.
fn f4(self) -> Cat {}
+
+ // We want spaces around `=`
+ #[cfg(feature = "nightly")]
+ fn f5(self) -> Monkey {}
+}
+
+// #984
+struct Foo {
+ #[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
+ foo: usize,
}
--- /dev/null
+#![feature(catch_expr)]
+
+fn main() {
+ let x = do catch { foo()? };
+
+ let x = do catch /* Invisible comment */ { foo()? };
+
+ let x = do catch { unsafe { foo()? } };
+
+ let y = match (do catch { foo()? }) {
+ _ => (),
+ };
+
+ do catch {
+ foo()?;
+ };
+
+ do catch {
+ // Regular do catch block
+ };
+}
// TODO make Dict "structlike" AKA name the two values.
Dict(&'i [u8], BTreeMap<&'i [u8], Bencoding<'i>>),
}
+
+// #1261
+pub enum CoreResourceMsg {
+ SetCookieForUrl(ServoUrl,
+ #[serde(deserialize_with = "::hyper_serde::deserialize",
+ serialize_with = "::hyper_serde::serialize")]
+ Cookie,
+ CookieSource),
+}
sfEvtGainedFocus => GainedFocus,
sfEvtTextEntered => {
TextEntered {
- unicode:
- unsafe {
- ::std::char::from_u32((*event.text.as_ref()).unicode)
- .expect("Invalid unicode encountered on TextEntered event")
- },
+ unicode: unsafe {
+ ::std::char::from_u32((*event.text.as_ref()).unicode)
+ .expect("Invalid unicode encountered on TextEntered event")
+ },
}
}
sfEvtKeyPressed => {
mod mod3a;
}
-#[path="mod2c.rs"]
+#[path = "mod2c.rs"]
mod mymod2;
mod submod2;
-#[path="mod2a.rs"]
+#[path = "mod2a.rs"]
mod c;
WriteData(Writer<D>),
}
-pub(global::path::to::some_mod) enum WriteState<D> {
+pub(in global::path::to::some_mod) enum WriteState<D> {
WriteId {
id: U64Writer,
size: U64Writer,
WriteData(Writer<D>),
}
-pub(local::path::to::some_mod) enum WriteState<D> {
+pub(in local::path::to::some_mod) enum WriteState<D> {
WriteId {
id: U64Writer,
size: U64Writer,
fn main() {
do_something();
}
+
+// #1462
+struct Foo {
+ foo: usize,
+ #[cfg(feature = "include-bar")]
+ bar: usize,
+}
+
+fn new_foo() -> Foo {
+ Foo {
+ foo: 0,
+ #[cfg(feature = "include-bar")]
+ bar: 0,
+ }
+}