Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
d67f1a4
Update log to 0.4.14
jyn514 May 2, 2021
e243be6
Allow formatting `Anonymous{Struct, Union}` declarations
jedel1043 May 17, 2021
58c63cf
Add support for using qualified paths with structs in expression and …
rylev Dec 10, 2020
1e2258f
Use `AttrVec` for `Arm`, `FieldDef`, and `Variant`
JohnTitor Jun 16, 2021
2608f2c
fix(rustfmt): load nested out-of-line mods correctly
calebcartwright Jun 18, 2021
a26237e
Remove `Ipv4Addr::is_ietf_protocol_assignment`
CDirkx Jun 18, 2021
71f01d1
Delete spaces
Jun 21, 2021
d13020c
Rollup merge of #86274 - alexander-melentyev:spaces, r=bjorn3
JohnTitor Jun 21, 2021
0b8a26f
Rollup merge of #86424 - calebcartwright:rustfmt-mod-resolution, r=Ma…
JohnTitor Jun 21, 2021
5d85130
Partially stabilize `const_slice_first_last`
jhpratt Jun 24, 2021
33acc96
Document rustfmt on nightly-rustc
jyn514 Jun 30, 2021
c93cb40
Move `os_str_bytes` to `sys::unix` and reuse it on other platforms.
CDirkx Jun 21, 2021
f2c0f29
Change env var getters to error recoverably
inquisitivecrystal Jun 9, 2021
d26e01e
Add test to prevent regression
inquisitivecrystal Jun 9, 2021
a12107a
Make `getenv` return an Option instead of a Result
inquisitivecrystal Jun 24, 2021
d9752c7
Improve env var getter docs
inquisitivecrystal Jul 6, 2021
a674ae6
Add documentation for `Ipv6MulticastScope`
CDirkx Jul 7, 2021
abf449f
Rework SESSION_GLOBALS API to prevent overwriting it
GuillaumeGomez May 5, 2021
277feac
Use LocalExpnId where possible.
cjgillot Jun 25, 2021
8f3844f
refactor adding rustc and std into extended builds
pietroalbini Jul 19, 2021
0c8baa7
refactor gating of dist docs
pietroalbini Jul 19, 2021
7167f8b
change output of dist cargo and clippy to be consistent with other tools
pietroalbini Jul 19, 2021
e60b348
refactor gating of tools
pietroalbini Jul 19, 2021
82faa9c
refactor gating of demangler
pietroalbini Jul 19, 2021
f4c6d8f
refactor gating of mingw
pietroalbini Jul 19, 2021
2cfac3f
don't build extra tools if build.tools is explicitly an empty list
pietroalbini Jul 23, 2021
c15e248
refactor extended tarball generaton to use the new ensure_if_default
pietroalbini Jul 23, 2021
bfd479d
Merge pull request #4920 from calebcartwright/subtree-sync
calebcartwright Jul 26, 2021
75765f6
Allow `--edition 2021` to be passed to rustfmt
PatchMixolydic May 22, 2021
1ca3798
Improve pasta copyability of `merge_imports` deprecation message
casey May 10, 2021
486e774
Adjusting help message (#4865)
murchu27 Jun 11, 2021
e634a6f
Updating outdated links (#4869)
murchu27 Jun 16, 2021
b305d62
fix: correct arm leading pipe check (#4880)
calebcartwright Jun 24, 2021
19733f1
Change line endings from CRLF to LF
Jun 25, 2021
2cf280e
docs: clarify match_arm_blocks config documentation
calebcartwright Jul 5, 2021
4c2959f
fix a bunch of clippy warnings
matthiaskrgr Jul 18, 2021
d42be80
chore: disable clippy::matches_like_macro lint
calebcartwright Jul 18, 2021
0832137
fix link in Contributing.md
ebobrow Jul 19, 2021
4236289
chore: bump toolchain
calebcartwright Jul 26, 2021
102a06b
Merge commit '4236289b75ee55c78538c749512cdbeea5e1c332' into update-r…
calebcartwright Jul 26, 2021
661f461
Update mdbook.
ehuss Jul 27, 2021
69f712c
set all of the optional tools as DEFAULT = true
pietroalbini Jul 28, 2021
377b4ce
Remove unused field `Session.system_library_path`
Aaron1011 Jul 29, 2021
8d2bb93
Consistent spelling of "adapter" in the standard library
steffahn Jul 30, 2021
12017f9
Update compiler_builtins to fix i128 shift/mul on thumbv6m
Amanieu Jul 30, 2021
9a2e3f3
Recommend `swap_remove` in `Vec::remove` docs
Flying-Toast Jul 30, 2021
6aaa832
mark a UB doctest as no_run
RalfJung Jul 31, 2021
9854d30
Update const_slice_first_last_not_mut stable version.
m-ou-se Aug 1, 2021
016612d
Rollup merge of #86183 - inquisitivecrystal:env-nul, r=m-ou-se
JohnTitor Aug 2, 2021
a03d6da
Rollup merge of #86439 - CDirkx:ip-protocol-assignment, r=m-ou-se
JohnTitor Aug 2, 2021
1176d30
Rollup merge of #86509 - CDirkx:os_str, r=m-ou-se
JohnTitor Aug 2, 2021
77d5683
Rollup merge of #86593 - jhpratt:stabilize-const_slice_first_last, r=…
JohnTitor Aug 2, 2021
f386ae3
Rollup merge of #86936 - CDirkx:ipv6-multicast, r=JohnTitor
JohnTitor Aug 2, 2021
46f01ca
Rollup merge of #87282 - pietroalbini:refactor-extended, r=Mark-Simul…
JohnTitor Aug 2, 2021
e95b0ff
Rollup merge of #87468 - calebcartwright:update-rustfmt, r=Mark-Simul…
JohnTitor Aug 2, 2021
0d747d0
Rollup merge of #87504 - ehuss:update-mdbook, r=Mark-Simulacrum
JohnTitor Aug 2, 2021
5cf6566
Rollup merge of #87608 - Aaron1011:remove-system-library, r=Mark-Simu…
JohnTitor Aug 2, 2021
87c1436
Rollup merge of #87629 - steffahn:consistent_adapter_spelling, r=m-ou-se
JohnTitor Aug 2, 2021
e924e76
Rollup merge of #87633 - Amanieu:fix-86063, r=Mark-Simulacrum
JohnTitor Aug 2, 2021
0c9b35b
Rollup merge of #87644 - Flying-Toast:vec-remove-note, r=the8472
JohnTitor Aug 2, 2021
0851841
Rollup merge of #87653 - RalfJung:dont-run-ub, r=kennytm
JohnTitor Aug 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix a bunch of clippy warnings
clippy::bind_instead_of_map
clippy::branches_sharing_code
clippy::collapsible_match
clippy::inconsistent_struct_constructor
clippy::int_plus_one
clippy::iter_count
clippy::iter_nth_zero
clippy::manual_range_contains
clippy::match_like_matches_macro
clippy::needless::collect
clippy::needless_question_mark
clippy::needless_return
clippy::op_ref
clippy::option_as_ref_deref
clippy::ptr_arg
clippy::redundant_clone
clippy::redundant_closure
clippy::redundant_static_lifetimes
clippy::search_is_some
clippy::#single_char_add_str
clippy::single_char_pattern
clippy::single_component_path_imports
clippy::single_match
clippy::skip_while_next
clippy::unnecessary_lazy_evaluations
clippy::unnecessary_unwrap
clippy::useless_conversion
clippy::useless_format
  • Loading branch information
matthiaskrgr authored and calebcartwright committed Jul 26, 2021
commit 4c2959fb12a6bd083003ec4371126211402e265d
2 changes: 1 addition & 1 deletion src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn format_derive(
} else if let SeparatorTactic::Always = context.config.trailing_comma() {
// Retain the trailing comma.
result.push_str(&item_str);
} else if item_str.ends_with(",") {
} else if item_str.ends_with(',') {
// Remove the trailing comma.
result.push_str(&item_str[..item_str.len() - 1]);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/cargo-fmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ fn get_targets_recursive(
.packages
.iter()
.find(|p| p.name == dependency.name && p.source.is_none());
let manifest_path = if dependency_package.is_some() {
PathBuf::from(&dependency_package.unwrap().manifest_path)
let manifest_path = if let Some(dep_pkg) = dependency_package {
PathBuf::from(&dep_pkg.manifest_path)
} else {
let mut package_manifest_path = PathBuf::from(&package.manifest_path);
package_manifest_path.pop();
Expand Down
5 changes: 1 addition & 4 deletions src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,7 @@ impl ChainItem {
}

fn is_comment(&self) -> bool {
match self.kind {
ChainItemKind::Comment(..) => true,
_ => false,
}
matches!(self.kind, ChainItemKind::Comment(..))
}

fn rewrite_method_call(
Expand Down
15 changes: 6 additions & 9 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,23 +336,23 @@ pub(crate) fn rewrite_last_closure(

// We force to use block for the body of the closure for certain kinds of expressions.
if is_block_closure_forced(context, body) {
return rewrite_closure_with_block(body, &prefix, context, body_shape).and_then(
return rewrite_closure_with_block(body, &prefix, context, body_shape).map(
|body_str| {
match fn_decl.output {
ast::FnRetTy::Default(..) if body_str.lines().count() <= 7 => {
// If the expression can fit in a single line, we need not force block
// closure. However, if the closure has a return type, then we must
// keep the blocks.
match rewrite_closure_expr(body, &prefix, context, shape) {
Some(ref single_line_body_str)
Some(single_line_body_str)
if !single_line_body_str.contains('\n') =>
{
Some(single_line_body_str.clone())
single_line_body_str
}
_ => Some(body_str),
_ => body_str,
}
}
_ => Some(body_str),
_ => body_str,
}
},
);
Expand All @@ -377,10 +377,7 @@ pub(crate) fn rewrite_last_closure(
pub(crate) fn args_have_many_closure(args: &[OverflowableItem<'_>]) -> bool {
args.iter()
.filter_map(OverflowableItem::to_expr)
.filter(|expr| match expr.kind {
ast::ExprKind::Closure(..) => true,
_ => false,
})
.filter(|expr| matches!(expr.kind, ast::ExprKind::Closure(..)))
.count()
> 1
}
Expand Down
21 changes: 9 additions & 12 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ impl<'a> CommentStyle<'a> {

/// Returns `true` if the commenting style is for documentation.
pub(crate) fn is_doc_comment(&self) -> bool {
match *self {
CommentStyle::TripleSlash | CommentStyle::Doc => true,
_ => false,
}
matches!(*self, CommentStyle::TripleSlash | CommentStyle::Doc)
}

pub(crate) fn opener(&self) -> &'a str {
Expand Down Expand Up @@ -689,8 +686,8 @@ impl<'a> CommentRewrite<'a> {

self.code_block_attr = None;
self.item_block = None;
if line.starts_with("```") {
self.code_block_attr = Some(CodeBlockAttribute::new(&line[3..]))
if let Some(stripped) = line.strip_prefix("```") {
self.code_block_attr = Some(CodeBlockAttribute::new(stripped))
} else if self.fmt.config.wrap_comments() && ItemizedBlock::is_itemized_line(&line) {
let ib = ItemizedBlock::new(&line);
self.item_block = Some(ib);
Expand Down Expand Up @@ -948,8 +945,8 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle<'_>) -> (&'a s
{
(&line[4..], true)
} else if let CommentStyle::Custom(opener) = *style {
if line.starts_with(opener) {
(&line[opener.len()..], true)
if let Some(ref stripped) = line.strip_prefix(opener) {
(stripped, true)
} else {
(&line[opener.trim_end().len()..], false)
}
Expand All @@ -968,8 +965,8 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle<'_>) -> (&'a s
|| line.starts_with("**")
{
(&line[2..], line.chars().nth(1).unwrap() == ' ')
} else if line.starts_with('*') {
(&line[1..], false)
} else if let Some(stripped) = line.strip_prefix('*') {
(stripped, false)
} else {
(line, line.starts_with(' '))
}
Expand Down Expand Up @@ -1682,8 +1679,8 @@ impl<'a> Iterator for CommentReducer<'a> {
fn remove_comment_header(comment: &str) -> &str {
if comment.starts_with("///") || comment.starts_with("//!") {
&comment[3..]
} else if comment.starts_with("//") {
&comment[2..]
} else if let Some(ref stripped) = comment.strip_prefix("//") {
stripped
} else if (comment.starts_with("/**") && !comment.starts_with("/**/"))
|| comment.starts_with("/*!")
{
Expand Down
4 changes: 2 additions & 2 deletions src/config/file_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl str::FromStr for FileLines {
let mut m = HashMap::new();
for js in v {
let (s, r) = JsonSpan::into_tuple(js)?;
m.entry(s).or_insert_with(|| vec![]).push(r);
m.entry(s).or_insert_with(Vec::new).push(r);
}
Ok(FileLines::from_ranges(m))
}
Expand All @@ -322,7 +322,7 @@ impl JsonSpan {
fn into_tuple(self) -> Result<(FileName, Range), FileLinesError> {
let (lo, hi) = self.range;
let canonical = canonicalize_path_string(&self.file)
.ok_or_else(|| FileLinesError::CannotCanonicalize(self.file))?;
.ok_or(FileLinesError::CannotCanonicalize(self.file))?;
Ok((canonical, Range::new(lo, hi)))
}
}
Expand Down
1 change: 0 additions & 1 deletion src/config/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::fs::File;
use std::io;
use std::io::Read;

use regex;
use regex::Regex;

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/emitter/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Emitter for DiffEmitter {
return Ok(EmitterResult { has_diff: true });
}

return Ok(EmitterResult { has_diff });
Ok(EmitterResult { has_diff })
}
}

Expand Down
30 changes: 10 additions & 20 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,12 @@ pub(crate) fn format_expr(
}

fn needs_space_after_range(rhs: &ast::Expr) -> bool {
match rhs.kind {
// Don't format `.. ..` into `....`, which is invalid.
//
// This check is unnecessary for `lhs`, because a range
// starting from another range needs parentheses as `(x ..) ..`
// (`x .. ..` is a range from `x` to `..`).
ast::ExprKind::Range(None, _, _) => true,
_ => false,
}
// Don't format `.. ..` into `....`, which is invalid.
//
// This check is unnecessary for `lhs`, because a range
// starting from another range needs parentheses as `(x ..) ..`
// (`x .. ..` is a range from `x` to `..`).
matches!(rhs.kind, ast::ExprKind::Range(None, _, _))
}

let default_sp_delim = |lhs: Option<&ast::Expr>, rhs: Option<&ast::Expr>| {
Expand Down Expand Up @@ -531,7 +528,7 @@ pub(crate) fn rewrite_block_with_visitor(

let inner_attrs = attrs.map(inner_attributes);
let label_str = rewrite_label(label);
visitor.visit_block(block, inner_attrs.as_ref().map(|a| &**a), has_braces);
visitor.visit_block(block, inner_attrs.as_deref(), has_braces);
let visitor_context = visitor.get_context();
context
.skipped_range
Expand Down Expand Up @@ -595,7 +592,7 @@ pub(crate) fn rewrite_cond(
String::from("\n") + &shape.indent.block_only().to_string(context.config);
control_flow
.rewrite_cond(context, shape, &alt_block_sep)
.and_then(|rw| Some(rw.0))
.map(|rw| rw.0)
}),
}
}
Expand Down Expand Up @@ -1157,18 +1154,11 @@ pub(crate) fn is_empty_block(
}

pub(crate) fn stmt_is_expr(stmt: &ast::Stmt) -> bool {
match stmt.kind {
ast::StmtKind::Expr(..) => true,
_ => false,
}
matches!(stmt.kind, ast::StmtKind::Expr(..))
}

pub(crate) fn is_unsafe_block(block: &ast::Block) -> bool {
if let ast::BlockCheckMode::Unsafe(..) = block.rules {
true
} else {
false
}
matches!(block.rules, ast::BlockCheckMode::Unsafe(..))
}

pub(crate) fn rewrite_literal(
Expand Down
2 changes: 1 addition & 1 deletion src/formatting/newline_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn convert_to_windows_newlines(formatted_text: &String) -> String {
transformed
}

fn convert_to_unix_newlines(formatted_text: &String) -> String {
fn convert_to_unix_newlines(formatted_text: &str) -> String {
formatted_text.replace(WINDOWS_NEWLINE, UNIX_NEWLINE)
}

Expand Down
30 changes: 11 additions & 19 deletions src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl UseTree {
UseTreeKind::Nested(ref list) => {
// Extract comments between nested use items.
// This needs to be done before sorting use items.
let items: Vec<_> = itemize_list(
let items = itemize_list(
context.snippet_provider,
list.iter().map(|(tree, _)| tree),
"}",
Expand All @@ -385,16 +385,16 @@ impl UseTree {
context.snippet_provider.span_after(a.span, "{"),
a.span.hi(),
false,
)
.collect();
);

// in case of a global path and the nested list starts at the root,
// e.g., "::{foo, bar}"
if a.prefix.segments.len() == 1 && leading_modsep {
result.path.push(UseSegment::Ident("".to_owned(), None));
}
result.path.push(UseSegment::List(
list.iter()
.zip(items.into_iter())
.zip(items)
.map(|(t, list_item)| {
Self::from_ast(context, &t.0, Some(list_item), None, None, None)
})
Expand Down Expand Up @@ -466,11 +466,8 @@ impl UseTree {

// Normalise foo::self as bar -> foo as bar.
if let UseSegment::Slf(_) = last {
match self.path.last() {
Some(UseSegment::Ident(_, None)) => {
aliased_self = true;
}
_ => {}
if let Some(UseSegment::Ident(_, None)) = self.path.last() {
aliased_self = true;
}
}

Expand Down Expand Up @@ -572,9 +569,8 @@ impl UseTree {
match self.path.clone().last().unwrap() {
UseSegment::List(list) => {
if list.len() == 1 && list[0].path.len() == 1 {
match list[0].path[0] {
UseSegment::Slf(..) => return vec![self],
_ => (),
if let UseSegment::Slf(..) = list[0].path[0] {
return vec![self];
};
}
let prefix = &self.path[..self.path.len() - 1];
Expand Down Expand Up @@ -790,13 +786,9 @@ fn rewrite_nested_use_tree(
}
}
let has_nested_list = use_tree_list.iter().any(|use_segment| {
use_segment
.path
.last()
.map_or(false, |last_segment| match last_segment {
UseSegment::List(..) => true,
_ => false,
})
use_segment.path.last().map_or(false, |last_segment| {
matches!(last_segment, UseSegment::List(..))
})
});

let remaining_width = if has_nested_list {
Expand Down
14 changes: 3 additions & 11 deletions src/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@ impl BadIssueSeeker {
return Seeking::Number {
issue: Issue {
issue_type: IssueType::Todo,
missing_number: if let ReportTactic::Unnumbered = self.report_todo {
true
} else {
false
},
missing_number: matches!(self.report_todo, ReportTactic::Unnumbered),
},
part: NumberPart::OpenParen,
};
Expand All @@ -144,11 +140,7 @@ impl BadIssueSeeker {
return Seeking::Number {
issue: Issue {
issue_type: IssueType::Fixme,
missing_number: if let ReportTactic::Unnumbered = self.report_fixme {
true
} else {
false
},
missing_number: matches!(self.report_fixme, ReportTactic::Unnumbered),
},
part: NumberPart::OpenParen,
};
Expand Down Expand Up @@ -196,7 +188,7 @@ impl BadIssueSeeker {
}
}
NumberPart::Number => {
if c >= '0' && c <= '9' {
if ('0'..='9').contains(&c) {
part = NumberPart::CloseParen;
} else {
return IssueClassification::Bad(issue);
Expand Down
Loading