From 02bb1c8c973689a9ee3ac89a2d41b9b1576bb2db Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sat, 23 Dec 2017 11:58:19 +0900 Subject: [PATCH 1/5] Rustup to rustc 1.24.0-nightly (5165ee9e2 2017-12-22) --- src/closures.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/closures.rs b/src/closures.rs index cfc75664f301..f63242f63554 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -135,6 +135,7 @@ fn rewrite_closure_with_block( id: ast::NodeId::new(0), rules: ast::BlockCheckMode::Default, span: body.span, + recovered: false, }; let block = ::expr::rewrite_block_with_visitor(context, "", &block, shape, false)?; Some(format!("{} {}", prefix, block)) From 0ef2b99b745cd85c10a1a5d8d4e048a9a00a1e08 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sat, 23 Dec 2017 12:24:58 +0900 Subject: [PATCH 2/5] Remove workspace membership check --- src/bin/cargo-fmt.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/bin/cargo-fmt.rs b/src/bin/cargo-fmt.rs index dda99b43d4b8..270ed1446d6b 100644 --- a/src/bin/cargo-fmt.rs +++ b/src/bin/cargo-fmt.rs @@ -252,24 +252,13 @@ fn get_targets_root_only(targets: &mut HashSet) -> Result<(), io::Error> for package in metadata.packages { for target in package.targets { - if is_target_workspace_members(&target.name, &metadata.workspace_members) { - targets.insert(Target::from_target(&target)); - } + targets.insert(Target::from_target(&target)); } } Ok(()) } -fn is_target_workspace_members(target: &str, workspace_members: &[String]) -> bool { - workspace_members.iter().any(|member| { - member - .split_whitespace() - .nth(0) - .map_or(false, |name| name == target) - }) -} - fn get_targets_recursive( manifest_path: Option<&Path>, mut targets: &mut HashSet, From 6714a447d063b079de8fb2884ded2c8c3e96bc1d Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sat, 23 Dec 2017 12:25:42 +0900 Subject: [PATCH 3/5] 0.3.4 --- CHANGELOG.md | 10 ++++++++++ Cargo.lock | 8 ++++---- Cargo.toml | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3113a0a594e9..86fbafbef8c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ ## [Unreleased] +## [0.3.4] 2017-12-23 + +### Added + +- Add `--version` flag to `cargo-fmt`, allow `carfo fmt --version`. + +### Fixed + +- Rustup to `rustc 1.24.0-nightly (5165ee9e2 2017-12-22)`. + ## [0.3.3] 2017-12-22 ### Added diff --git a/Cargo.lock b/Cargo.lock index 5fdaa40f52ce..87d2529fe24c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,7 +31,7 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -172,9 +172,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rustfmt-nightly" -version = "0.3.3" +version = "0.3.4" dependencies = [ - "cargo_metadata 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo_metadata 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "derive-new 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -327,7 +327,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4" "checksum backtrace 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8709cc7ec06f6f0ae6c2c7e12f6ed41540781f72b488d83734978295ceae182e" "checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661" -"checksum cargo_metadata 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1f56ec3e469bca7c276f2eea015aa05c5e381356febdbb0683c2580189604537" +"checksum cargo_metadata 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "20d6fb2b5574726329c85cdba0df0347fddfec3cf9c8b588f9931708280f5643" "checksum cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a9b13a57efd6b30ecd6598ebdb302cca617930b5470647570468a65d12ef9719" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" diff --git a/Cargo.toml b/Cargo.toml index 74e83414b3da..a0f974c66144 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustfmt-nightly" -version = "0.3.3" +version = "0.3.4" authors = ["Nicholas Cameron ", "The Rustfmt developers"] description = "Tool to find and fix Rust formatting issues" repository = "https://github.com/rust-lang-nursery/rustfmt" @@ -43,7 +43,7 @@ log = "0.3" env_logger = "0.4" getopts = "0.2" derive-new = "0.5" -cargo_metadata = "0.3" +cargo_metadata = "0.4" [target.'cfg(unix)'.dependencies] libc = "0.2.11" From 1ef6bccea37839b3d33cbadc15e5e243b6371ea5 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sun, 24 Dec 2017 00:28:58 +0900 Subject: [PATCH 4/5] Cargo fmt Run 'cargo fmt' with the following setting: ``` reorder_imports = true reorder_imports_in_group = true ``` --- src/chains.rs | 2 +- src/config.rs | 2 +- src/expr.rs | 4 ++-- src/filemap.rs | 8 ++++---- src/imports.rs | 2 +- src/items.rs | 2 +- src/modules.rs | 2 +- src/patterns.rs | 2 +- src/types.rs | 2 +- src/vertical.rs | 2 +- src/visitor.rs | 4 ++-- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/chains.rs b/src/chains.rs index f63ddd44c1da..383e7077d660 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -59,11 +59,11 @@ //! .qux //! ``` -use shape::Shape; use config::IndentStyle; 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}; diff --git a/src/config.rs b/src/config.rs index 67ca3f6c3ad2..bdf39ed6a2c0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,9 +17,9 @@ use std::fs::File; use std::io::{Error, ErrorKind, Read}; use std::path::{Path, PathBuf}; +use Summary; use file_lines::FileLines; use lists::{ListTactic, SeparatorPlace, SeparatorTactic}; -use Summary; /// Check if we're in a nightly build. /// diff --git a/src/expr.rs b/src/expr.rs index 45804b5b701a..3d9e7b502dab 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -8,14 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cmp::min; use std::borrow::Cow; +use std::cmp::min; use std::iter::{repeat, ExactSizeIterator}; use syntax::{ast, ptr}; use syntax::codemap::{BytePos, CodeMap, Span}; -use spanned::Spanned; use chains::rewrite_chain; use closures; use codemap::{LineRangeUtils, SpanUtils}; @@ -29,6 +28,7 @@ use macros::{rewrite_macro, MacroArg, MacroPosition}; use patterns::{can_be_overflowed_pat, TuplePatField}; use rewrite::{Rewrite, RewriteContext}; 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, extra_offset, first_line_width, inner_attributes, diff --git a/src/filemap.rs b/src/filemap.rs index 5678dd59c55b..81f950cfb9b5 100644 --- a/src/filemap.rs +++ b/src/filemap.rs @@ -120,7 +120,7 @@ where match config.write_mode() { WriteMode::Replace => { let filename = filename_to_path(); - if let Ok((ori, fmt)) = source_and_formatted_text(text, &filename, config) { + if let Ok((ori, fmt)) = source_and_formatted_text(text, filename, config) { if fmt != ori { // Do a little dance to make writing safer - write to a temp file // rename the original to a .bk, then rename the temp file to the @@ -141,7 +141,7 @@ where WriteMode::Overwrite => { // Write text directly over original file if there is a diff. let filename = filename_to_path(); - let (source, formatted) = source_and_formatted_text(text, &filename, config)?; + let (source, formatted) = source_and_formatted_text(text, filename, config)?; if source != formatted { let file = File::create(filename)?; write_system_newlines(file, text, config)?; @@ -156,7 +156,7 @@ where } WriteMode::Diff => { let filename = filename_to_path(); - if let Ok((ori, fmt)) = source_and_formatted_text(text, &filename, config) { + if let Ok((ori, fmt)) = source_and_formatted_text(text, filename, config) { let mismatch = make_diff(&ori, &fmt, 3); let has_diff = !mismatch.is_empty(); print_diff( @@ -169,7 +169,7 @@ where } WriteMode::Checkstyle => { let filename = filename_to_path(); - let diff = create_diff(&filename, text, config)?; + let diff = create_diff(filename, text, config)?; output_checkstyle_file(out, filename, diff)?; } } diff --git a/src/imports.rs b/src/imports.rs index 53ccd67b7928..dac748af9b1e 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -13,7 +13,6 @@ use std::cmp::Ordering; use syntax::ast; use syntax::codemap::{BytePos, Span}; -use spanned::Spanned; use codemap::SpanUtils; use comment::combine_strs_with_missing_comments; use config::IndentStyle; @@ -21,6 +20,7 @@ use lists::{definitive_tactic, itemize_list, write_list, DefinitiveListTactic, L ListItem, Separator, SeparatorPlace, SeparatorTactic}; use rewrite::{Rewrite, RewriteContext}; use shape::Shape; +use spanned::Spanned; use types::{rewrite_path, PathContext}; use utils::{format_visibility, mk_sp}; use visitor::{rewrite_extern_crate, FmtVisitor}; diff --git a/src/items.rs b/src/items.rs index 13b4c0e49405..35dd5c39d384 100644 --- a/src/items.rs +++ b/src/items.rs @@ -18,7 +18,6 @@ use syntax::ast::{CrateSugar, ImplItem}; use syntax::codemap::{BytePos, Span}; use syntax::visit; -use spanned::Spanned; 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}; @@ -29,6 +28,7 @@ use lists::{definitive_tactic, itemize_list, write_list, DefinitiveListTactic, L ListItem, ListTactic, Separator, SeparatorPlace, SeparatorTactic}; use rewrite::{Rewrite, RewriteContext}; use shape::{Indent, Shape}; +use spanned::Spanned; use types::join_bounds; use utils::{colon_spaces, contains_skip, end_typaram, first_line_width, format_abi, format_constness, format_defaultness, format_mutability, format_unsafety, diff --git a/src/modules.rs b/src/modules.rs index 81414ee175e6..0f439910324e 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -9,8 +9,8 @@ // except according to those terms. use std::collections::BTreeMap; -use std::path::{Path, PathBuf}; use std::io; +use std::path::{Path, PathBuf}; use syntax::ast; use syntax::codemap::{self, FileName}; diff --git a/src/patterns.rs b/src/patterns.rs index 700fbd0da218..f877239f5189 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -12,7 +12,6 @@ use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd, RangeSynt use syntax::codemap::{self, BytePos, Span}; use syntax::ptr; -use spanned::Spanned; use codemap::SpanUtils; use comment::FindUncommented; use expr::{can_be_overflowed_expr, rewrite_call_inner, rewrite_pair, rewrite_unary_prefix, @@ -22,6 +21,7 @@ use lists::{itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_sh use macros::{rewrite_macro, MacroPosition}; use rewrite::{Rewrite, RewriteContext}; use shape::Shape; +use spanned::Spanned; use types::{rewrite_path, PathContext}; use utils::{format_mutability, mk_sp}; diff --git a/src/types.rs b/src/types.rs index a1156a7b4bbe..77dffd3cd89d 100644 --- a/src/types.rs +++ b/src/types.rs @@ -16,7 +16,6 @@ use syntax::codemap::{self, BytePos, Span}; use syntax::print::pprust; use syntax::symbol::keywords; -use spanned::Spanned; use codemap::SpanUtils; use config::{IndentStyle, TypeDensity}; use expr::{rewrite_pair, rewrite_tuple, rewrite_unary_prefix, wrap_args_with_parens, PairParts}; @@ -26,6 +25,7 @@ use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListTac use macros::{rewrite_macro, MacroPosition}; 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}; diff --git a/src/vertical.rs b/src/vertical.rs index d3b35677407f..9644f76cca42 100644 --- a/src/vertical.rs +++ b/src/vertical.rs @@ -15,7 +15,6 @@ use std::cmp; use syntax::ast; use syntax::codemap::{BytePos, Span}; -use spanned::Spanned; use codemap::SpanUtils; use comment::{combine_strs_with_missing_comments, contains_comment}; use expr::rewrite_field; @@ -24,6 +23,7 @@ use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListTac SeparatorPlace}; use rewrite::{Rewrite, RewriteContext}; use shape::{Indent, Shape}; +use spanned::Spanned; use utils::{contains_skip, is_attributes_extendable, mk_sp}; pub trait AlignedItem { diff --git a/src/visitor.rs b/src/visitor.rs index ae9f7a091f92..095f5c6865b1 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -15,13 +15,12 @@ use syntax::attr::HasAttrs; use syntax::codemap::{self, BytePos, CodeMap, Pos, Span}; use syntax::parse::ParseSess; -use expr::rewrite_literal; -use spanned::Spanned; use codemap::{LineRangeUtils, SpanUtils}; use comment::{combine_strs_with_missing_comments, contains_comment, remove_trailing_white_spaces, CodeCharKind, CommentCodeSlices, FindUncommented}; use comment::rewrite_comment; use config::{BraceStyle, Config}; +use expr::rewrite_literal; use items::{format_impl, format_trait, format_trait_alias, rewrite_associated_impl_type, rewrite_associated_type, rewrite_type_alias, FnSig, StaticParts, StructParts}; use lists::{itemize_list, write_list, DefinitiveListTactic, ListFormatting, SeparatorPlace, @@ -30,6 +29,7 @@ use macros::{rewrite_macro, MacroPosition}; use regex::Regex; use rewrite::{Rewrite, RewriteContext}; use shape::{Indent, Shape}; +use spanned::Spanned; use utils::{self, contains_skip, count_newlines, inner_attributes, mk_sp, ptr_vec_to_ref_vec}; fn is_use_item(item: &ast::Item) -> bool { From 939a6c58202f775a63e46fbde4e0d6b3b04cf8aa Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sun, 24 Dec 2017 00:29:59 +0900 Subject: [PATCH 5/5] Get rid of GenericsArg wrapper type `GenericsArg` is basically identical to `ast::GenericParam`. Just use the latter. --- src/items.rs | 57 +++++++++++++------------------------------------- src/spanned.rs | 9 ++++++++ src/utils.rs | 13 ------------ 3 files changed, 23 insertions(+), 56 deletions(-) diff --git a/src/items.rs b/src/items.rs index 35dd5c39d384..d09d95699b7d 100644 --- a/src/items.rs +++ b/src/items.rs @@ -30,9 +30,9 @@ use rewrite::{Rewrite, RewriteContext}; use shape::{Indent, Shape}; use spanned::Spanned; use types::join_bounds; -use utils::{colon_spaces, contains_skip, end_typaram, first_line_width, format_abi, - format_constness, format_defaultness, format_mutability, format_unsafety, - format_visibility, is_attributes_extendable, last_line_contains_single_line_comment, +use utils::{colon_spaces, contains_skip, first_line_width, format_abi, 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, trim_newlines, trimmed_last_line_width}; use vertical::rewrite_with_alignment; @@ -1871,12 +1871,8 @@ fn rewrite_fn_base( .generics .params .iter() - .filter_map(|p| match p { - &ast::GenericParam::Type(ref t) => Some(t), - _ => None, - }) .last() - .map_or(lo_after_visibility, |tp| end_typaram(tp)); + .map_or(lo_after_visibility, |param| param.span().hi()); let args_end = if fd.inputs.is_empty() { context .codemap @@ -2346,47 +2342,13 @@ fn rewrite_generics_inner( // FIXME: convert bounds to where clauses where they get too big or if // there is a where clause at all. - // Wrapper type - enum GenericsArg<'a> { - Lifetime(&'a ast::LifetimeDef), - TyParam(&'a ast::TyParam), - } - impl<'a> Rewrite for GenericsArg<'a> { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { - match *self { - GenericsArg::Lifetime(lifetime) => lifetime.rewrite(context, shape), - GenericsArg::TyParam(ty) => ty.rewrite(context, shape), - } - } - } - impl<'a> Spanned for GenericsArg<'a> { - fn span(&self) -> Span { - match *self { - GenericsArg::Lifetime(lifetime) => lifetime.span(), - GenericsArg::TyParam(ty) => ty.span(), - } - } - } - if generics.params.is_empty() { return Some(String::new()); } - let generics_args = generics - .params - .iter() - .filter_map(|p| match p { - &ast::GenericParam::Lifetime(ref l) => Some(l), - _ => None, - }) - .map(|lt| GenericsArg::Lifetime(lt)) - .chain(generics.params.iter().filter_map(|ty| match ty { - &ast::GenericParam::Type(ref ty) => Some(GenericsArg::TyParam(ty)), - _ => None, - })); let items = itemize_list( context.codemap, - generics_args, + generics.params.iter(), ">", ",", |arg| arg.span().lo(), @@ -2868,3 +2830,12 @@ impl Rewrite for ast::ForeignItem { ) } } + +impl Rewrite for ast::GenericParam { + fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + match *self { + ast::GenericParam::Lifetime(ref lifetime_def) => lifetime_def.rewrite(context, shape), + ast::GenericParam::Type(ref ty) => ty.rewrite(context, shape), + } + } +} diff --git a/src/spanned.rs b/src/spanned.rs index 7181512273ef..eb36a1174289 100644 --- a/src/spanned.rs +++ b/src/spanned.rs @@ -105,6 +105,15 @@ impl Spanned for ast::Arg { } } +impl Spanned for ast::GenericParam { + fn span(&self) -> Span { + match *self { + ast::GenericParam::Lifetime(ref lifetime_def) => lifetime_def.span(), + ast::GenericParam::Type(ref ty) => ty.span(), + } + } +} + impl Spanned for ast::StructField { fn span(&self) -> Span { span_with_attrs_lo_hi!(self, self.span.lo(), self.ty.span.hi()) diff --git a/src/utils.rs b/src/utils.rs index 7d3fcf73d565..1bad8aecdf41 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -213,19 +213,6 @@ pub fn contains_skip(attrs: &[Attribute]) -> bool { .any(|a| a.meta().map_or(false, |a| is_skip(&a))) } -// Find the end of a TyParam -#[inline] -pub fn end_typaram(typaram: &ast::TyParam) -> BytePos { - typaram - .bounds - .last() - .map_or(typaram.span, |bound| match *bound { - ast::RegionTyParamBound(ref lt) => lt.span, - ast::TraitTyParamBound(ref prt, _) => prt.span, - }) - .hi() -} - #[inline] pub fn semicolon_for_expr(context: &RewriteContext, expr: &ast::Expr) -> bool { match expr.node {