Merge branch 'master' of github.com:rust-lang-nursery/rustfmt
This commit is contained in:
commit
248f2aba56
@ -19,14 +19,14 @@ cargo-fmt = []
|
||||
toml = "0.2.1"
|
||||
rustc-serialize = "0.3"
|
||||
unicode-segmentation = "1.0.0"
|
||||
regex = "0.1"
|
||||
regex = "0.2"
|
||||
term = "0.4"
|
||||
strings = "0.0.1"
|
||||
diff = "0.1"
|
||||
syntex_syntax = "0.56"
|
||||
syntex_errors = "0.56"
|
||||
syntex_syntax = "0.58"
|
||||
syntex_errors = "0.58"
|
||||
log = "0.3"
|
||||
env_logger = "0.3"
|
||||
env_logger = "0.4"
|
||||
getopts = "0.2"
|
||||
itertools = "0.5.8"
|
||||
multimap = "0.3"
|
||||
|
12
README.md
12
README.md
@ -124,13 +124,13 @@ A minimal Travis setup could look like this:
|
||||
```yaml
|
||||
language: rust
|
||||
cache: cargo
|
||||
before_script: (cargo install rustfmt || true)
|
||||
before_script:
|
||||
- export PATH="$PATH:$HOME/.cargo/bin"
|
||||
- which rustfmt || cargo install rustfmt
|
||||
script:
|
||||
- |
|
||||
export PATH=$PATH:~/.cargo/bin &&
|
||||
cargo fmt -- --write-mode=diff &&
|
||||
cargo build &&
|
||||
cargo test
|
||||
- cargo fmt -- --write-mode=diff
|
||||
- cargo build
|
||||
- cargo test
|
||||
```
|
||||
|
||||
Note that using `cache: cargo` is optional but highly recommended to speed up the installation.
|
||||
|
30
src/expr.rs
30
src/expr.rs
@ -1287,21 +1287,33 @@ impl Rewrite for ast::Arm {
|
||||
("{", "}")
|
||||
}
|
||||
} else {
|
||||
("", "")
|
||||
("", ",")
|
||||
};
|
||||
|
||||
|
||||
let block_sep = match context.config.control_brace_style {
|
||||
ControlBraceStyle::AlwaysNextLine => alt_block_sep + body_prefix + "\n",
|
||||
_ => String::from(" ") + body_prefix + "\n",
|
||||
};
|
||||
Some(format!("{}{} =>{}{}{}\n{}{}",
|
||||
attr_str.trim_left(),
|
||||
pats_str,
|
||||
block_sep,
|
||||
indent_str,
|
||||
next_line_body,
|
||||
shape.indent.to_string(context.config),
|
||||
body_suffix))
|
||||
|
||||
if context.config.wrap_match_arms {
|
||||
Some(format!("{}{} =>{}{}{}\n{}{}",
|
||||
attr_str.trim_left(),
|
||||
pats_str,
|
||||
block_sep,
|
||||
indent_str,
|
||||
next_line_body,
|
||||
shape.indent.to_string(context.config),
|
||||
body_suffix))
|
||||
} else {
|
||||
Some(format!("{}{} =>{}{}{}{}",
|
||||
attr_str.trim_left(),
|
||||
pats_str,
|
||||
block_sep,
|
||||
indent_str,
|
||||
next_line_body,
|
||||
body_suffix))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
26
src/items.rs
26
src/items.rs
@ -1236,11 +1236,11 @@ pub fn rewrite_associated_type(ident: ast::Ident,
|
||||
let type_bounds_str = if let Some(ty_param_bounds) = ty_param_bounds_opt {
|
||||
let bounds: &[_] = ty_param_bounds;
|
||||
let bound_str = try_opt!(bounds.iter()
|
||||
.map(|ty_bound| {
|
||||
ty_bound.rewrite(context, Shape::legacy(context.config.max_width, indent))
|
||||
})
|
||||
.intersperse(Some(" + ".to_string()))
|
||||
.collect::<Option<String>>());
|
||||
.map(|ty_bound| {
|
||||
ty_bound.rewrite(context, Shape::legacy(context.config.max_width, indent))
|
||||
})
|
||||
.intersperse(Some(" + ".to_string()))
|
||||
.collect::<Option<String>>());
|
||||
if bounds.len() > 0 {
|
||||
format!(": {}", bound_str)
|
||||
} else {
|
||||
@ -1263,6 +1263,22 @@ pub fn rewrite_associated_type(ident: ast::Ident,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rewrite_associated_impl_type(ident: ast::Ident,
|
||||
defaultness: ast::Defaultness,
|
||||
ty_opt: Option<&ptr::P<ast::Ty>>,
|
||||
ty_param_bounds_opt: Option<&ast::TyParamBounds>,
|
||||
context: &RewriteContext,
|
||||
indent: Indent)
|
||||
-> Option<String> {
|
||||
let result =
|
||||
try_opt!(rewrite_associated_type(ident, ty_opt, ty_param_bounds_opt, context, indent));
|
||||
|
||||
match defaultness {
|
||||
ast::Defaultness::Default => Some(format!("default {}", result)),
|
||||
_ => Some(result),
|
||||
}
|
||||
}
|
||||
|
||||
impl Rewrite for ast::FunctionRetTy {
|
||||
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
match *self {
|
||||
|
@ -18,7 +18,7 @@ use types::{rewrite_path, PathContext};
|
||||
use super::Spanned;
|
||||
use comment::FindUncommented;
|
||||
|
||||
use syntax::ast::{self, BindingMode, Pat, PatKind, FieldPat};
|
||||
use syntax::ast::{self, BindingMode, Pat, PatKind, FieldPat, RangeEnd};
|
||||
use syntax::ptr;
|
||||
use syntax::codemap::{self, BytePos, Span};
|
||||
|
||||
@ -56,8 +56,15 @@ impl Rewrite for Pat {
|
||||
None
|
||||
}
|
||||
}
|
||||
PatKind::Range(ref lhs, ref rhs) => {
|
||||
rewrite_pair(&**lhs, &**rhs, "", "...", "", context, shape)
|
||||
PatKind::Range(ref lhs, ref rhs, ref end_kind) => {
|
||||
match *end_kind {
|
||||
RangeEnd::Included => {
|
||||
rewrite_pair(&**lhs, &**rhs, "", "...", "", context, shape)
|
||||
}
|
||||
RangeEnd::Excluded => {
|
||||
rewrite_pair(&**lhs, &**rhs, "", "..", "", context, shape)
|
||||
}
|
||||
}
|
||||
}
|
||||
PatKind::Ref(ref pat, mutability) => {
|
||||
let prefix = format!("&{}", format_mutability(mutability));
|
||||
|
@ -32,7 +32,7 @@ pub struct StringFormat<'a> {
|
||||
// FIXME: simplify this!
|
||||
pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option<String> {
|
||||
// Strip line breaks.
|
||||
let re = Regex::new(r"([^\\](\\\\)*)\\[\n\r][:space:]*").unwrap();
|
||||
let re = Regex::new(r"([^\\](\\\\)*)\\[\n\r][[:space:]]*").unwrap();
|
||||
let stripped_str = re.replace_all(orig, "$1");
|
||||
|
||||
let graphemes = UnicodeSegmentation::graphemes(&*stripped_str, false).collect::<Vec<&str>>();
|
||||
|
@ -21,7 +21,8 @@ use config::Config;
|
||||
use rewrite::{Rewrite, RewriteContext};
|
||||
use comment::rewrite_comment;
|
||||
use macros::{rewrite_macro, MacroPosition};
|
||||
use items::{rewrite_static, rewrite_associated_type, rewrite_type_alias, format_impl, format_trait};
|
||||
use items::{rewrite_static, rewrite_associated_type, rewrite_associated_impl_type,
|
||||
rewrite_type_alias, format_impl, format_trait};
|
||||
|
||||
fn is_use_item(item: &ast::Item) -> bool {
|
||||
match item.node {
|
||||
@ -411,11 +412,12 @@ impl<'a> FmtVisitor<'a> {
|
||||
self.push_rewrite(ii.span, rewrite);
|
||||
}
|
||||
ast::ImplItemKind::Type(ref ty) => {
|
||||
let rewrite = rewrite_associated_type(ii.ident,
|
||||
Some(ty),
|
||||
None,
|
||||
&self.get_context(),
|
||||
self.block_indent);
|
||||
let rewrite = rewrite_associated_impl_type(ii.ident,
|
||||
ii.defaultness,
|
||||
Some(ty),
|
||||
None,
|
||||
&self.get_context(),
|
||||
self.block_indent);
|
||||
self.push_rewrite(ii.span, rewrite);
|
||||
}
|
||||
ast::ImplItemKind::Macro(ref mac) => {
|
||||
|
23
tests/source/issue-1127.rs
Normal file
23
tests/source/issue-1127.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// rustfmt-max_width:120
|
||||
// rustfmt-wrap_match_arms: false
|
||||
// rustfmt-match_block_trailing_comma: true
|
||||
|
||||
fn a_very_very_very_very_very_very_very_very_very_very_very_long_function_name() -> i32 {
|
||||
42
|
||||
}
|
||||
|
||||
enum TestEnum {
|
||||
AVeryVeryLongEnumName,
|
||||
AnotherVeryLongEnumName,
|
||||
TheLastVeryLongEnumName,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let var = TestEnum::AVeryVeryLongEnumName;
|
||||
let num = match var {
|
||||
TestEnum::AVeryVeryLongEnumName => a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
|
||||
TestEnum::AnotherVeryLongEnumName => a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
|
||||
TestEnum::TheLastVeryLongEnumName => a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
|
||||
};
|
||||
}
|
||||
|
@ -300,8 +300,8 @@ fn read_significant_comments(file_name: &str) -> HashMap<String, String> {
|
||||
.take_while(|line| line_regex.is_match(&line))
|
||||
.filter_map(|line| {
|
||||
regex.captures_iter(&line).next().map(|capture| {
|
||||
(capture.at(1).expect("Couldn't unwrap capture").to_owned(),
|
||||
capture.at(2).expect("Couldn't unwrap capture").to_owned())
|
||||
(capture.get(1).expect("Couldn't unwrap capture").as_str().to_owned(),
|
||||
capture.get(2).expect("Couldn't unwrap capture").as_str().to_owned())
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
|
25
tests/target/issue-1127.rs
Normal file
25
tests/target/issue-1127.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// rustfmt-max_width:120
|
||||
// rustfmt-wrap_match_arms: false
|
||||
// rustfmt-match_block_trailing_comma: true
|
||||
|
||||
fn a_very_very_very_very_very_very_very_very_very_very_very_long_function_name() -> i32 {
|
||||
42
|
||||
}
|
||||
|
||||
enum TestEnum {
|
||||
AVeryVeryLongEnumName,
|
||||
AnotherVeryLongEnumName,
|
||||
TheLastVeryLongEnumName,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let var = TestEnum::AVeryVeryLongEnumName;
|
||||
let num = match var {
|
||||
TestEnum::AVeryVeryLongEnumName =>
|
||||
a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
|
||||
TestEnum::AnotherVeryLongEnumName =>
|
||||
a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
|
||||
TestEnum::TheLastVeryLongEnumName =>
|
||||
a_very_very_very_very_very_very_very_very_very_very_very_long_function_name(),
|
||||
};
|
||||
}
|
10
tests/target/issue-1255.rs
Normal file
10
tests/target/issue-1255.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// Test for issue #1255
|
||||
// Default annotation incorrectly removed on associated types
|
||||
#![feature(specialization)]
|
||||
|
||||
trait Trait {
|
||||
type Type;
|
||||
}
|
||||
impl<T> Trait for T {
|
||||
default type Type = u64; // 'default' should not be removed
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user