Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
h-michael committed Feb 9, 2019
1 parent 4bb90f5 commit 8183b94
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/cargo-fmt/main.rs
Expand Up @@ -16,7 +16,6 @@
use cargo_metadata;
use getopts;


use std::collections::{HashMap, HashSet};
use std::env;
use std::fs;
Expand Down
14 changes: 11 additions & 3 deletions src/chains.rs
Expand Up @@ -84,7 +84,11 @@ use crate::utils::{
trimmed_last_line_width, wrap_str,
};

pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
pub fn rewrite_chain(
expr: &ast::Expr,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
let chain = Chain::from_ast(expr, context);
debug!("rewrite_chain {:?} {:?}", chain, shape);

Expand Down Expand Up @@ -419,8 +423,12 @@ impl Rewrite for Chain {
debug!("rewrite chain {:?} {:?}", self, shape);

let mut formatter = match context.config.indent_style() {
IndentStyle::Block => Box::new(ChainFormatterBlock::new(self)) as Box<dyn ChainFormatter>,
IndentStyle::Visual => Box::new(ChainFormatterVisual::new(self)) as Box<dyn ChainFormatter>,
IndentStyle::Block => {
Box::new(ChainFormatterBlock::new(self)) as Box<dyn ChainFormatter>
}
IndentStyle::Visual => {
Box::new(ChainFormatterVisual::new(self)) as Box<dyn ChainFormatter>
}
};

formatter.format_root(&self.parent, context, shape)?;
Expand Down
12 changes: 10 additions & 2 deletions src/expr.rs
Expand Up @@ -590,7 +590,11 @@ impl Rewrite for ast::Stmt {
}

// Rewrite condition if the given expression has one.
pub fn rewrite_cond(context: &RewriteContext<'_>, expr: &ast::Expr, shape: Shape) -> Option<String> {
pub fn rewrite_cond(
context: &RewriteContext<'_>,
expr: &ast::Expr,
shape: Shape,
) -> Option<String> {
match expr.node {
ast::ExprKind::Match(ref cond, _) => {
// `match `cond` {`
Expand Down Expand Up @@ -1337,7 +1341,11 @@ pub fn is_every_expr_simple(lists: &[OverflowableItem<'_>]) -> bool {
lists.iter().all(OverflowableItem::is_simple)
}

pub fn can_be_overflowed_expr(context: &RewriteContext<'_>, expr: &ast::Expr, args_len: usize) -> bool {
pub fn can_be_overflowed_expr(
context: &RewriteContext<'_>,
expr: &ast::Expr,
args_len: usize,
) -> bool {
match expr.node {
ast::ExprKind::Match(..) => {
(context.use_block_indent() && args_len == 1)
Expand Down
12 changes: 10 additions & 2 deletions src/items.rs
Expand Up @@ -998,7 +998,11 @@ fn format_struct(
}
}

pub fn format_trait(context: &RewriteContext<'_>, item: &ast::Item, offset: Indent) -> Option<String> {
pub fn format_trait(
context: &RewriteContext<'_>,
item: &ast::Item,
offset: Indent,
) -> Option<String> {
if let ast::ItemKind::Trait(
is_auto,
unsafety,
Expand Down Expand Up @@ -1172,7 +1176,11 @@ pub fn format_trait_alias(
rewrite_assign_rhs(context, lhs, generic_bounds, shape.sub_width(1)?).map(|s| s + ";")
}

fn format_unit_struct(context: &RewriteContext<'_>, p: &StructParts<'_>, offset: Indent) -> Option<String> {
fn format_unit_struct(
context: &RewriteContext<'_>,
p: &StructParts<'_>,
offset: Indent,
) -> Option<String> {
let header_str = format_header(context, p.prefix, p.ident, p.vis);
let generics_str = if let Some(generics) = p.generics {
let hi = if generics.where_clause.predicates.is_empty() {
Expand Down
12 changes: 10 additions & 2 deletions src/macros.rs
Expand Up @@ -1027,7 +1027,11 @@ fn wrap_macro_args_inner(
//
// We always try and format on one line.
// FIXME: Use multi-line when every thing does not fit on one line.
fn format_macro_args(context: &RewriteContext<'_>, toks: TokenStream, shape: Shape) -> Option<String> {
fn format_macro_args(
context: &RewriteContext<'_>,
toks: TokenStream,
shape: Shape,
) -> Option<String> {
if !context.config.format_macro_matchers() {
let token_stream: TokenStream = toks.into();
let span = span_for_token_stream(&token_stream);
Expand Down Expand Up @@ -1340,7 +1344,11 @@ impl MacroBranch {
/// [pub] static ref NAME_N: TYPE_N = EXPR_N;
/// }
/// ```
fn format_lazy_static(context: &RewriteContext<'_>, shape: Shape, ts: &TokenStream) -> Option<String> {
fn format_lazy_static(
context: &RewriteContext<'_>,
shape: Shape,
ts: &TokenStream,
) -> Option<String> {
let mut result = String::with_capacity(1024);
let mut parser = new_parser_from_tts(context.parse_session, ts.trees().collect());
let nested_shape = shape
Expand Down
5 changes: 4 additions & 1 deletion src/overflow.rs
Expand Up @@ -758,7 +758,10 @@ fn no_long_items(list: &[ListItem]) -> bool {
}

/// In case special-case style is required, returns an offset from which we start horizontal layout.
pub fn maybe_get_args_offset(callee_str: &str, args: &[OverflowableItem<'_>]) -> Option<(bool, usize)> {
pub fn maybe_get_args_offset(
callee_str: &str,
args: &[OverflowableItem<'_>],
) -> Option<(bool, usize)> {
if let Some(&(_, num_args_before)) = args
.get(0)?
.whitelist()
Expand Down
6 changes: 5 additions & 1 deletion src/patterns.rs
Expand Up @@ -288,7 +288,11 @@ impl<'a> Spanned for TuplePatField<'a> {
}
}

pub fn can_be_overflowed_pat(context: &RewriteContext<'_>, pat: &TuplePatField<'_>, len: usize) -> bool {
pub fn can_be_overflowed_pat(
context: &RewriteContext<'_>,
pat: &TuplePatField<'_>,
len: usize,
) -> bool {
match *pat {
TuplePatField::Pat(pat) => match pat.node {
ast::PatKind::Path(..)
Expand Down

0 comments on commit 8183b94

Please sign in to comment.