Skip to content

Commit 42bc2b5

Browse files
cargo fmt
1 parent 861a4e0 commit 42bc2b5

16 files changed

+71
-83
lines changed

src/closures.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ fn needs_block(
124124
prefix: &str,
125125
context: &RewriteContext<'_>,
126126
) -> bool {
127-
let has_attributes = block.stmts.first().is_some_and(|first_stmt| {
128-
!get_attrs_from_stmt(first_stmt).is_empty()
129-
});
127+
let has_attributes = block
128+
.stmts
129+
.first()
130+
.is_some_and(|first_stmt| !get_attrs_from_stmt(first_stmt).is_empty());
130131

131132
is_unsafe_block(block)
132133
|| block.stmts.len() > 1
@@ -434,9 +435,8 @@ pub(crate) fn rewrite_last_closure(
434435

435436
// When overflowing the closure which consists of a single control flow expression,
436437
// force to use block if its condition uses multi line.
437-
let is_multi_lined_cond = rewrite_cond(context, body, body_shape).is_some_and(|cond| {
438-
cond.contains('\n') || cond.len() > body_shape.width
439-
});
438+
let is_multi_lined_cond = rewrite_cond(context, body, body_shape)
439+
.is_some_and(|cond| cond.contains('\n') || cond.len() > body_shape.width);
440440
if is_multi_lined_cond {
441441
return rewrite_closure_with_block(body, &prefix, context, body_shape);
442442
}

src/config/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1389,8 +1389,7 @@ make_backup = false
13891389
for minor in current_version.minor..0 {
13901390
let toml = format!(
13911391
"required_version=\"^{}.{}.0\"",
1392-
current_version.major,
1393-
minor
1392+
current_version.major, minor
13941393
);
13951394
let config = Config::from_toml(&toml, Path::new("./rustfmt.toml")).unwrap();
13961395

@@ -1443,10 +1442,7 @@ make_backup = false
14431442
#[nightly_only_test]
14441443
#[test]
14451444
fn test_required_version_pre_release() {
1446-
let toml = format!(
1447-
"required_version=\"^{}-alpha\"",
1448-
get_current_version()
1449-
);
1445+
let toml = format!("required_version=\"^{}-alpha\"", get_current_version());
14501446
let config = Config::from_toml(&toml, Path::new("./rustfmt.toml")).unwrap();
14511447

14521448
assert!(config.version_meets_requirement());
@@ -1455,10 +1451,7 @@ make_backup = false
14551451
#[nightly_only_test]
14561452
#[test]
14571453
fn test_required_version_with_build_metadata() {
1458-
let toml = format!(
1459-
"required_version=\"{}+build.1\"",
1460-
get_current_version()
1461-
);
1454+
let toml = format!("required_version=\"{}+build.1\"", get_current_version());
14621455

14631456
let config = Config::from_toml(&toml, Path::new("./rustfmt.toml")).unwrap();
14641457

src/config/options.rs

-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ impl ::std::str::FromStr for WidthHeuristics {
327327
}
328328
}
329329

330-
331330
/// A set of directories, files and modules that rustfmt should ignore.
332331
#[derive(Default, Clone, Debug, PartialEq)]
333332
pub struct IgnoreList {
@@ -459,7 +458,6 @@ pub enum Edition {
459458
Edition2024,
460459
}
461460

462-
463461
impl From<Edition> for rustc_span::edition::Edition {
464462
fn from(edition: Edition) -> Self {
465463
match edition {

src/expr.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,7 @@ pub(crate) fn format_expr(
300300
shape,
301301
SeparatorPlace::Front,
302302
),
303-
ast::ExprKind::Index(ref expr, ref index, _) => {
304-
rewrite_index(expr, index, context, shape)
305-
}
303+
ast::ExprKind::Index(ref expr, ref index, _) => rewrite_index(expr, index, context, shape),
306304
ast::ExprKind::Repeat(ref expr, ref repeats) => rewrite_pair(
307305
&**expr,
308306
&*repeats.value,
@@ -1765,13 +1763,14 @@ fn rewrite_struct_lit(
17651763
)
17661764
.unknown_error()?
17671765
} else {
1768-
let field_iter = fields.iter().map(StructLitField::Regular).chain(
1769-
match struct_rest {
1766+
let field_iter = fields
1767+
.iter()
1768+
.map(StructLitField::Regular)
1769+
.chain(match struct_rest {
17701770
ast::StructRest::Base(expr) => Some(StructLitField::Base(expr)),
17711771
ast::StructRest::Rest(span) => Some(StructLitField::Rest(*span)),
17721772
ast::StructRest::None => None,
1773-
},
1774-
);
1773+
});
17751774

17761775
let span_lo = |item: &StructLitField<'_>| match *item {
17771776
StructLitField::Regular(field) => field.span().lo(),

src/imports.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,10 @@ fn rewrite_nested_use_tree(
10341034
}
10351035
}
10361036
let has_nested_list = use_tree_list.iter().any(|use_segment| {
1037-
use_segment.path.last().is_some_and(|last_segment| {
1038-
matches!(last_segment.kind, UseSegmentKind::List(..))
1039-
})
1037+
use_segment
1038+
.path
1039+
.last()
1040+
.is_some_and(|last_segment| matches!(last_segment.kind, UseSegmentKind::List(..)))
10401041
});
10411042

10421043
let remaining_width = if has_nested_list {

src/items.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ fn same_line_else_kw_and_brace(
235235
.lines()
236236
.last()
237237
.expect("initializer expression is multi-lined")
238-
.strip_prefix(indent.as_ref()).is_some_and(|l| !l.starts_with(char::is_whitespace))
238+
.strip_prefix(indent.as_ref())
239+
.is_some_and(|l| !l.starts_with(char::is_whitespace))
239240
}
240241

241242
fn allow_single_line_let_else_block(result: &str, block: &ast::Block) -> bool {
@@ -767,7 +768,8 @@ impl FmtVisitor<'_> {
767768
// Make sure that there are at least a single empty line between
768769
// different impl items.
769770
if prev_kind
770-
.as_ref().is_some_and(|prev_kind| need_empty_line(prev_kind, &item.kind))
771+
.as_ref()
772+
.is_some_and(|prev_kind| need_empty_line(prev_kind, &item.kind))
771773
{
772774
self.push_str("\n");
773775
}
@@ -2483,7 +2485,8 @@ fn rewrite_fn_base(
24832485

24842486
let snuggle_angle_bracket = generics_str
24852487
.lines()
2486-
.last().is_some_and(|l| l.trim_start().len() == 1);
2488+
.last()
2489+
.is_some_and(|l| l.trim_start().len() == 1);
24872490

24882491
// Note that the width and indent don't really matter, we'll re-layout the
24892492
// return type later anyway.
@@ -2568,7 +2571,8 @@ fn rewrite_fn_base(
25682571
// on the same line.
25692572
params_last_line_contains_comment = param_str
25702573
.lines()
2571-
.last().is_some_and(|last_line| last_line.contains("//"));
2574+
.last()
2575+
.is_some_and(|last_line| last_line.contains("//"));
25722576

25732577
if context.config.style_edition() >= StyleEdition::Edition2027 {
25742578
if closing_paren_overflow_max_width {
@@ -2676,9 +2680,11 @@ fn rewrite_fn_base(
26762680
let snippet = context.snippet(mk_sp(snippet_lo, snippet_hi));
26772681
// Try to preserve the layout of the original snippet.
26782682
let original_starts_with_newline = snippet
2679-
.find(|c| c != ' ').is_some_and(|i| starts_with_newline(&snippet[i..]));
2683+
.find(|c| c != ' ')
2684+
.is_some_and(|i| starts_with_newline(&snippet[i..]));
26802685
let original_ends_with_newline = snippet
2681-
.rfind(|c| c != ' ').is_some_and(|i| snippet[i..].ends_with('\n'));
2686+
.rfind(|c| c != ' ')
2687+
.is_some_and(|i| snippet[i..].ends_with('\n'));
26822688
let snippet = snippet.trim();
26832689
if !snippet.is_empty() {
26842690
result.push(if original_starts_with_newline {
@@ -3381,7 +3387,8 @@ fn format_generics(
33813387
};
33823388
// add missing comments
33833389
let missed_line_comments = missed_comments
3384-
.filter(|missed_comments| !missed_comments.is_empty()).is_some_and(|missed_comments| {
3390+
.filter(|missed_comments| !missed_comments.is_empty())
3391+
.is_some_and(|missed_comments| {
33853392
let is_block = is_last_comment_block(&missed_comments);
33863393
let sep = if is_block { " " } else { "\n" };
33873394
result.push_str(sep);

src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,7 @@ impl<'b, T: Write + 'b> Session<'b, T> {
517517

518518
pub(crate) fn create_emitter<'a>(config: &Config) -> Box<dyn Emitter + 'a> {
519519
match config.emit_mode() {
520-
EmitMode::Files if config.make_backup() => {
521-
Box::new(emitter::FilesWithBackupEmitter)
522-
}
520+
EmitMode::Files if config.make_backup() => Box::new(emitter::FilesWithBackupEmitter),
523521
EmitMode::Files => Box::new(emitter::FilesEmitter::new(
524522
config.print_misformatted_file_names(),
525523
)),

src/lists.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -149,27 +149,23 @@ impl ListItem {
149149
pub(crate) fn is_different_group(&self) -> bool {
150150
self.inner_as_ref().contains('\n')
151151
|| self.pre_comment.is_some()
152-
|| self
153-
.post_comment
154-
.as_ref().is_some_and(|s| s.contains('\n'))
152+
|| self.post_comment.as_ref().is_some_and(|s| s.contains('\n'))
155153
}
156154

157155
pub(crate) fn is_multiline(&self) -> bool {
158156
self.inner_as_ref().contains('\n')
159-
|| self
160-
.pre_comment
161-
.as_ref().is_some_and(|s| s.contains('\n'))
162-
|| self
163-
.post_comment
164-
.as_ref().is_some_and(|s| s.contains('\n'))
157+
|| self.pre_comment.as_ref().is_some_and(|s| s.contains('\n'))
158+
|| self.post_comment.as_ref().is_some_and(|s| s.contains('\n'))
165159
}
166160

167161
pub(crate) fn has_single_line_comment(&self) -> bool {
168162
self.pre_comment
169-
.as_ref().is_some_and(|comment| comment.trim_start().starts_with("//"))
163+
.as_ref()
164+
.is_some_and(|comment| comment.trim_start().starts_with("//"))
170165
|| self
171166
.post_comment
172-
.as_ref().is_some_and(|comment| comment.trim_start().starts_with("//"))
167+
.as_ref()
168+
.is_some_and(|comment| comment.trim_start().starts_with("//"))
173169
}
174170

175171
pub(crate) fn has_comment(&self) -> bool {
@@ -720,9 +716,7 @@ pub(crate) fn has_extra_newline(post_snippet: &str, comment_end: usize) -> bool
720716
.len_utf8();
721717
// Everything from the separator to the next item.
722718
let test_snippet = &post_snippet[comment_end - len_last..];
723-
let first_newline = test_snippet
724-
.find('\n')
725-
.unwrap_or(test_snippet.len());
719+
let first_newline = test_snippet.find('\n').unwrap_or(test_snippet.len());
726720
// From the end of the first line of comments.
727721
let test_snippet = &test_snippet[first_newline..];
728722
let first = test_snippet

src/matches.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ fn flatten_arm_body<'a>(
370370
}
371371
} else {
372372
let cond_becomes_multi_line = opt_shape
373-
.and_then(|shape| rewrite_cond(context, expr, shape)).is_some_and(|cond| cond.contains('\n'));
373+
.and_then(|shape| rewrite_cond(context, expr, shape))
374+
.is_some_and(|cond| cond.contains('\n'));
374375
if cond_becomes_multi_line {
375376
(false, body)
376377
} else {

src/overflow.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,8 @@ impl<'a> Context<'a> {
445445
| ast::ExprKind::Loop(..)
446446
| ast::ExprKind::While(..)
447447
| ast::ExprKind::Match(..) => {
448-
let multi_line = rewrite_cond(self.context, expr, shape).is_some_and(|cond| cond.contains('\n'));
448+
let multi_line = rewrite_cond(self.context, expr, shape)
449+
.is_some_and(|cond| cond.contains('\n'));
449450

450451
if multi_line {
451452
None
@@ -738,13 +739,15 @@ impl<'a> Context<'a> {
738739

739740
fn need_block_indent(s: &str, shape: Shape) -> bool {
740741
s.lines().skip(1).any(|s| {
741-
s.find(|c| !char::is_whitespace(c)).is_some_and(|w| w + 1 < shape.indent.width())
742+
s.find(|c| !char::is_whitespace(c))
743+
.is_some_and(|w| w + 1 < shape.indent.width())
742744
})
743745
}
744746

745747
fn can_be_overflowed(context: &RewriteContext<'_>, items: &[OverflowableItem<'_>]) -> bool {
746748
items
747-
.last().is_some_and(|x| x.can_be_overflowed(context, items.len()))
749+
.last()
750+
.is_some_and(|x| x.can_be_overflowed(context, items.len()))
748751
}
749752

750753
/// Returns a shape for the last argument which is going to be overflowed.
@@ -804,7 +807,8 @@ pub(crate) fn maybe_get_args_offset(
804807
args: &[OverflowableItem<'_>],
805808
config: &Config,
806809
) -> Option<(bool, usize)> {
807-
if let Some(&(_, num_args_before)) = args.first()?
810+
if let Some(&(_, num_args_before)) = args
811+
.first()?
808812
.special_cases(config)
809813
.find(|&&(s, _)| s == callee_str)
810814
{

src/reorder.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ fn rewrite_reorderable_or_regroupable_items(
148148
.map(|use_tree| {
149149
let item = use_tree.rewrite_top_level(context, nested_shape);
150150
if let Some(list_item) = use_tree.list_item {
151-
ListItem {
152-
item,
153-
..list_item
154-
}
151+
ListItem { item, ..list_item }
155152
} else {
156153
ListItem::from_item(item)
157154
}

src/rewrite.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ impl<T> RewriteErrorExt<T> for Option<T> {
9393
}
9494

9595
fn macro_error(self, kind: MacroErrorKind, span: Span) -> Result<T, RewriteError> {
96-
self.ok_or(RewriteError::MacroFailure {
97-
kind,
98-
span,
99-
})
96+
self.ok_or(RewriteError::MacroFailure { kind, span })
10097
}
10198

10299
fn unknown_error(self) -> Result<T, RewriteError> {

src/sort.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ impl<'a> VersionChunkIter<'a> {
5050
})
5151
}
5252

53-
fn parse_str_chunk(
54-
&mut self,
55-
chars: std::str::CharIndices<'a>,
56-
) -> Option<VersionChunk<'a>> {
53+
fn parse_str_chunk(&mut self, chars: std::str::CharIndices<'a>) -> Option<VersionChunk<'a>> {
5754
let mut end = self.start;
5855
let mut is_end_of_chunk = false;
5956

src/test/mod.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ fn is_file_skip(path: &Path) -> bool {
105105
fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
106106
let mut files = vec![];
107107
if path.is_dir() {
108-
for entry in
109-
fs::read_dir(path).unwrap_or_else(|_| panic!("couldn't read directory {}", path.display()))
108+
for entry in fs::read_dir(path)
109+
.unwrap_or_else(|_| panic!("couldn't read directory {}", path.display()))
110110
{
111111
let entry = entry.expect("couldn't get `DirEntry`");
112112
let path = entry.path();
@@ -121,7 +121,9 @@ fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
121121
}
122122

123123
fn verify_config_used(path: &Path, config_name: &str) {
124-
for entry in fs::read_dir(path).unwrap_or_else(|_| panic!("couldn't read {} directory", path.display())) {
124+
for entry in
125+
fs::read_dir(path).unwrap_or_else(|_| panic!("couldn't read {} directory", path.display()))
126+
{
125127
let entry = entry.expect("couldn't get directory entry");
126128
let path = entry.path();
127129
if path.extension().is_some_and(|f| f == "rs") {
@@ -762,15 +764,16 @@ fn get_editions_from_comments(
762764
comments: &HashMap<String, String>,
763765
) -> (Option<Edition>, Option<StyleEdition>, Option<Version>) {
764766
(
765-
comments
766-
.get("edition")
767-
.map(|e| Edition::from_str(e).unwrap_or_else(|_| panic!("invalid edition value: '{}'", e))),
767+
comments.get("edition").map(|e| {
768+
Edition::from_str(e).unwrap_or_else(|_| panic!("invalid edition value: '{}'", e))
769+
}),
768770
comments.get("style_edition").map(|se| {
769-
StyleEdition::from_str(se).unwrap_or_else(|_| panic!("invalid style_edition value: '{}'", se))
771+
StyleEdition::from_str(se)
772+
.unwrap_or_else(|_| panic!("invalid style_edition value: '{}'", se))
773+
}),
774+
comments.get("version").map(|v| {
775+
Version::from_str(v).unwrap_or_else(|_| panic!("invalid version value: '{}'", v))
770776
}),
771-
comments
772-
.get("version")
773-
.map(|v| Version::from_str(v).unwrap_or_else(|_| panic!("invalid version value: '{}'", v))),
774777
)
775778
}
776779

src/utils.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,7 @@ fn is_skip_nested(meta_item: &MetaItemInner) -> bool {
266266

267267
#[inline]
268268
pub(crate) fn contains_skip(attrs: &[Attribute]) -> bool {
269-
attrs
270-
.iter()
271-
.any(|a| a.meta().is_some_and(|a| is_skip(&a)))
269+
attrs.iter().any(|a| a.meta().is_some_and(|a| is_skip(&a)))
272270
}
273271

274272
#[inline]

src/visitor.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
120120
// snippet preceding the semicolon is picked up.
121121
let snippet = self.snippet(mk_sp(self.last_pos, stmt.span().lo()));
122122
let original_starts_with_newline = snippet
123-
.find(|c| c != ' ').is_some_and(|i| starts_with_newline(&snippet[i..]));
123+
.find(|c| c != ' ')
124+
.is_some_and(|i| starts_with_newline(&snippet[i..]));
124125
let snippet = snippet.trim();
125126
if !snippet.is_empty() {
126127
// FIXME(calebcartwright 2021-01-03) - This exists strictly to maintain legacy

0 commit comments

Comments
 (0)