Skip to content

Commit

Permalink
Format source codes
Browse files Browse the repository at this point in the history
  • Loading branch information
topecongiro committed Jul 11, 2017
1 parent 08f3f03 commit e3310a6
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 480 deletions.
22 changes: 9 additions & 13 deletions src/bin/cargo-fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,11 @@ fn execute() -> i32 {
print_usage(&opts, &e.to_string());
failure
}
Ok(status) => {
if status.success() {
success
} else {
status.code().unwrap_or(failure)
}
}
Ok(status) => if status.success() {
success
} else {
status.code().unwrap_or(failure)
},
}
}

Expand Down Expand Up @@ -324,12 +322,10 @@ fn format_files(
.args(fmt_args)
.spawn()
.map_err(|e| match e.kind() {
std::io::ErrorKind::NotFound => {
std::io::Error::new(
std::io::ErrorKind::Other,
"Could not run rustfmt, please make sure it is in your PATH.",
)
}
std::io::ErrorKind::NotFound => std::io::Error::new(
std::io::ErrorKind::Other,
"Could not run rustfmt, please make sure it is in your PATH.",
),
_ => e,
})?;
command.wait()
Expand Down
20 changes: 8 additions & 12 deletions src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,10 @@ fn rewrite_method_call_with_overflow(
None => return false,
};
let types = match segment.parameters {
Some(ref params) => {
match **params {
ast::PathParameters::AngleBracketed(ref data) => &data.types[..],
_ => &[],
}
}
Some(ref params) => match **params {
ast::PathParameters::AngleBracketed(ref data) => &data.types[..],
_ => &[],
},
_ => &[],
};
let mut last_rewrite = rewrite_method_call(
Expand Down Expand Up @@ -516,12 +514,10 @@ fn rewrite_chain_subexpr(
match expr.node {
ast::ExprKind::MethodCall(ref segment, ref expressions) => {
let types = match segment.parameters {
Some(ref params) => {
match **params {
ast::PathParameters::AngleBracketed(ref data) => &data.types[..],
_ => &[],
}
}
Some(ref params) => match **params {
ast::PathParameters::AngleBracketed(ref data) => &data.types[..],
_ => &[],
},
_ => &[],
};
rewrite_method_call(segment.identifier, types, expressions, span, context, shape)
Expand Down
88 changes: 38 additions & 50 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,12 @@ impl FindUncommented for str {
None => {
return Some(i - pat.len());
}
Some(c) => {
match kind {
FullCodeCharKind::Normal if b == c => {}
_ => {
needle_iter = pat.chars();
}
Some(c) => match kind {
FullCodeCharKind::Normal if b == c => {}
_ => {
needle_iter = pat.chars();
}
}
},
}
}

Expand Down Expand Up @@ -494,42 +492,34 @@ where
let item = try_opt!(self.base.next());
let chr = item.get_char();
self.status = match self.status {
CharClassesStatus::LitString => {
match chr {
'"' => CharClassesStatus::Normal,
'\\' => CharClassesStatus::LitStringEscape,
_ => CharClassesStatus::LitString,
}
}
CharClassesStatus::LitString => match chr {
'"' => CharClassesStatus::Normal,
'\\' => CharClassesStatus::LitStringEscape,
_ => CharClassesStatus::LitString,
},
CharClassesStatus::LitStringEscape => CharClassesStatus::LitString,
CharClassesStatus::LitChar => {
match chr {
'\\' => CharClassesStatus::LitCharEscape,
'\'' => CharClassesStatus::Normal,
_ => CharClassesStatus::LitChar,
}
}
CharClassesStatus::LitChar => match chr {
'\\' => CharClassesStatus::LitCharEscape,
'\'' => CharClassesStatus::Normal,
_ => CharClassesStatus::LitChar,
},
CharClassesStatus::LitCharEscape => CharClassesStatus::LitChar,
CharClassesStatus::Normal => {
match chr {
'"' => CharClassesStatus::LitString,
'\'' => CharClassesStatus::LitChar,
'/' => {
match self.base.peek() {
Some(next) if next.get_char() == '*' => {
self.status = CharClassesStatus::BlockCommentOpening(1);
return Some((FullCodeCharKind::StartComment, item));
}
Some(next) if next.get_char() == '/' => {
self.status = CharClassesStatus::LineComment;
return Some((FullCodeCharKind::StartComment, item));
}
_ => CharClassesStatus::Normal,
}
CharClassesStatus::Normal => match chr {
'"' => CharClassesStatus::LitString,
'\'' => CharClassesStatus::LitChar,
'/' => match self.base.peek() {
Some(next) if next.get_char() == '*' => {
self.status = CharClassesStatus::BlockCommentOpening(1);
return Some((FullCodeCharKind::StartComment, item));
}
Some(next) if next.get_char() == '/' => {
self.status = CharClassesStatus::LineComment;
return Some((FullCodeCharKind::StartComment, item));
}
_ => CharClassesStatus::Normal,
}
}
},
_ => CharClassesStatus::Normal,
},
CharClassesStatus::BlockComment(deepness) => {
assert!(deepness != 0);
self.status = match self.base.peek() {
Expand Down Expand Up @@ -558,18 +548,16 @@ where
return Some((FullCodeCharKind::InComment, item));
}
}
CharClassesStatus::LineComment => {
match chr {
'\n' => {
self.status = CharClassesStatus::Normal;
return Some((FullCodeCharKind::EndComment, item));
}
_ => {
self.status = CharClassesStatus::LineComment;
return Some((FullCodeCharKind::InComment, item));
}
CharClassesStatus::LineComment => match chr {
'\n' => {
self.status = CharClassesStatus::Normal;
return Some((FullCodeCharKind::EndComment, item));
}
}
_ => {
self.status = CharClassesStatus::LineComment;
return Some((FullCodeCharKind::InComment, item));
}
},
};
Some((FullCodeCharKind::Normal, item))
}
Expand Down
8 changes: 3 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,9 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
Ok(ref md) if md.is_file() => return Ok(Some(config_file)),
// Return the error if it's something other than `NotFound`; otherwise we didn't
// find the project file yet, and continue searching.
Err(e) => {
if e.kind() != ErrorKind::NotFound {
return Err(e);
}
}
Err(e) => if e.kind() != ErrorKind::NotFound {
return Err(e);
},
_ => {}
}
}
Expand Down
Loading

0 comments on commit e3310a6

Please sign in to comment.