Skip to content

Commit e50afa4

Browse files
committed
Auto merge of #6822 - camsteffen:rustfmt, r=llogiq
Rustfmt version "Two" changelog: none This enables some ~bug fixes~ changes from rustfmt. This is more consistent with rustc's config, and should be more forward-compatible. Also, the changes look good IMO. 😃
2 parents 5ae1e17 + ada8c72 commit e50afa4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+225
-503
lines changed

clippy_lints/src/await_holding_invalid.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType
123123
}
124124
if is_refcell_ref(cx, adt.did) {
125125
span_lint_and_note(
126-
cx,
127-
AWAIT_HOLDING_REFCELL_REF,
128-
ty_cause.span,
129-
"this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await",
130-
ty_cause.scope_span.or(Some(span)),
131-
"these are all the await points this ref is held through",
132-
);
126+
cx,
127+
AWAIT_HOLDING_REFCELL_REF,
128+
ty_cause.span,
129+
"this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await",
130+
ty_cause.scope_span.or(Some(span)),
131+
"these are all the await points this ref is held through",
132+
);
133133
}
134134
}
135135
}

clippy_lints/src/float_literal.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ fn count_digits(s: &str) -> usize {
145145
.take_while(|c| *c != 'e' && *c != 'E')
146146
.fold(0, |count, c| {
147147
// leading zeros
148-
if c == '0' && count == 0 {
149-
count
150-
} else {
151-
count + 1
152-
}
148+
if c == '0' && count == 0 { count } else { count + 1 }
153149
})
154150
}
155151

clippy_lints/src/infinite_iter.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ impl Finiteness {
8989
impl From<bool> for Finiteness {
9090
#[must_use]
9191
fn from(b: bool) -> Self {
92-
if b {
93-
Infinite
94-
} else {
95-
Finite
96-
}
92+
if b { Infinite } else { Finite }
9793
}
9894
}
9995

clippy_lints/src/inherent_to_string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) {
139139
self_type.to_string()
140140
),
141141
None,
142-
&format!("remove the inherent method from type `{}`", self_type.to_string())
142+
&format!("remove the inherent method from type `{}`", self_type.to_string()),
143143
);
144144
} else {
145145
span_lint_and_help(

clippy_lints/src/loops.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -3158,11 +3158,7 @@ fn detect_iter_and_into_iters<'tcx>(block: &'tcx Block<'tcx>, identifier: Ident)
31583158
seen_other: false,
31593159
};
31603160
visitor.visit_block(block);
3161-
if visitor.seen_other {
3162-
None
3163-
} else {
3164-
Some(visitor.uses)
3165-
}
3161+
if visitor.seen_other { None } else { Some(visitor.uses) }
31663162
}
31673163

31683164
fn shorten_needless_collect_span(expr: &Expr<'_>) -> Span {

clippy_lints/src/mutable_debug_assertion.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> {
7373
}
7474

7575
fn expr_span(&self) -> Option<Span> {
76-
if self.found {
77-
self.expr_span
78-
} else {
79-
None
80-
}
76+
if self.found { self.expr_span } else { None }
8177
}
8278
}
8379

clippy_lints/src/needless_continue.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,7 @@ fn erode_from_back(s: &str) -> String {
416416
break;
417417
}
418418
}
419-
if ret.is_empty() {
420-
s.to_string()
421-
} else {
422-
ret
423-
}
419+
if ret.is_empty() { s.to_string() } else { ret }
424420
}
425421

426422
fn span_of_first_expr_in_block(block: &ast::Block) -> Option<Span> {

clippy_lints/src/open_options.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,11 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec
6969
..
7070
} = *span
7171
{
72-
if lit {
73-
Argument::True
74-
} else {
75-
Argument::False
76-
}
72+
if lit { Argument::True } else { Argument::False }
7773
} else {
78-
return; // The function is called with a literal
79-
// which is not a boolean literal. This is theoretically
80-
// possible, but not very likely.
74+
// The function is called with a literal which is not a boolean literal.
75+
// This is theoretically possible, but not very likely.
76+
return;
8177
}
8278
},
8379
_ => Argument::Unknown,

clippy_utils/src/camel_case.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ pub fn until(s: &str) -> usize {
2525
return i;
2626
}
2727
}
28-
if up {
29-
last_i
30-
} else {
31-
s.len()
32-
}
28+
if up { last_i } else { s.len() }
3329
}
3430

3531
/// Returns index of the last camel-case component of `s`.

clippy_utils/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1563,12 +1563,12 @@ pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool {
15631563
/// ```
15641564
pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool {
15651565
use rustc_trait_selection::traits;
1566-
let predicates =
1567-
cx.tcx
1568-
.predicates_of(did)
1569-
.predicates
1570-
.iter()
1571-
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
1566+
let predicates = cx
1567+
.tcx
1568+
.predicates_of(did)
1569+
.predicates
1570+
.iter()
1571+
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
15721572
traits::impossible_predicates(
15731573
cx.tcx,
15741574
traits::elaborate_predicates(cx.tcx, predicates)

clippy_utils/src/ptr.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ fn extract_clone_suggestions<'tcx>(
3636
abort: false,
3737
};
3838
visitor.visit_body(body);
39-
if visitor.abort {
40-
None
41-
} else {
42-
Some(visitor.spans)
43-
}
39+
if visitor.abort { None } else { Some(visitor.spans) }
4440
}
4541

4642
struct PtrCloneVisitor<'a, 'tcx> {

rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ match_block_trailing_comma = true
44
wrap_comments = true
55
edition = "2018"
66
error_on_line_overflow = true
7+
version = "Two"

tests/lint_message_convention.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ fn lint_message_convention() {
9898
eprintln!("\n\n");
9999
});
100100

101-
eprintln!("\n\n\nLint message should not start with a capital letter and should not have punctuation at the end of the message unless multiple sentences are needed.");
101+
eprintln!(
102+
"\n\n\nLint message should not start with a capital letter and should not have punctuation at the end of the message unless multiple sentences are needed."
103+
);
102104
eprintln!("Check out the rustc-dev-guide for more information:");
103105
eprintln!("https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure\n\n\n");
104106

tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ enum Flags {
1616
FIN,
1717
}
1818

19-
struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
20-
// `GccLlvmSomething`
19+
// linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
20+
// `GccLlvmSomething`
21+
struct GCCLLVMSomething;
2122

2223
fn main() {}

tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ LL | FIN,
6161
| ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin`
6262

6363
error: name `GCCLLVMSomething` contains a capitalized acronym
64-
--> $DIR/upper_case_acronyms.rs:19:8
64+
--> $DIR/upper_case_acronyms.rs:21:8
6565
|
66-
LL | struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
66+
LL | struct GCCLLVMSomething;
6767
| ^^^^^^^^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `GccllvmSomething`
6868

6969
error: aborting due to 11 previous errors

tests/ui/auxiliary/macro_rules.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ macro_rules! try_err {
2323
pub fn try_err_fn() -> Result<i32, i32> {
2424
let err: i32 = 1;
2525
// To avoid warnings during rustfix
26-
if true {
27-
Err(err)?
28-
} else {
29-
Ok(2)
30-
}
26+
if true { Err(err)? } else { Ok(2) }
3127
}
3228
};
3329
}

tests/ui/blocks_in_if_conditions.fixed

+12-21
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
#![warn(clippy::nonminimal_bool)]
55

66
macro_rules! blocky {
7-
() => {{
8-
true
9-
}};
7+
() => {{ true }};
108
}
119

1210
macro_rules! blocky_too {
@@ -34,20 +32,12 @@ fn condition_has_block() -> i32 {
3432
}
3533

3634
fn condition_has_block_with_single_expression() -> i32 {
37-
if true {
38-
6
39-
} else {
40-
10
41-
}
35+
if true { 6 } else { 10 }
4236
}
4337

4438
fn condition_is_normal() -> i32 {
4539
let x = 3;
46-
if x == 3 {
47-
6
48-
} else {
49-
10
50-
}
40+
if x == 3 { 6 } else { 10 }
5141
}
5242

5343
fn condition_is_unsafe_block() {
@@ -61,14 +51,15 @@ fn condition_is_unsafe_block() {
6151

6252
fn block_in_assert() {
6353
let opt = Some(42);
64-
assert!(opt
65-
.as_ref()
66-
.map(|val| {
67-
let mut v = val * 2;
68-
v -= 1;
69-
v * 3
70-
})
71-
.is_some());
54+
assert!(
55+
opt.as_ref()
56+
.map(|val| {
57+
let mut v = val * 2;
58+
v -= 1;
59+
v * 3
60+
})
61+
.is_some()
62+
);
7263
}
7364

7465
fn main() {}

tests/ui/blocks_in_if_conditions.rs

+12-21
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
#![warn(clippy::nonminimal_bool)]
55

66
macro_rules! blocky {
7-
() => {{
8-
true
9-
}};
7+
() => {{ true }};
108
}
119

1210
macro_rules! blocky_too {
@@ -34,20 +32,12 @@ fn condition_has_block() -> i32 {
3432
}
3533

3634
fn condition_has_block_with_single_expression() -> i32 {
37-
if { true } {
38-
6
39-
} else {
40-
10
41-
}
35+
if { true } { 6 } else { 10 }
4236
}
4337

4438
fn condition_is_normal() -> i32 {
4539
let x = 3;
46-
if true && x == 3 {
47-
6
48-
} else {
49-
10
50-
}
40+
if true && x == 3 { 6 } else { 10 }
5141
}
5242

5343
fn condition_is_unsafe_block() {
@@ -61,14 +51,15 @@ fn condition_is_unsafe_block() {
6151

6252
fn block_in_assert() {
6353
let opt = Some(42);
64-
assert!(opt
65-
.as_ref()
66-
.map(|val| {
67-
let mut v = val * 2;
68-
v -= 1;
69-
v * 3
70-
})
71-
.is_some());
54+
assert!(
55+
opt.as_ref()
56+
.map(|val| {
57+
let mut v = val * 2;
58+
v -= 1;
59+
v * 3
60+
})
61+
.is_some()
62+
);
7263
}
7364

7465
fn main() {}

tests/ui/blocks_in_if_conditions.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
2-
--> $DIR/blocks_in_if_conditions.rs:26:5
2+
--> $DIR/blocks_in_if_conditions.rs:24:5
33
|
44
LL | / if {
55
LL | | let x = 3;
@@ -17,15 +17,15 @@ LL | }; if res {
1717
|
1818

1919
error: omit braces around single expression condition
20-
--> $DIR/blocks_in_if_conditions.rs:37:8
20+
--> $DIR/blocks_in_if_conditions.rs:35:8
2121
|
22-
LL | if { true } {
22+
LL | if { true } { 6 } else { 10 }
2323
| ^^^^^^^^ help: try: `true`
2424

2525
error: this boolean expression can be simplified
26-
--> $DIR/blocks_in_if_conditions.rs:46:8
26+
--> $DIR/blocks_in_if_conditions.rs:40:8
2727
|
28-
LL | if true && x == 3 {
28+
LL | if true && x == 3 { 6 } else { 10 }
2929
| ^^^^^^^^^^^^^^ help: try: `x == 3`
3030
|
3131
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`

tests/ui/checked_unwrap/simple_conditionals.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,16 @@ fn main() {
6666
}
6767
if x.is_ok() {
6868
x = Err(());
69-
x.unwrap(); // not unnecessary because of mutation of x
70-
// it will always panic but the lint is not smart enough to see this (it only
71-
// checks if conditions).
69+
// not unnecessary because of mutation of x
70+
// it will always panic but the lint is not smart enough to see this (it only
71+
// checks if conditions).
72+
x.unwrap();
7273
} else {
7374
x = Ok(());
74-
x.unwrap_err(); // not unnecessary because of mutation of x
75-
// it will always panic but the lint is not smart enough to see this (it
76-
// only checks if conditions).
75+
// not unnecessary because of mutation of x
76+
// it will always panic but the lint is not smart enough to see this (it
77+
// only checks if conditions).
78+
x.unwrap_err();
7779
}
7880

7981
assert!(x.is_ok(), "{:?}", x.unwrap_err()); // ok, it's a common test pattern

tests/ui/crashes/ice-6256.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ impl dyn TT {
88
fn func(&self) {}
99
}
1010

11+
#[rustfmt::skip]
1112
fn main() {
1213
let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
1314
//[nll]~^ ERROR: borrowed data escapes outside of closure

0 commit comments

Comments
 (0)