mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Update to latest Syntex
+ Cargo update + 0.6.2 release
This commit is contained in:
parent
f9712b075e
commit
4418fab4f2
90
Cargo.lock
generated
90
Cargo.lock
generated
@ -1,29 +1,30 @@
|
||||
[root]
|
||||
name = "rustfmt"
|
||||
version = "0.6.0"
|
||||
version = "0.6.2"
|
||||
dependencies = [
|
||||
"diff 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.4.19 (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.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"multimap 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.1.73 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.1.77 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"strings 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syntex_errors 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syntex_syntax 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-segmentation 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.5.2"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -41,11 +42,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.3.4"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.1.73 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.1.77 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -55,7 +56,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.4.17"
|
||||
version = "0.4.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@ -69,7 +70,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.15"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@ -82,7 +83,7 @@ name = "memchr"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -92,19 +93,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "0.1.73"
|
||||
version = "0.1.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"aho-corasick 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_local 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.3.4"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
@ -121,25 +122,39 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syntex_syntax"
|
||||
version = "0.33.0"
|
||||
name = "syntex_errors"
|
||||
version = "0.43.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syntex_pos 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "term"
|
||||
version = "0.2.14"
|
||||
name = "syntex_pos"
|
||||
version = "0.43.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syntex_syntax"
|
||||
version = "0.43.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syntex_errors 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syntex_pos 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -157,7 +172,7 @@ version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -193,7 +208,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "0.1.5"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -211,23 +226,24 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum aho-corasick 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2b3fb52b09c1710b961acb35390d514be82e4ac96a9969a8e38565a29b878dc9"
|
||||
"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66"
|
||||
"checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23"
|
||||
"checksum diff 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e48977eec6d3b7707462c2dc2e1363ad91b5dd822cf942537ccdc2085dc87587"
|
||||
"checksum env_logger 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "82dcb9ceed3868a03b335657b85a159736c961900f7e7747d3b0b97b9ccb5ccb"
|
||||
"checksum env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f"
|
||||
"checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685"
|
||||
"checksum itertools 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7ddb83e0e9730d830afba4e6839077948b4efa22075f7cd80a3867ec286c610f"
|
||||
"checksum itertools 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "c4a9b56eb56058f43dc66e58f40a214b2ccbc9f3df51861b63d51dec7b65bc3f"
|
||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "23e3757828fa702a20072c37ff47938e9dd331b92fac6e223d26d4b7a55f7ee2"
|
||||
"checksum libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "408014cace30ee0f767b1c4517980646a573ec61a57957aeeabcac8ac0a02e8d"
|
||||
"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
|
||||
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
|
||||
"checksum multimap 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9223f4774d08e06185e44e555b9a7561243d387bac49c78a6205c42d6975fbf2"
|
||||
"checksum regex 0.1.73 (registry+https://github.com/rust-lang/crates.io-index)" = "56b7ee9f764ecf412c6e2fff779bca4b22980517ae335a21aeaf4e32625a5df2"
|
||||
"checksum regex-syntax 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "31040aad7470ad9d8c46302dcffba337bb4289ca5da2e3cd6e37b64109a85199"
|
||||
"checksum regex 0.1.77 (registry+https://github.com/rust-lang/crates.io-index)" = "64b03446c466d35b42f2a8b203c8e03ed8b91c0f17b56e1f84f7210a257aa665"
|
||||
"checksum regex-syntax 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279401017ae31cf4e15344aa3f085d0e2e5c1e70067289ef906906fdbe92c8fd"
|
||||
"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
|
||||
"checksum strings 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "54f86446ab480b4f60782188f4f78886465c5793aee248cbb48b7fdc0d022420"
|
||||
"checksum syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44bded3cabafc65c90b663b1071bd2d198a9ab7515e6ce729e4570aaf53c407e"
|
||||
"checksum term 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "f2077e54d38055cf1ca0fd7933a2e00cd3ec8f6fed352b2a377f06dcdaaf3281"
|
||||
"checksum syntex_errors 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cad40c64b27f251ee286cf18e157e40fe3586bd1ad89e2318d336829e4f6bb41"
|
||||
"checksum syntex_pos 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e56b7e73e8826c0bdd111da685becee1d42a42200139f72687242b6c0394247"
|
||||
"checksum syntex_syntax 0.43.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1590efa9a3862c1f812abb205e16e15c81a36a6c22cdaa28962c2eb80f1453e"
|
||||
"checksum term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3deff8a2b3b6607d6d7cc32ac25c0b33709453ca9cceac006caac51e963cf94a"
|
||||
"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03"
|
||||
"checksum thread_local 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "55dd963dbaeadc08aa7266bf7f91c3154a7805e32bb94b820b769d2ef3b4744d"
|
||||
@ -235,6 +251,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum unicode-segmentation 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b905d0fc2a1f0befd86b0e72e31d1787944efef9d38b9358a9e92a69757f7e3b"
|
||||
"checksum unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "36dff09cafb4ec7c8cf0023eb0b686cb6ce65499116a12201c9e11840ca01beb"
|
||||
"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f"
|
||||
"checksum walkdir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7ad450634b9022aeb0e8e7f1c79c1ded92d0fc5bee831033d148479771bd218d"
|
||||
"checksum walkdir 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d42144c31c9909882ce76e696b306b88a5b091721251137d5d522d1ef3da7cf9"
|
||||
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
|
||||
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
|
||||
name = "rustfmt"
|
||||
version = "0.6.0"
|
||||
version = "0.6.2"
|
||||
authors = ["Nicholas Cameron <ncameron@mozilla.com>", "Marcus Klaas <mail@marcusklaas.nl>", "The Rustfmt contributors"]
|
||||
description = "Tool to find and fix Rust formatting issues"
|
||||
repository = "https://github.com/rust-lang-nursery/rustfmt"
|
||||
@ -22,7 +22,8 @@ regex = "0.1"
|
||||
term = "0.4"
|
||||
strings = "0.0.1"
|
||||
diff = "0.1"
|
||||
syntex_syntax = "0.33"
|
||||
syntex_syntax = "0.43"
|
||||
syntex_errors = "0.43"
|
||||
log = "0.3"
|
||||
env_logger = "0.3"
|
||||
getopts = "0.2"
|
||||
|
98
src/expr.rs
98
src/expr.rs
@ -22,7 +22,7 @@ use lists::{write_list, itemize_list, ListFormatting, SeparatorTactic, ListTacti
|
||||
DefinitiveListTactic, definitive_tactic, ListItem, format_item_list};
|
||||
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};
|
||||
semicolon_for_stmt, trimmed_last_line_width, left_most_sub_expr, stmt_block, stmt_expr};
|
||||
use visitor::FmtVisitor;
|
||||
use config::{Config, StructLitStyle, MultilineStyle, ElseIfBraceStyle, ControlBraceStyle};
|
||||
use comment::{FindUncommented, rewrite_comment, contains_comment, recover_comment_removed};
|
||||
@ -150,7 +150,7 @@ fn format_expr(expr: &ast::Expr,
|
||||
ast::ExprKind::AssignOp(ref op, ref lhs, ref rhs) => {
|
||||
rewrite_assignment(context, lhs, rhs, Some(op), width, offset)
|
||||
}
|
||||
ast::ExprKind::Again(ref opt_ident) => {
|
||||
ast::ExprKind::Continue(ref opt_ident) => {
|
||||
let id_str = match *opt_ident {
|
||||
Some(ident) => format!(" {}", ident.node),
|
||||
None => String::new(),
|
||||
@ -400,7 +400,7 @@ fn rewrite_closure(capture: ast::CaptureBy,
|
||||
prefix.push_str(&ret_str);
|
||||
}
|
||||
|
||||
if body.expr.is_none() && body.stmts.is_empty() {
|
||||
if body.stmts.is_empty() {
|
||||
return Some(format!("{} {{}}", prefix));
|
||||
}
|
||||
|
||||
@ -412,10 +412,17 @@ fn rewrite_closure(capture: ast::CaptureBy,
|
||||
let mut had_braces = true;
|
||||
let mut inner_block = body;
|
||||
|
||||
let mut trailing_expr = stmt_expr(&inner_block.stmts[inner_block.stmts.len() - 1]);
|
||||
|
||||
// If there is an inner block and we can ignore it, do so.
|
||||
if body.stmts.is_empty() {
|
||||
if let ast::ExprKind::Block(ref inner) = inner_block.expr.as_ref().unwrap().node {
|
||||
if body.stmts.len() == 1 && trailing_expr.is_some() {
|
||||
if let Some(ref inner) = stmt_block(&inner_block.stmts[0]) {
|
||||
inner_block = inner;
|
||||
trailing_expr = if inner_block.stmts.is_empty() {
|
||||
None
|
||||
} else {
|
||||
stmt_expr(&inner_block.stmts[inner_block.stmts.len() - 1])
|
||||
};
|
||||
} else if !force_block {
|
||||
had_braces = false;
|
||||
}
|
||||
@ -426,14 +433,13 @@ fn rewrite_closure(capture: ast::CaptureBy,
|
||||
|
||||
if try_single_line && !force_block {
|
||||
let must_preserve_braces =
|
||||
!classify::expr_requires_semi_to_be_stmt(left_most_sub_expr(inner_block.expr
|
||||
.as_ref()
|
||||
.unwrap()));
|
||||
trailing_expr.is_none() ||
|
||||
!classify::expr_requires_semi_to_be_stmt(left_most_sub_expr(trailing_expr.unwrap()));
|
||||
if !(must_preserve_braces && had_braces) &&
|
||||
(must_preserve_braces || !prefix.contains('\n')) {
|
||||
// If we got here, then we can try to format without braces.
|
||||
|
||||
let inner_expr = inner_block.expr.as_ref().unwrap();
|
||||
let inner_expr = &inner_block.stmts[0];
|
||||
let mut rewrite = inner_expr.rewrite(context, budget, offset + extra_offset);
|
||||
|
||||
if must_preserve_braces {
|
||||
@ -456,7 +462,7 @@ fn rewrite_closure(capture: ast::CaptureBy,
|
||||
// still prefer a one-liner (we might also have fallen through because of
|
||||
// lack of space).
|
||||
if try_single_line && !prefix.contains('\n') {
|
||||
let inner_expr = inner_block.expr.as_ref().unwrap();
|
||||
let inner_expr = &inner_block.stmts[0];
|
||||
// 4 = braces and spaces.
|
||||
let mut rewrite = inner_expr.rewrite(context,
|
||||
try_opt!(budget.checked_sub(4)),
|
||||
@ -538,15 +544,11 @@ impl Rewrite for ast::Block {
|
||||
};
|
||||
|
||||
if is_simple_block(self, context.codemap) && prefix.len() < width {
|
||||
let body = self.expr
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.rewrite(context, width - prefix.len(), offset);
|
||||
if let Some(ref expr_str) = body {
|
||||
let result = format!("{}{{ {} }}", prefix, expr_str);
|
||||
if result.len() <= width && !result.contains('\n') {
|
||||
return Some(result);
|
||||
}
|
||||
let expr_str = self.stmts[0].rewrite(context, width - prefix.len(), offset);
|
||||
let expr_str = try_opt!(expr_str);
|
||||
let result = format!("{}{{ {} }}", prefix, expr_str);
|
||||
if result.len() <= width && !result.contains('\n') {
|
||||
return Some(result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -568,25 +570,26 @@ impl Rewrite for ast::Block {
|
||||
impl Rewrite for ast::Stmt {
|
||||
fn rewrite(&self, context: &RewriteContext, _width: usize, offset: Indent) -> Option<String> {
|
||||
let result = match self.node {
|
||||
ast::StmtKind::Decl(ref decl, _) => {
|
||||
if let ast::DeclKind::Local(ref local) = decl.node {
|
||||
local.rewrite(context, context.config.max_width, offset)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
ast::StmtKind::Local(ref local) => {
|
||||
local.rewrite(context, context.config.max_width, offset)
|
||||
}
|
||||
ast::StmtKind::Expr(ref ex, _) |
|
||||
ast::StmtKind::Semi(ref ex, _) => {
|
||||
ast::StmtKind::Expr(ref ex) |
|
||||
ast::StmtKind::Semi(ref ex) => {
|
||||
let suffix = if semicolon_for_stmt(self) { ";" } else { "" };
|
||||
|
||||
format_expr(ex,
|
||||
ExprType::Statement,
|
||||
match self.node {
|
||||
ast::StmtKind::Expr(_) => ExprType::SubExpression,
|
||||
ast::StmtKind::Semi(_) => ExprType::Statement,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
context,
|
||||
context.config.max_width - offset.width() - suffix.len(),
|
||||
offset)
|
||||
.map(|s| s + suffix)
|
||||
}
|
||||
ast::StmtKind::Mac(..) => None,
|
||||
ast::StmtKind::Mac(..) |
|
||||
ast::StmtKind::Item(..) => None,
|
||||
};
|
||||
result.and_then(|res| recover_comment_removed(res, self.span, context, _width, offset))
|
||||
}
|
||||
@ -876,11 +879,11 @@ fn single_line_if_else(context: &RewriteContext,
|
||||
}
|
||||
|
||||
let new_width = try_opt!(width.checked_sub(pat_expr_str.len() + fixed_cost));
|
||||
let if_expr = if_node.expr.as_ref().unwrap();
|
||||
let if_expr = &if_node.stmts[0];
|
||||
let if_str = try_opt!(if_expr.rewrite(context, new_width, Indent::empty()));
|
||||
|
||||
let new_width = try_opt!(new_width.checked_sub(if_str.len()));
|
||||
let else_expr = else_node.expr.as_ref().unwrap();
|
||||
let else_expr = &else_node.stmts[0];
|
||||
let else_str = try_opt!(else_expr.rewrite(context, new_width, Indent::empty()));
|
||||
|
||||
// FIXME: this check shouldn't be necessary. Rewrites should either fail
|
||||
@ -907,18 +910,25 @@ fn block_contains_comment(block: &ast::Block, codemap: &CodeMap) -> bool {
|
||||
// FIXME: incorrectly returns false when comment is contained completely within
|
||||
// the expression.
|
||||
pub fn is_simple_block(block: &ast::Block, codemap: &CodeMap) -> bool {
|
||||
block.stmts.is_empty() && block.expr.is_some() && !block_contains_comment(block, codemap)
|
||||
block.stmts.len() == 1 && stmt_is_expr(&block.stmts[0]) &&
|
||||
!block_contains_comment(block, codemap)
|
||||
}
|
||||
|
||||
/// Checks whether a block contains at most one statement or expression, and no comments.
|
||||
pub fn is_simple_block_stmt(block: &ast::Block, codemap: &CodeMap) -> bool {
|
||||
(block.stmts.is_empty() || (block.stmts.len() == 1 && block.expr.is_none())) &&
|
||||
!block_contains_comment(block, codemap)
|
||||
block.stmts.len() <= 1 && !block_contains_comment(block, codemap)
|
||||
}
|
||||
|
||||
/// Checks whether a block contains no statements, expressions, or comments.
|
||||
pub fn is_empty_block(block: &ast::Block, codemap: &CodeMap) -> bool {
|
||||
block.stmts.is_empty() && block.expr.is_none() && !block_contains_comment(block, codemap)
|
||||
block.stmts.is_empty() && !block_contains_comment(block, codemap)
|
||||
}
|
||||
|
||||
pub fn stmt_is_expr(stmt: &ast::Stmt) -> bool {
|
||||
match stmt.node {
|
||||
ast::StmtKind::Expr(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_unsafe_block(block: &ast::Block) -> bool {
|
||||
@ -1138,14 +1148,20 @@ impl Rewrite for ast::Arm {
|
||||
line_start += offset.width();
|
||||
}
|
||||
|
||||
let body = match **body {
|
||||
ast::Expr { node: ast::ExprKind::Block(ref block), .. }
|
||||
if !is_unsafe_block(block) && is_simple_block(block, context.codemap) &&
|
||||
context.config.wrap_match_arms => block.expr.as_ref().map(|e| &**e).unwrap(),
|
||||
ref x => x,
|
||||
let body = match body.node {
|
||||
ast::ExprKind::Block(ref block) if !is_unsafe_block(block) &&
|
||||
is_simple_block(block, context.codemap) &&
|
||||
context.config.wrap_match_arms => {
|
||||
if let ast::StmtKind::Expr(ref expr) = block.stmts[0].node {
|
||||
expr
|
||||
} else {
|
||||
&**body
|
||||
}
|
||||
}
|
||||
_ => &**body,
|
||||
};
|
||||
|
||||
let comma = arm_comma(context.config, self, body);
|
||||
let comma = arm_comma(&context.config, self, body);
|
||||
let alt_block_sep = String::from("\n") + &context.block_indent.to_string(context.config);
|
||||
|
||||
// Let's try and get the arm body on the same line as the condition.
|
||||
|
@ -9,6 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
//! This module contains types and functions to support formatting specific line ranges.
|
||||
|
||||
use std::{cmp, iter, path, str};
|
||||
|
||||
use itertools::Itertools;
|
||||
|
@ -43,34 +43,30 @@ fn compare_paths(a: &ast::Path, b: &ast::Path) -> Ordering {
|
||||
}
|
||||
|
||||
fn compare_path_list_items(a: &ast::PathListItem, b: &ast::PathListItem) -> Ordering {
|
||||
let name_ordering = match a.node.name() {
|
||||
Some(a_name) => {
|
||||
match b.node.name() {
|
||||
Some(b_name) => a_name.name.as_str().cmp(&b_name.name.as_str()),
|
||||
None => Ordering::Greater,
|
||||
}
|
||||
let a_name_str = a.node.name.name.as_str();
|
||||
let b_name_str = b.node.name.name.as_str();
|
||||
let name_ordering = if a_name_str == "self" {
|
||||
if b_name_str == "self" {
|
||||
Ordering::Equal
|
||||
} else {
|
||||
Ordering::Less
|
||||
}
|
||||
None => {
|
||||
match b.node.name() {
|
||||
Some(_) => Ordering::Less,
|
||||
None => Ordering::Equal,
|
||||
}
|
||||
} else {
|
||||
if b_name_str == "self" {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
a_name_str.cmp(&b_name_str)
|
||||
}
|
||||
};
|
||||
if name_ordering == Ordering::Equal {
|
||||
match a.node.rename() {
|
||||
match a.node.rename {
|
||||
Some(a_rename) => {
|
||||
match b.node.rename() {
|
||||
match b.node.rename {
|
||||
Some(b_rename) => a_rename.name.as_str().cmp(&b_rename.name.as_str()),
|
||||
None => Ordering::Greater,
|
||||
}
|
||||
}
|
||||
None => {
|
||||
match b.node.name() {
|
||||
Some(_) => Ordering::Less,
|
||||
None => Ordering::Equal,
|
||||
}
|
||||
}
|
||||
None => Ordering::Less,
|
||||
}
|
||||
} else {
|
||||
name_ordering
|
||||
@ -241,41 +237,23 @@ impl<'a> FmtVisitor<'a> {
|
||||
}
|
||||
|
||||
fn rewrite_single_use_list(path_str: Option<String>, vpi: &ast::PathListItem) -> String {
|
||||
let path_item_str = if let ast::PathListItemKind::Ident { name, .. } = vpi.node {
|
||||
// A name.
|
||||
match path_str {
|
||||
Some(path_str) => format!("{}::{}", path_str, name),
|
||||
None => name.to_string(),
|
||||
}
|
||||
} else {
|
||||
// `self`.
|
||||
match path_str {
|
||||
Some(path_str) => path_str,
|
||||
// This catches the import: use {self}, which is a compiler error, so we just
|
||||
// leave it alone.
|
||||
None => "{self}".to_owned(),
|
||||
}
|
||||
let path_item_str = match path_str {
|
||||
Some(ref path_str) if vpi.node.name.to_string() == "self" => path_str.to_owned(),
|
||||
Some(path_str) => format!("{}::{}", path_str, vpi.node.name),
|
||||
None => vpi.node.name.to_string(),
|
||||
};
|
||||
|
||||
append_alias(path_item_str, vpi)
|
||||
}
|
||||
|
||||
fn rewrite_path_item(vpi: &&ast::PathListItem) -> Option<String> {
|
||||
let path_item_str = match vpi.node {
|
||||
ast::PathListItemKind::Ident { name, .. } => name.to_string(),
|
||||
ast::PathListItemKind::Mod { .. } => "self".to_owned(),
|
||||
};
|
||||
|
||||
Some(append_alias(path_item_str, vpi))
|
||||
Some(append_alias(vpi.node.name.to_string(), vpi))
|
||||
}
|
||||
|
||||
fn append_alias(path_item_str: String, vpi: &ast::PathListItem) -> String {
|
||||
match vpi.node {
|
||||
ast::PathListItemKind::Ident { rename: Some(rename), .. } |
|
||||
ast::PathListItemKind::Mod { rename: Some(rename), .. } => {
|
||||
format!("{} as {}", path_item_str, rename)
|
||||
}
|
||||
_ => path_item_str,
|
||||
match vpi.node.rename {
|
||||
Some(rename) => format!("{} as {}", path_item_str, rename),
|
||||
None => path_item_str,
|
||||
}
|
||||
}
|
||||
|
||||
|
39
src/items.rs
39
src/items.rs
@ -13,7 +13,7 @@
|
||||
use Indent;
|
||||
use codemap::SpanUtils;
|
||||
use utils::{format_mutability, format_visibility, contains_skip, end_typaram, wrap_str,
|
||||
last_line_width, semicolon_for_expr, format_unsafety, trim_newlines};
|
||||
last_line_width, format_unsafety, trim_newlines, stmt_expr, semicolon_for_expr};
|
||||
use lists::{write_list, itemize_list, ListItem, ListFormatting, SeparatorTactic,
|
||||
DefinitiveListTactic, ListTactic, definitive_tactic, format_item_list};
|
||||
use expr::{is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, type_annotation_separator};
|
||||
@ -240,7 +240,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
&sig.decl,
|
||||
&sig.generics,
|
||||
sig.unsafety,
|
||||
sig.constness,
|
||||
sig.constness.node,
|
||||
ast::Defaultness::Final,
|
||||
sig.abi,
|
||||
&ast::Visibility::Inherited,
|
||||
@ -268,18 +268,23 @@ impl<'a> FmtVisitor<'a> {
|
||||
|
||||
if self.config.fn_single_line && is_simple_block_stmt(block, codemap) {
|
||||
let rewrite = {
|
||||
if let Some(ref e) = block.expr {
|
||||
let suffix = if semicolon_for_expr(e) { ";" } else { "" };
|
||||
if let Some(ref stmt) = block.stmts.first() {
|
||||
match stmt_expr(stmt) {
|
||||
Some(e) => {
|
||||
let suffix = if semicolon_for_expr(e) { ";" } else { "" };
|
||||
|
||||
e.rewrite(&self.get_context(),
|
||||
self.config.max_width - self.block_indent.width(),
|
||||
self.block_indent)
|
||||
.map(|s| s + suffix)
|
||||
.or_else(|| Some(self.snippet(e.span)))
|
||||
} else if let Some(stmt) = block.stmts.first() {
|
||||
stmt.rewrite(&self.get_context(),
|
||||
self.config.max_width - self.block_indent.width(),
|
||||
self.block_indent)
|
||||
e.rewrite(&self.get_context(),
|
||||
self.config.max_width - self.block_indent.width(),
|
||||
self.block_indent)
|
||||
.map(|s| s + suffix)
|
||||
.or_else(|| Some(self.snippet(e.span)))
|
||||
}
|
||||
None => {
|
||||
stmt.rewrite(&self.get_context(),
|
||||
self.config.max_width - self.block_indent.width(),
|
||||
self.block_indent)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -1153,13 +1158,6 @@ impl Rewrite for ast::FunctionRetTy {
|
||||
fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
|
||||
match *self {
|
||||
ast::FunctionRetTy::Default(_) => Some(String::new()),
|
||||
ast::FunctionRetTy::None(_) => {
|
||||
if width >= 4 {
|
||||
Some("-> !".to_owned())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
ast::FunctionRetTy::Ty(ref ty) => {
|
||||
let inner_width = try_opt!(width.checked_sub(3));
|
||||
ty.rewrite(context, inner_width, offset + 3).map(|r| format!("-> {}", r))
|
||||
@ -1259,7 +1257,6 @@ pub fn is_named_arg(arg: &ast::Arg) -> bool {
|
||||
|
||||
fn span_for_return(ret: &ast::FunctionRetTy) -> Span {
|
||||
match *ret {
|
||||
ast::FunctionRetTy::None(ref span) |
|
||||
ast::FunctionRetTy::Default(ref span) => span.clone(),
|
||||
ast::FunctionRetTy::Ty(ref ty) => ty.span,
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
extern crate log;
|
||||
|
||||
extern crate syntex_syntax as syntax;
|
||||
extern crate syntex_errors as errors;
|
||||
extern crate rustc_serialize;
|
||||
|
||||
extern crate strings;
|
||||
@ -27,10 +28,10 @@ extern crate term;
|
||||
extern crate itertools;
|
||||
extern crate multimap;
|
||||
|
||||
use errors::{Handler, DiagnosticBuilder};
|
||||
use errors::emitter::{ColorConfig, EmitterWriter};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::{mk_sp, CodeMap, Span};
|
||||
use syntax::errors::{Handler, DiagnosticBuilder};
|
||||
use syntax::errors::emitter::{ColorConfig, EmitterWriter};
|
||||
use syntax::parse::{self, ParseSess};
|
||||
|
||||
use strings::string_buffer::StringBuffer;
|
||||
@ -419,7 +420,7 @@ pub fn format_input<T: Write>(input: Input,
|
||||
let codemap = Rc::new(CodeMap::new());
|
||||
|
||||
let tty_handler =
|
||||
Handler::with_tty_emitter(ColorConfig::Auto, None, true, false, codemap.clone());
|
||||
Handler::with_tty_emitter(ColorConfig::Auto, true, false, Some(codemap.clone()));
|
||||
let mut parse_session = ParseSess::with_span_handler(tty_handler, codemap.clone());
|
||||
|
||||
let main_file = match input {
|
||||
@ -443,7 +444,7 @@ pub fn format_input<T: Write>(input: Input,
|
||||
}
|
||||
|
||||
// Suppress error output after parsing.
|
||||
let silent_emitter = Box::new(EmitterWriter::new(Box::new(Vec::new()), None, codemap.clone()));
|
||||
let silent_emitter = Box::new(EmitterWriter::new(Box::new(Vec::new()), Some(codemap.clone())));
|
||||
parse_session.span_diagnostic = Handler::with_emitter(true, false, silent_emitter);
|
||||
|
||||
let mut report = FormatReport::new();
|
||||
|
@ -23,6 +23,7 @@ use syntax::ast;
|
||||
use syntax::parse::token::Token;
|
||||
use syntax::parse::tts_to_parser;
|
||||
use syntax::codemap::{mk_sp, BytePos};
|
||||
use syntax::util::ThinVec;
|
||||
|
||||
use Indent;
|
||||
use codemap::SpanUtils;
|
||||
@ -159,7 +160,7 @@ pub fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext) -> Option<ast::
|
||||
id: 0, // dummy value
|
||||
node: ast::ExprKind::Try(try_opt!(parser.parse_expr().ok())),
|
||||
span: mac.span, // incorrect span, but shouldn't matter too much
|
||||
attrs: None,
|
||||
attrs: ThinVec::new(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
@ -54,9 +54,6 @@ impl Rewrite for Pat {
|
||||
None
|
||||
}
|
||||
}
|
||||
PatKind::QPath(ref q_self, ref path) => {
|
||||
rewrite_path(context, true, Some(q_self), path, width, offset)
|
||||
}
|
||||
PatKind::Range(ref lhs, ref rhs) => {
|
||||
rewrite_pair(&**lhs, &**rhs, "", "...", "", context, width, offset)
|
||||
}
|
||||
@ -67,7 +64,9 @@ impl Rewrite for Pat {
|
||||
PatKind::Tuple(ref items, dotdot_pos) => {
|
||||
rewrite_tuple_pat(items, dotdot_pos, None, self.span, context, width, offset)
|
||||
}
|
||||
PatKind::Path(ref path) => rewrite_path(context, true, None, path, width, offset),
|
||||
PatKind::Path(ref q_self, ref path) => {
|
||||
rewrite_path(context, true, q_self.as_ref(), path, width, offset)
|
||||
}
|
||||
PatKind::TupleStruct(ref path, ref pat_vec, dotdot_pos) => {
|
||||
let path_str = try_opt!(rewrite_path(context, true, None, path, width, offset));
|
||||
rewrite_tuple_pat(pat_vec,
|
||||
|
@ -302,7 +302,6 @@ fn format_function_type<'a, I>(inputs: I,
|
||||
let type_str = try_opt!(ty.rewrite(context, budget, offset + 4));
|
||||
format!(" -> {}", type_str)
|
||||
}
|
||||
FunctionRetTy::None(..) => " -> !".to_owned(),
|
||||
FunctionRetTy::Default(..) => String::new(),
|
||||
};
|
||||
|
||||
@ -594,9 +593,14 @@ impl Rewrite for ast::Ty {
|
||||
ast::TyKind::BareFn(ref bare_fn) => {
|
||||
rewrite_bare_fn(bare_fn, self.span, context, width, offset)
|
||||
}
|
||||
ast::TyKind::Never => Some(String::from("!")),
|
||||
ast::TyKind::Mac(..) |
|
||||
ast::TyKind::Typeof(..) => unreachable!(),
|
||||
ast::TyKind::ImplicitSelf => Some(String::from("")),
|
||||
ast::TyKind::ImplTrait(..) => {
|
||||
// FIXME(#1154) Implement impl Trait
|
||||
Some(String::from("impl TODO"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
45
src/utils.rs
45
src/utils.rs
@ -13,7 +13,8 @@ use std::cmp::Ordering;
|
||||
|
||||
use itertools::Itertools;
|
||||
|
||||
use syntax::ast::{self, Visibility, Attribute, MetaItem, MetaItemKind, Path};
|
||||
use syntax::ast::{self, Visibility, Attribute, MetaItem, MetaItemKind, NestedMetaItem,
|
||||
NestedMetaItemKind, Path};
|
||||
use syntax::codemap::BytePos;
|
||||
use syntax::abi;
|
||||
|
||||
@ -101,11 +102,21 @@ pub fn trimmed_last_line_width(s: &str) -> usize {
|
||||
fn is_skip(meta_item: &MetaItem) -> bool {
|
||||
match meta_item.node {
|
||||
MetaItemKind::Word(ref s) => *s == SKIP_ANNOTATION,
|
||||
MetaItemKind::List(ref s, ref l) => *s == "cfg_attr" && l.len() == 2 && is_skip(&l[1]),
|
||||
MetaItemKind::List(ref s, ref l) => {
|
||||
*s == "cfg_attr" && l.len() == 2 && is_skip_nested(&l[1])
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_skip_nested(meta_item: &NestedMetaItem) -> bool {
|
||||
match meta_item.node {
|
||||
NestedMetaItemKind::MetaItem(ref mi) => is_skip(mi),
|
||||
NestedMetaItemKind::Literal(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn contains_skip(attrs: &[Attribute]) -> bool {
|
||||
attrs.iter().any(|a| is_skip(&a.node.value))
|
||||
@ -129,7 +140,7 @@ pub fn end_typaram(typaram: &ast::TyParam) -> BytePos {
|
||||
pub fn semicolon_for_expr(expr: &ast::Expr) -> bool {
|
||||
match expr.node {
|
||||
ast::ExprKind::Ret(..) |
|
||||
ast::ExprKind::Again(..) |
|
||||
ast::ExprKind::Continue(..) |
|
||||
ast::ExprKind::Break(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -138,7 +149,7 @@ pub fn semicolon_for_expr(expr: &ast::Expr) -> bool {
|
||||
#[inline]
|
||||
pub fn semicolon_for_stmt(stmt: &ast::Stmt) -> bool {
|
||||
match stmt.node {
|
||||
ast::StmtKind::Semi(ref expr, _) => {
|
||||
ast::StmtKind::Semi(ref expr) => {
|
||||
match expr.node {
|
||||
ast::ExprKind::While(..) |
|
||||
ast::ExprKind::WhileLet(..) |
|
||||
@ -152,6 +163,27 @@ pub fn semicolon_for_stmt(stmt: &ast::Stmt) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn stmt_block(stmt: &ast::Stmt) -> Option<&ast::Block> {
|
||||
match stmt.node {
|
||||
ast::StmtKind::Expr(ref expr) => {
|
||||
match expr.node {
|
||||
ast::ExprKind::Block(ref inner) => Some(inner),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn stmt_expr(stmt: &ast::Stmt) -> Option<&ast::Expr> {
|
||||
match stmt.node {
|
||||
ast::StmtKind::Expr(ref expr) => Some(expr),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn trim_newlines(input: &str) -> &str {
|
||||
match input.find(|c| c != '\n' && c != '\r') {
|
||||
@ -330,9 +362,8 @@ pub fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr {
|
||||
ast::ExprKind::Field(ref e, _) |
|
||||
ast::ExprKind::TupField(ref e, _) |
|
||||
ast::ExprKind::Index(ref e, _) |
|
||||
ast::ExprKind::Range(Some(ref e), _, _) => left_most_sub_expr(e),
|
||||
// FIXME needs Try in Syntex
|
||||
// ast::ExprKind::Try(ref f) => left_most_sub_expr(e),
|
||||
ast::ExprKind::Range(Some(ref e), _, _) |
|
||||
ast::ExprKind::Try(ref e) => left_most_sub_expr(e),
|
||||
_ => e,
|
||||
}
|
||||
}
|
||||
|
@ -52,17 +52,10 @@ impl<'a> FmtVisitor<'a> {
|
||||
}
|
||||
|
||||
match stmt.node {
|
||||
ast::StmtKind::Decl(ref decl, _) => {
|
||||
if let ast::DeclKind::Item(ref item) = decl.node {
|
||||
self.visit_item(item);
|
||||
} else {
|
||||
let rewrite = stmt.rewrite(&self.get_context(),
|
||||
self.config.max_width - self.block_indent.width(),
|
||||
self.block_indent);
|
||||
|
||||
self.push_rewrite(stmt.span, rewrite);
|
||||
}
|
||||
ast::StmtKind::Item(ref item) => {
|
||||
self.visit_item(item);
|
||||
}
|
||||
ast::StmtKind::Local(..) |
|
||||
ast::StmtKind::Expr(..) |
|
||||
ast::StmtKind::Semi(..) => {
|
||||
let rewrite = stmt.rewrite(&self.get_context(),
|
||||
@ -71,7 +64,8 @@ impl<'a> FmtVisitor<'a> {
|
||||
|
||||
self.push_rewrite(stmt.span, rewrite);
|
||||
}
|
||||
ast::StmtKind::Mac(ref mac, _macro_style, _) => {
|
||||
ast::StmtKind::Mac(ref mac) => {
|
||||
let (ref mac, _macro_style, _) = **mac;
|
||||
self.format_missing_with_indent(source!(self, stmt.span).lo);
|
||||
self.visit_mac(mac, None);
|
||||
}
|
||||
@ -96,18 +90,11 @@ impl<'a> FmtVisitor<'a> {
|
||||
self.visit_stmt(stmt)
|
||||
}
|
||||
|
||||
if let Some(ref e) = b.expr {
|
||||
self.format_missing_with_indent(source!(self, e.span).lo);
|
||||
let rewrite = e.rewrite(&self.get_context(),
|
||||
self.config.max_width - self.block_indent.width(),
|
||||
self.block_indent)
|
||||
.unwrap_or_else(|| self.snippet(e.span));
|
||||
|
||||
self.buffer.push_str(&rewrite);
|
||||
self.last_pos = source!(self, e.span).hi;
|
||||
|
||||
if utils::semicolon_for_expr(e) {
|
||||
self.buffer.push_str(";");
|
||||
if !b.stmts.is_empty() {
|
||||
if let Some(expr) = utils::stmt_expr(&b.stmts[b.stmts.len() - 1]) {
|
||||
if utils::semicolon_for_expr(expr) {
|
||||
self.buffer.push_str(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,7 +137,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
fd,
|
||||
generics,
|
||||
unsafety,
|
||||
constness,
|
||||
constness.node,
|
||||
defaultness,
|
||||
abi,
|
||||
vis,
|
||||
@ -163,7 +150,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
fd,
|
||||
&sig.generics,
|
||||
sig.unsafety,
|
||||
sig.constness,
|
||||
sig.constness.node,
|
||||
defaultness,
|
||||
sig.abi,
|
||||
vis.unwrap_or(&ast::Visibility::Inherited),
|
||||
@ -347,6 +334,9 @@ impl<'a> FmtVisitor<'a> {
|
||||
item.span);
|
||||
self.push_rewrite(item.span, rewrite);
|
||||
}
|
||||
ast::ItemKind::Union(..) => {
|
||||
// FIXME(#1157): format union definitions.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -387,6 +377,9 @@ impl<'a> FmtVisitor<'a> {
|
||||
self.block_indent);
|
||||
self.push_rewrite(ti.span, rewrite);
|
||||
}
|
||||
ast::TraitItemKind::Macro(..) => {
|
||||
// FIXME(#1158) Macros in trait item position
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ fn floaters() {
|
||||
{
|
||||
match x {
|
||||
PushParam => {
|
||||
// params are 1-indexed
|
||||
stack.push(mparams[match cur.to_digit(10) {
|
||||
Some(d) => d as usize - 1,
|
||||
None => return Err("bad param number".to_owned()),
|
||||
|
@ -17,7 +17,6 @@ fn floaters() {
|
||||
{
|
||||
match x {
|
||||
PushParam => {
|
||||
// params are 1-indexed
|
||||
stack.push(mparams[match cur.to_digit(10) {
|
||||
Some(d) => d as usize - 1,
|
||||
None => return Err("bad param number".to_owned()),
|
||||
|
@ -17,7 +17,6 @@ fn floaters() {
|
||||
{
|
||||
match x {
|
||||
PushParam => {
|
||||
// params are 1-indexed
|
||||
stack.push(mparams[match cur.to_digit(10) {
|
||||
Some(d) => d as usize - 1,
|
||||
None => return Err("bad param number".to_owned()),
|
||||
|
@ -18,7 +18,6 @@ fn floaters() {
|
||||
{
|
||||
match x {
|
||||
PushParam => {
|
||||
// params are 1-indexed
|
||||
stack.push(mparams[match cur.to_digit(10) {
|
||||
Some(d) => d as usize - 1,
|
||||
None => return Err("bad param number".to_owned()),
|
||||
|
@ -18,7 +18,6 @@ fn floaters() {
|
||||
{
|
||||
match x {
|
||||
PushParam => {
|
||||
// params are 1-indexed
|
||||
stack.push(mparams[match cur.to_digit(10) {
|
||||
Some(d) => d as usize - 1,
|
||||
None => return Err("bad param number".to_owned()),
|
||||
|
@ -12,7 +12,6 @@ fn floaters() {
|
||||
{
|
||||
match x {
|
||||
PushParam => {
|
||||
// params are 1-indexed
|
||||
stack.push(mparams[match cur.to_digit(10) {
|
||||
Some(d) => d as usize - 1,
|
||||
None => return Err("bad param number".to_owned()),
|
||||
|
@ -13,7 +13,6 @@ fn floaters() {
|
||||
{
|
||||
match x {
|
||||
PushParam => {
|
||||
// params are 1-indexed
|
||||
stack.push(mparams[match cur.to_digit(10) {
|
||||
Some(d) => d as usize - 1,
|
||||
None => return Err("bad param number".to_owned()),
|
||||
|
@ -18,7 +18,6 @@ fn floaters() {
|
||||
{
|
||||
match x {
|
||||
PushParam => {
|
||||
// params are 1-indexed
|
||||
stack.push(mparams[match cur.to_digit(10) {
|
||||
Some(d) => d as usize - 1,
|
||||
None => return Err("bad param number".to_owned()),
|
||||
|
Loading…
Reference in New Issue
Block a user