From c9cef5db170bc0ac2eb0cc42dff2013a4ad3d0c5 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Sun, 29 Apr 2018 19:57:49 +0800 Subject: [PATCH 1/3] import_indent to Block --- src/config/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 23897f3cc32..a4c0e1630a8 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -62,7 +62,7 @@ create_config! { where_single_line: bool, false, false, "Force where clauses to be on a single line"; // Imports - imports_indent: IndentStyle, IndentStyle::Visual, false, "Indent of imports"; + imports_indent: IndentStyle, IndentStyle::Block, false, "Indent of imports"; imports_layout: ListTactic, ListTactic::Mixed, false, "Item layout inside a import block"; merge_imports: bool, false, false, "Merge imports"; From f7415bcea235cab84b775d59dab3b9a0cb68dd01 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Sun, 29 Apr 2018 20:22:48 +0800 Subject: [PATCH 2/3] update self format --- Configurations.md | 44 ++++++++++++++++++++++++++------------------ src/bin/main.rs | 6 ++++-- src/chains.rs | 6 ++++-- src/expr.rs | 20 +++++++++++++------- src/items.rs | 24 +++++++++++++++--------- src/macros.rs | 6 ++++-- src/matches.rs | 12 ++++++++---- src/overflow.rs | 4 +++- src/patterns.rs | 11 +++++++---- src/types.rs | 11 +++++++---- src/utils.rs | 6 ++++-- src/visitor.rs | 8 +++++--- 12 files changed, 100 insertions(+), 58 deletions(-) diff --git a/Configurations.md b/Configurations.md index cd0fdb23def..110925f8e02 100644 --- a/Configurations.md +++ b/Configurations.md @@ -1042,8 +1042,10 @@ Item layout inside a imports block ```rust use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz}; -use foo::{aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd, - eeeeeeeeeeeeeeeeee, ffffffffffffffffff}; +use foo::{ + aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd, + eeeeeeeeeeeeeeeeee, ffffffffffffffffff, +}; ``` #### `"Horizontal"`: @@ -1061,27 +1063,33 @@ use foo::{aaa, bbb, ccc, ddd, eee, fff}; ```rust use foo::{xxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz}; -use foo::{aaaaaaaaaaaaaaaaaa, - bbbbbbbbbbbbbbbbbb, - cccccccccccccccccc, - dddddddddddddddddd, - eeeeeeeeeeeeeeeeee, - ffffffffffffffffff}; +use foo::{ + aaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbb, + cccccccccccccccccc, + dddddddddddddddddd, + eeeeeeeeeeeeeeeeee, + ffffffffffffffffff, +}; ``` #### `"Vertical"`: ```rust -use foo::{xxx, - yyy, - zzz}; +use foo::{ + xxx, + yyy, + zzz, +}; -use foo::{aaa, - bbb, - ccc, - ddd, - eee, - fff}; +use foo::{ + aaa, + bbb, + ccc, + ddd, + eee, + fff, +}; ``` ## `merge_imports` @@ -2036,7 +2044,7 @@ fn foo() { ## `required_version` -Require a specific version of rustfmt. If you want to make sure that the +Require a specific version of rustfmt. If you want to make sure that the specific version of rustfmt is used in your CI, use this option. - **Default value**: `CARGO_PKG_VERSION` diff --git a/src/bin/main.rs b/src/bin/main.rs index 0ddf2f8c3df..46e18864d30 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -24,8 +24,10 @@ use failure::err_msg; use getopts::{Matches, Options}; -use rustfmt::{emit_post_matter, emit_pre_matter, load_config, CliOptions, Config, FmtResult, - WriteMode, WRITE_MODE_LIST}; +use rustfmt::{ + emit_post_matter, emit_pre_matter, load_config, CliOptions, Config, FmtResult, WriteMode, + WRITE_MODE_LIST, +}; use rustfmt::{format_and_emit_report, FileName, Input, Summary}; fn main() { diff --git a/src/chains.rs b/src/chains.rs index 94099002f73..2f05f4a2c46 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -70,8 +70,10 @@ use expr::rewrite_call; use macros::convert_try_mac; use rewrite::{Rewrite, RewriteContext}; use shape::Shape; -use utils::{first_line_width, last_line_extendable, last_line_width, mk_sp, - trimmed_last_line_width, wrap_str}; +use utils::{ + first_line_width, last_line_extendable, last_line_width, mk_sp, trimmed_last_line_width, + wrap_str, +}; use std::borrow::Cow; use std::cmp::min; diff --git a/src/expr.rs b/src/expr.rs index cd8bfa8a72b..a048b1896c8 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -19,11 +19,15 @@ use syntax::{ast, ptr}; use chains::rewrite_chain; use closures; use codemap::{LineRangeUtils, SpanUtils}; -use comment::{combine_strs_with_missing_comments, contains_comment, recover_comment_removed, - rewrite_comment, rewrite_missing_comment, CharClasses, FindUncommented}; +use comment::{ + combine_strs_with_missing_comments, contains_comment, recover_comment_removed, rewrite_comment, + rewrite_missing_comment, CharClasses, FindUncommented, +}; use config::{Config, ControlBraceStyle, IndentStyle}; -use lists::{definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, - struct_lit_shape, struct_lit_tactic, write_list, ListFormatting, ListItem, Separator}; +use lists::{ + definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape, + struct_lit_tactic, write_list, ListFormatting, ListItem, Separator, +}; use macros::{rewrite_macro, MacroArg, MacroPosition}; use matches::rewrite_match; use overflow; @@ -33,9 +37,11 @@ use shape::{Indent, Shape}; use spanned::Spanned; use string::{rewrite_string, StringFormat}; use types::{can_be_overflowed_type, rewrite_path, PathContext}; -use utils::{colon_spaces, contains_skip, count_newlines, first_line_width, inner_attributes, - last_line_extendable, last_line_width, mk_sp, outer_attributes, paren_overhead, - ptr_vec_to_ref_vec, semicolon_for_stmt, wrap_str}; +use utils::{ + colon_spaces, contains_skip, count_newlines, first_line_width, inner_attributes, + last_line_extendable, last_line_width, mk_sp, outer_attributes, paren_overhead, + ptr_vec_to_ref_vec, semicolon_for_stmt, wrap_str, +}; use vertical::rewrite_with_alignment; use visitor::FmtVisitor; diff --git a/src/items.rs b/src/items.rs index f68fb890961..d6985c5b554 100644 --- a/src/items.rs +++ b/src/items.rs @@ -21,11 +21,15 @@ use syntax::visit; use syntax::{ast, ptr, symbol}; use codemap::{LineRangeUtils, SpanUtils}; -use comment::{combine_strs_with_missing_comments, contains_comment, recover_comment_removed, - recover_missing_comment_in_span, rewrite_missing_comment, FindUncommented}; +use comment::{ + combine_strs_with_missing_comments, contains_comment, recover_comment_removed, + recover_missing_comment_in_span, rewrite_missing_comment, FindUncommented, +}; use config::{BraceStyle, Config, Density, IndentStyle}; -use expr::{format_expr, is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, - rewrite_assign_rhs_with, ExprType, RhsTactics}; +use expr::{ + format_expr, is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_with, + ExprType, RhsTactics, +}; use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator}; use macros::{rewrite_macro, MacroPosition}; use overflow; @@ -33,11 +37,13 @@ use rewrite::{Rewrite, RewriteContext}; use shape::{Indent, Shape}; use spanned::Spanned; use types::TraitTyParamBounds; -use utils::{colon_spaces, contains_skip, first_line_width, format_abi, format_auto, - format_constness, format_defaultness, format_mutability, format_unsafety, - format_visibility, is_attributes_extendable, last_line_contains_single_line_comment, - last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, starts_with_newline, - stmt_expr, trimmed_last_line_width}; +use utils::{ + colon_spaces, contains_skip, first_line_width, format_abi, format_auto, format_constness, + format_defaultness, format_mutability, format_unsafety, format_visibility, + is_attributes_extendable, last_line_contains_single_line_comment, last_line_used_width, + last_line_width, mk_sp, semicolon_for_expr, starts_with_newline, stmt_expr, + trimmed_last_line_width, +}; use vertical::rewrite_with_alignment; use visitor::FmtVisitor; diff --git a/src/macros.rs b/src/macros.rs index a76520c8fe6..1fc150e1256 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -33,8 +33,10 @@ use syntax::util::ThinVec; use syntax::{ast, ptr}; use codemap::SpanUtils; -use comment::{contains_comment, remove_trailing_white_spaces, CharClasses, FindUncommented, - FullCodeCharKind, LineClasses}; +use comment::{ + contains_comment, remove_trailing_white_spaces, CharClasses, FindUncommented, FullCodeCharKind, + LineClasses, +}; use expr::rewrite_array; use lists::{itemize_list, write_list, ListFormatting}; use overflow; diff --git a/src/matches.rs b/src/matches.rs index 65bf7f579d4..bc092b1a718 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -19,14 +19,18 @@ use syntax::{ast, ptr}; use codemap::SpanUtils; use comment::combine_strs_with_missing_comments; use config::{Config, ControlBraceStyle, IndentStyle}; -use expr::{format_expr, is_empty_block, is_simple_block, is_unsafe_block, prefer_next_line, - rewrite_multiple_patterns, ExprType, RhsTactics, ToExpr}; +use expr::{ + format_expr, is_empty_block, is_simple_block, is_unsafe_block, prefer_next_line, + rewrite_multiple_patterns, ExprType, RhsTactics, ToExpr, +}; use lists::{itemize_list, write_list, ListFormatting}; use rewrite::{Rewrite, RewriteContext}; use shape::Shape; use spanned::Spanned; -use utils::{contains_skip, extra_offset, first_line_width, inner_attributes, last_line_extendable, - mk_sp, ptr_vec_to_ref_vec, trimmed_last_line_width}; +use utils::{ + contains_skip, extra_offset, first_line_width, inner_attributes, last_line_extendable, mk_sp, + ptr_vec_to_ref_vec, trimmed_last_line_width, +}; /// A simple wrapper type against `ast::Arm`. Used inside `write_list()`. struct ArmWrapper<'a> { diff --git a/src/overflow.rs b/src/overflow.rs index cc68f3e1ec2..b42c6be90ca 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -23,7 +23,9 @@ use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListIte use rewrite::{Rewrite, RewriteContext}; use shape::Shape; use spanned::Spanned; -use utils::{count_newlines, extra_offset, first_line_width, last_line_width, mk_sp, paren_overhead}; +use utils::{ + count_newlines, extra_offset, first_line_width, last_line_width, mk_sp, paren_overhead, +}; use std::cmp::min; diff --git a/src/patterns.rs b/src/patterns.rs index 243b85e4267..b4865ad329e 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -15,10 +15,13 @@ use syntax::ptr; use codemap::SpanUtils; use comment::FindUncommented; -use expr::{can_be_overflowed_expr, rewrite_pair, rewrite_unary_prefix, wrap_struct_field, - PairParts}; -use lists::{itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape, - struct_lit_tactic, write_list}; +use expr::{ + can_be_overflowed_expr, rewrite_pair, rewrite_unary_prefix, wrap_struct_field, PairParts, +}; +use lists::{ + itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape, struct_lit_tactic, + write_list, +}; use macros::{rewrite_macro, MacroPosition}; use overflow; use rewrite::{Rewrite, RewriteContext}; diff --git a/src/types.rs b/src/types.rs index 4bde91f67f1..149769c5df7 100644 --- a/src/types.rs +++ b/src/types.rs @@ -18,16 +18,19 @@ use syntax::symbol::keywords; use codemap::SpanUtils; use config::{IndentStyle, TypeDensity}; -use expr::{rewrite_assign_rhs, rewrite_pair, rewrite_tuple, rewrite_unary_prefix, PairParts, - ToExpr}; +use expr::{ + rewrite_assign_rhs, rewrite_pair, rewrite_tuple, rewrite_unary_prefix, PairParts, ToExpr, +}; use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator}; use macros::{rewrite_macro, MacroPosition}; use overflow; use rewrite::{Rewrite, RewriteContext}; use shape::Shape; use spanned::Spanned; -use utils::{colon_spaces, extra_offset, first_line_width, format_abi, format_mutability, - last_line_width, mk_sp}; +use utils::{ + colon_spaces, extra_offset, first_line_width, format_abi, format_mutability, last_line_width, + mk_sp, +}; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum PathContext { diff --git a/src/utils.rs b/src/utils.rs index 115aee7dd2b..78efbf1159d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -11,8 +11,10 @@ use std::borrow::Cow; use rustc_target::spec::abi; -use syntax::ast::{self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, - NestedMetaItemKind, Path, Visibility, VisibilityKind}; +use syntax::ast::{ + self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind, Path, + Visibility, VisibilityKind, +}; use syntax::codemap::{BytePos, Span, NO_EXPANSION}; use syntax::ptr; diff --git a/src/visitor.rs b/src/visitor.rs index d15d2ad7aef..05f2e7e5cc1 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -17,9 +17,11 @@ use attr::*; use codemap::{LineRangeUtils, SpanUtils}; use comment::{CodeCharKind, CommentCodeSlices, FindUncommented}; use config::{BraceStyle, Config}; -use items::{format_impl, format_trait, format_trait_alias, is_mod_decl, is_use_item, - rewrite_associated_impl_type, rewrite_associated_type, rewrite_extern_crate, - rewrite_type_alias, FnSig, StaticParts, StructParts}; +use items::{ + format_impl, format_trait, format_trait_alias, is_mod_decl, is_use_item, + rewrite_associated_impl_type, rewrite_associated_type, rewrite_extern_crate, + rewrite_type_alias, FnSig, StaticParts, StructParts, +}; use macros::{rewrite_macro, rewrite_macro_def, MacroPosition}; use rewrite::{Rewrite, RewriteContext}; use shape::{Indent, Shape}; From ce5efaf16fc9f080a8b39e8d2c7582dbb846a02e Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Sun, 29 Apr 2018 21:03:49 +0800 Subject: [PATCH 3/3] update tests --- tests/target/import-fencepost-length.rs | 9 ++- tests/target/imports.rs | 77 +++++++++++++++---------- tests/target/issue-2111.rs | 48 +++++++-------- tests/target/multiple.rs | 8 ++- 4 files changed, 82 insertions(+), 60 deletions(-) diff --git a/tests/target/import-fencepost-length.rs b/tests/target/import-fencepost-length.rs index e4f885c09b1..fd09d50d72d 100644 --- a/tests/target/import-fencepost-length.rs +++ b/tests/target/import-fencepost-length.rs @@ -1,4 +1,7 @@ use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; -use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, dddddddd}; -use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, - ddddddddd}; +use aaaaaaaaaaaaaaa::{ + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, dddddddd, +}; +use aaaaaaaaaaaaaaa::{ + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, ddddddddd, +}; diff --git a/tests/target/imports.rs b/tests/target/imports.rs index 236fee95e82..189f67cd8e9 100644 --- a/tests/target/imports.rs +++ b/tests/target/imports.rs @@ -4,18 +4,22 @@ // Imports. // Long import. -use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, - ItemB}; -use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, - ItemB}; +use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ + ItemA, ItemB, +}; +use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ + ItemA, ItemB, +}; use syntax::ast::{ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic}; -use list::{// Another item - AnotherItem, // Another Comment - // Last Item - LastItem, - // Some item - SomeItem /* Comment */}; +use list::{ + // Another item + AnotherItem, // Another Comment + // Last Item + LastItem, + // Some item + SomeItem, /* Comment */ +}; use test::{/* A */ self /* B */, Other /* C */}; @@ -28,11 +32,14 @@ use std::io; use std::io; mod Foo { - pub use syntax::ast::{ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic}; + pub use syntax::ast::{ + ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, + }; mod Foo2 { - pub use syntax::ast::{self, ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, - ItemStatic}; + pub use syntax::ast::{ + self, ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, + }; } } @@ -72,24 +79,32 @@ use foo::issue_1356::*; use self::unix::{}; // nested imports -use foo::{a, - b, - bar::{baz, - foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}, - qux, - xxxxxxxxxxx, - yyyyyyyyyyyyy, - zzzzzzzzzzzzzzzz}, - boo, - c}; - -use fooo::{baar::foobar::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, - zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz}, - bar, - bar::*, - x, - y, - z}; +use foo::{ + a, + b, + bar::{ + baz, + foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}, + qux, + xxxxxxxxxxx, + yyyyyyyyyyyyy, + zzzzzzzzzzzzzzzz, + }, + boo, + c, +}; + +use fooo::{ + baar::foobar::{ + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, + zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, + }, + bar, + bar::*, + x, + y, + z, +}; // nested imports with a single sub-tree. use a::b::c::d; diff --git a/tests/target/issue-2111.rs b/tests/target/issue-2111.rs index 13303a736a3..b82e41621a8 100644 --- a/tests/target/issue-2111.rs +++ b/tests/target/issue-2111.rs @@ -1,26 +1,28 @@ // rustfmt-normalize_comments: false // An import with single line comments. -use super::{DelayChoice, - Destinations, - Holding, - LodaModel, - MethodDescription, - ModelBehaviour, - ModelEdges, - ModelProperties, - ModelRequestGraph, - ModelSelector, - RequestDescription, - StringMap, - Switch, - // ModelMetaData, - // Generated, - // SecondsString, - // DateString, - // ModelConfiguration, - // ModelRequests, - // RestResponse, - // RestResponseCode, - // UniformHolding - SCHEMA_VERSIONS}; +use super::{ + DelayChoice, + Destinations, + Holding, + LodaModel, + MethodDescription, + ModelBehaviour, + ModelEdges, + ModelProperties, + ModelRequestGraph, + ModelSelector, + RequestDescription, + StringMap, + Switch, + // ModelMetaData, + // Generated, + // SecondsString, + // DateString, + // ModelConfiguration, + // ModelRequests, + // RestResponse, + // RestResponseCode, + // UniformHolding + SCHEMA_VERSIONS, +}; diff --git a/tests/target/multiple.rs b/tests/target/multiple.rs index 0c330d80a56..446b4357de3 100644 --- a/tests/target/multiple.rs +++ b/tests/target/multiple.rs @@ -16,9 +16,11 @@ extern crate foo; extern crate foo; use std::cell::*; -use std::{self, any, ascii, borrow, borrow, borrow, borrow, borrow, borrow, borrow, borrow, - borrow, borrow, borrow, boxed, boxed, boxed, boxed, boxed, boxed, boxed, boxed, boxed, - boxed, char, char, char, char, char, char, char, char, char, char}; +use std::{ + self, any, ascii, borrow, borrow, borrow, borrow, borrow, borrow, borrow, borrow, borrow, + borrow, borrow, boxed, boxed, boxed, boxed, boxed, boxed, boxed, boxed, boxed, boxed, char, + char, char, char, char, char, char, char, char, char, +}; mod doc; mod other;