This commit is contained in:
Shotaro Yamada
2018-10-15 20:36:39 +09:00
parent d55729987f
commit 751bcf5fa0
8 changed files with 36 additions and 40 deletions
+1 -1
View File
@@ -83,7 +83,7 @@ fn main() {
);
if let Err(e) = run(&opts) {
println!("{}", opts.usage(&format!("{}", e)));
println!("{}", opts.usage(&e.to_string()));
process::exit(1);
}
}
+7 -12
View File
@@ -1543,7 +1543,7 @@ pub fn rewrite_struct_field_prefix(
rewrite_ident(context, name),
type_annotation_spacing.0
),
None => format!("{}", vis),
None => vis.to_string(),
})
}
@@ -2004,18 +2004,13 @@ fn rewrite_fn_base(
one_line_budget, multi_line_budget, arg_indent
);
result.push('(');
// Check if vertical layout was forced.
if one_line_budget == 0 {
if snuggle_angle_bracket {
result.push('(');
} else {
result.push_str("(");
if context.config.indent_style() == IndentStyle::Visual {
result.push_str(&arg_indent.to_string_with_newline(context.config));
}
}
} else {
result.push('(');
if one_line_budget == 0
&& !snuggle_angle_bracket
&& context.config.indent_style() == IndentStyle::Visual
{
result.push_str(&arg_indent.to_string_with_newline(context.config));
}
// Skip `pub(crate)`.
+1 -1
View File
@@ -50,7 +50,7 @@ pub fn new(shape: Shape, config: &'a Config) -> Self {
ends_with_newline: true,
preserve_newline: false,
nested: false,
config: config,
config,
}
}
+2 -2
View File
@@ -1073,7 +1073,7 @@ fn next_space(tok: &Token) -> SpaceState {
/// when the macro is not an instance of try! (or parsing the inner expression
/// failed).
pub fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext) -> Option<ast::Expr> {
if &format!("{}", mac.node.path) == "try" {
if &mac.node.path.to_string() == "try" {
let ts: TokenStream = mac.node.tts.clone().into();
let mut parser = new_parser_from_tts(context.parse_session, ts.trees().collect());
@@ -1491,5 +1491,5 @@ fn rewrite_macro_with_items(
result.push_str(&shape.indent.to_string_with_newline(context.config));
result.push_str(closer);
result.push_str(trailing_semicolon);
return Some(result);
Some(result)
}
+1 -1
View File
@@ -425,7 +425,7 @@ fn rewrite_last_item_with_overflow(
_ => expr.rewrite(self.context, shape),
}
}
item @ _ => item.rewrite(self.context, shape),
item => item.rewrite(self.context, shape),
};
if let Some(rewrite) = rewrite {
+7 -5
View File
@@ -51,11 +51,13 @@ fn span_after_last(&self, original: Span, needle: &str) -> BytePos {
}
fn span_before(&self, original: Span, needle: &str) -> BytePos {
self.opt_span_before(original, needle).expect(&format!(
"bad span: {}: {}",
needle,
self.span_to_snippet(original).unwrap()
))
self.opt_span_before(original, needle).unwrap_or_else(|| {
panic!(
"bad span: {}: {}",
needle,
self.span_to_snippet(original).unwrap()
)
})
}
fn opt_span_after(&self, original: Span, needle: &str) -> Option<BytePos> {
+1 -1
View File
@@ -45,7 +45,7 @@ pub fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool {
(
VisibilityKind::Restricted { path: p, .. },
VisibilityKind::Restricted { path: q, .. },
) => format!("{}", p) == format!("{}", q),
) => p.to_string() == q.to_string(),
(VisibilityKind::Public, VisibilityKind::Public)
| (VisibilityKind::Inherited, VisibilityKind::Inherited)
| (
+16 -17
View File
@@ -112,7 +112,7 @@ fn visit_stmt(&mut self, stmt: &ast::Stmt) {
if contains_skip(get_attrs_from_stmt(stmt)) {
self.push_skipped_with_span(stmt.span());
} else {
let shape = self.shape().clone();
let shape = self.shape();
let rewrite = self.with_context(|ctx| stmt.rewrite(&ctx, shape));
self.push_rewrite(stmt.span(), rewrite)
}
@@ -367,13 +367,13 @@ pub fn visit_item(&mut self, item: &ast::Item) {
let where_span_end = snippet
.find_uncommented("{")
.map(|x| BytePos(x as u32) + source!(self, item.span).lo());
let block_indent = self.block_indent.clone();
let block_indent = self.block_indent;
let rw =
self.with_context(|ctx| format_impl(&ctx, item, block_indent, where_span_end));
self.push_rewrite(item.span, rw);
}
ast::ItemKind::Trait(..) => {
let block_indent = self.block_indent.clone();
let block_indent = self.block_indent;
let rw = self.with_context(|ctx| format_trait(&ctx, item, block_indent));
self.push_rewrite(item.span, rw);
}
@@ -652,20 +652,19 @@ pub fn visit_attrs(&mut self, attrs: &[ast::Attribute], style: ast::AttrStyle) -
ErrorKind::DeprecatedAttr,
)],
);
} else if attr.path.segments[0].ident.to_string() == "rustfmt" {
if attr.path.segments.len() == 1
|| attr.path.segments[1].ident.to_string() != "skip"
{
let file_name = self.source_map.span_to_filename(attr.span).into();
self.report.append(
file_name,
vec![FormattingError::from_span(
attr.span,
&self.source_map,
ErrorKind::BadAttr,
)],
);
}
} else if attr.path.segments[0].ident.to_string() == "rustfmt"
&& (attr.path.segments.len() == 1
|| attr.path.segments[1].ident.to_string() != "skip")
{
let file_name = self.source_map.span_to_filename(attr.span).into();
self.report.append(
file_name,
vec![FormattingError::from_span(
attr.span,
&self.source_map,
ErrorKind::BadAttr,
)],
);
}
}
if contains_skip(attrs) {