Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Merge imports from the same module #2475

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rustfmt-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ create_config! {
// Imports
imports_indent: IndentStyle, IndentStyle::Visual, false, "Indent of imports";
imports_layout: ListTactic, ListTactic::Mixed, false, "Item layout inside a import block";
merge_imports: bool, false, false, "Merge imports from the same module";

// Ordering
reorder_extern_crates: bool, true, false, "Reorder extern crate statements alphabetically";
Expand Down
7 changes: 2 additions & 5 deletions rustfmt-core/src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,9 @@ use shape::Shape;
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;
use std::iter;
use std::{iter, borrow::Cow, cmp::min};

use syntax::{ast, ptr};
use syntax::codemap::Span;
use syntax::{ast, ptr, codemap::Span};

pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -> Option<String> {
debug!("rewrite_chain {:?}", shape);
Expand Down
3 changes: 1 addition & 2 deletions rustfmt-core/src/checkstyle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::io::{self, Write};
use std::path::Path;
use std::{io::{self, Write}, path::Path};

use config::WriteMode;
use rustfmt_diff::{DiffLine, Mismatch};
Expand Down
4 changes: 1 addition & 3 deletions rustfmt-core/src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
// except according to those terms.

use config::lists::*;
use syntax::{ast, ptr};
use syntax::codemap::Span;
use syntax::parse::classify;
use syntax::{ast, ptr, codemap::Span, parse::classify};

use codemap::SpanUtils;
use expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond, ToExpr};
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/src/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
//! This includes extension traits and methods for looking up spans and line ranges for AST nodes.

use config::file_lines::LineRange;
use visitor::SnippetProvider;
use syntax::codemap::{BytePos, CodeMap, Span};
use visitor::SnippetProvider;

use comment::FindUncommented;

Expand Down
11 changes: 8 additions & 3 deletions rustfmt-core/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,9 +1117,14 @@ fn remove_comment_header(comment: &str) -> &str {

#[cfg(test)]
mod test {
use super::{contains_comment, rewrite_comment, CharClasses, CodeCharKind, CommentCodeSlices,
FindUncommented, FullCodeCharKind};
use shape::{Indent, Shape};
use CharClasses;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not handle use super::{/* .. */}; properly.

use CodeCharKind;
use CommentCodeSlices;
use FindUncommented;
use FullCodeCharKind;
use contains_comment;
use rewrite_comment;
use shape::{Indent, Shape};

#[test]
fn char_classes() {
Expand Down
10 changes: 4 additions & 6 deletions rustfmt-core/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::borrow::Cow;
use std::cmp::min;
use std::iter::repeat;
use std::{borrow::Cow, cmp::min, iter::repeat};

use config::lists::*;
use syntax::{ast, ptr};
use syntax::codemap::{BytePos, CodeMap, Span};
use syntax::{ast, ptr, codemap::{BytePos, CodeMap, Span}};

use chains::rewrite_chain;
use closures;
Expand All @@ -23,7 +20,8 @@ use comment::{combine_strs_with_missing_comments, contains_comment, recover_comm
rewrite_comment, rewrite_missing_comment, 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};
struct_lit_shape, struct_lit_tactic, write_list, ListFormatting, ListItem,
Separator};
use macros::{rewrite_macro, MacroArg, MacroPosition};
use patterns::{can_be_overflowed_pat, TuplePatField};
use rewrite::{Rewrite, RewriteContext};
Expand Down
4 changes: 1 addition & 3 deletions rustfmt-core/src/filemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

// TODO: add tests

use std::fs::{self, File};
use std::io::{self, BufWriter, Read, Write};
use std::path::Path;
use std::{fs::{self, File}, io::{self, BufWriter, Read, Write}, path::Path};

use checkstyle::{output_checkstyle_file, output_footer, output_header};
use config::{Config, NewlineStyle, WriteMode};
Expand Down
3 changes: 1 addition & 2 deletions rustfmt-core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
use std::cmp::Ordering;

use config::lists::*;
use syntax::ast;
use syntax::codemap::{BytePos, Span};
use syntax::{ast, codemap::{BytePos, Span}};

use codemap::SpanUtils;
use config::IndentStyle;
Expand Down
9 changes: 3 additions & 6 deletions rustfmt-core/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@

// Formatting top-level items - functions, structs, enums, traits, impls.

use std::borrow::Cow;
use std::cmp::min;
use std::{borrow::Cow, cmp::min};

use config::lists::*;
use syntax::{abi, ast, ptr, symbol};
use syntax::ast::{CrateSugar, ImplItem};
use syntax::codemap::{BytePos, Span};
use syntax::visit;
use syntax::{abi, ptr, symbol, visit, ast::{self, CrateSugar, ImplItem},
codemap::{BytePos, Span}};

use codemap::{LineRangeUtils, SpanUtils};
use comment::{combine_strs_with_missing_comments, contains_comment, recover_comment_removed,
Expand Down
28 changes: 11 additions & 17 deletions rustfmt-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(custom_attribute)]
#![feature(decl_macro)]
#![feature(match_default_bindings)]
Expand All @@ -25,20 +27,11 @@ extern crate syntax;
extern crate term;
extern crate unicode_segmentation;

use std::collections::HashMap;
use std::fmt;
use std::io::{self, stdout, BufRead, Write};
use std::iter::repeat;
use std::path::PathBuf;
use std::rc::Rc;
use std::time::Duration;

use errors::{DiagnosticBuilder, Handler};
use errors::emitter::{ColorConfig, EmitterWriter};
use syntax::ast;
use syntax::codemap::{CodeMap, FilePathMapping};
pub use syntax::codemap::FileName;
use syntax::parse::{self, ParseSess};
use std::{fmt, collections::HashMap, io::{self, stdout, BufRead, Write}, iter::repeat,
path::PathBuf, rc::Rc, time::Duration};

use errors::{DiagnosticBuilder, Handler, emitter::{ColorConfig, EmitterWriter}};
use syntax::{ast, codemap::{CodeMap, FileName, FilePathMapping}, parse::{self, ParseSess}};

use checkstyle::{output_footer, output_header};
use comment::{CharClasses, FullCodeCharKind};
Expand All @@ -47,8 +40,7 @@ use shape::Indent;
use utils::use_colored_tty;
use visitor::{FmtVisitor, SnippetProvider};

pub use config::Config;
pub use config::summary::Summary;
use config::{Config, summary::Summary};

#[macro_use]
mod utils;
Expand Down Expand Up @@ -847,7 +839,9 @@ pub fn run(input: Input, config: &Config) -> Summary {

#[cfg(test)]
mod test {
use super::{format_code_block, format_snippet, Config};
use Config;
use format_code_block;
use format_snippet;

#[test]
fn test_no_panic_on_format_snippet_and_format_code_block() {
Expand Down
3 changes: 1 addition & 2 deletions rustfmt-core/src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

//! Format list-like expressions and items.

use std::cmp;
use std::iter::Peekable;
use std::{cmp, iter::Peekable};

use config::lists::*;
use syntax::codemap::BytePos;
Expand Down
14 changes: 5 additions & 9 deletions rustfmt-core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@
use std::collections::HashMap;

use config::lists::*;
use syntax::ast;
use syntax::codemap::{BytePos, Span};
use syntax::parse::new_parser_from_tts;
use syntax::parse::parser::Parser;
use syntax::parse::token::{BinOpToken, DelimToken, Token};
use syntax::print::pprust;
use syntax::symbol;
use syntax::tokenstream::{Cursor, ThinTokenStream, TokenStream, TokenTree};
use syntax::util::ThinVec;
use syntax::{ast, symbol, codemap::{BytePos, Span},
parse::{new_parser_from_tts, parser::Parser,
token::{BinOpToken, DelimToken, Token}},
print::pprust, tokenstream::{Cursor, ThinTokenStream, TokenStream, TokenTree},
util::ThinVec};

use codemap::SpanUtils;
use comment::{contains_comment, remove_trailing_white_spaces, FindUncommented};
Expand Down
3 changes: 1 addition & 2 deletions rustfmt-core/src/missed_spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::borrow::Cow;
use std::iter::repeat;
use std::{borrow::Cow, iter::repeat};

use syntax::codemap::{BytePos, FileName, Pos, Span};

Expand Down
8 changes: 2 additions & 6 deletions rustfmt-core/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::collections::BTreeMap;
use std::io;
use std::path::{Path, PathBuf};
use std::{io, collections::BTreeMap, path::{Path, PathBuf}};

use syntax::ast;
use syntax::codemap::{self, FileName};
use syntax::parse::parser;
use syntax::{ast, codemap::{self, FileName}, parse::parser};

use utils::contains_skip;

Expand Down
5 changes: 2 additions & 3 deletions rustfmt-core/src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
// except according to those terms.

use config::lists::*;
use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd, RangeSyntax};
use syntax::codemap::{self, BytePos, Span};
use syntax::ptr;
use syntax::{ptr, ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd, RangeSyntax},
codemap::{self, BytePos, Span}};

use codemap::SpanUtils;
use comment::FindUncommented;
Expand Down
Loading