Merge branch 'master' of https://github.com/rust-lang-nursery/rustfmt
This commit is contained in:
commit
3320b400ae
10
CHANGELOG.md
10
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
|
||||
|
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -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"
|
||||
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
|
||||
name = "rustfmt-nightly"
|
||||
version = "0.3.3"
|
||||
version = "0.3.4"
|
||||
authors = ["Nicholas Cameron <ncameron@mozilla.com>", "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"
|
||||
|
@ -252,24 +252,13 @@ fn get_targets_root_only(targets: &mut HashSet<Target>) -> 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<Target>,
|
||||
|
@ -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};
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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.
|
||||
///
|
||||
|
@ -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,
|
||||
|
@ -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)?;
|
||||
}
|
||||
}
|
||||
|
@ -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};
|
||||
|
59
src/items.rs
59
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,10 +28,11 @@ 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,
|
||||
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<String> {
|
||||
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<String> {
|
||||
match *self {
|
||||
ast::GenericParam::Lifetime(ref lifetime_def) => lifetime_def.rewrite(context, shape),
|
||||
ast::GenericParam::Type(ref ty) => ty.rewrite(context, shape),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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};
|
||||
|
@ -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};
|
||||
|
||||
|
@ -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())
|
||||
|
@ -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};
|
||||
|
||||
|
13
src/utils.rs
13
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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user