Skip to content

Commit

Permalink
Add version = "Two" to rustfmt.toml
Browse files Browse the repository at this point in the history
Ignore UI tests since this change makes rustfmt less friendly with UI
test comments.
  • Loading branch information
camsteffen committed Mar 1, 2021
1 parent 5ae1e17 commit ada8c72
Show file tree
Hide file tree
Showing 52 changed files with 225 additions and 503 deletions.
14 changes: 7 additions & 7 deletions clippy_lints/src/await_holding_invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType
}
if is_refcell_ref(cx, adt.did) {
span_lint_and_note(
cx,
AWAIT_HOLDING_REFCELL_REF,
ty_cause.span,
"this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await",
ty_cause.scope_span.or(Some(span)),
"these are all the await points this ref is held through",
);
cx,
AWAIT_HOLDING_REFCELL_REF,
ty_cause.span,
"this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await",
ty_cause.scope_span.or(Some(span)),
"these are all the await points this ref is held through",
);
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions clippy_lints/src/float_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@ fn count_digits(s: &str) -> usize {
.take_while(|c| *c != 'e' && *c != 'E')
.fold(0, |count, c| {
// leading zeros
if c == '0' && count == 0 {
count
} else {
count + 1
}
if c == '0' && count == 0 { count } else { count + 1 }
})
}

Expand Down
6 changes: 1 addition & 5 deletions clippy_lints/src/infinite_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ impl Finiteness {
impl From<bool> for Finiteness {
#[must_use]
fn from(b: bool) -> Self {
if b {
Infinite
} else {
Finite
}
if b { Infinite } else { Finite }
}
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/inherent_to_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) {
self_type.to_string()
),
None,
&format!("remove the inherent method from type `{}`", self_type.to_string())
&format!("remove the inherent method from type `{}`", self_type.to_string()),
);
} else {
span_lint_and_help(
Expand Down
6 changes: 1 addition & 5 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3158,11 +3158,7 @@ fn detect_iter_and_into_iters<'tcx>(block: &'tcx Block<'tcx>, identifier: Ident)
seen_other: false,
};
visitor.visit_block(block);
if visitor.seen_other {
None
} else {
Some(visitor.uses)
}
if visitor.seen_other { None } else { Some(visitor.uses) }
}

fn shorten_needless_collect_span(expr: &Expr<'_>) -> Span {
Expand Down
6 changes: 1 addition & 5 deletions clippy_lints/src/mutable_debug_assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> {
}

fn expr_span(&self) -> Option<Span> {
if self.found {
self.expr_span
} else {
None
}
if self.found { self.expr_span } else { None }
}
}

Expand Down
6 changes: 1 addition & 5 deletions clippy_lints/src/needless_continue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,7 @@ fn erode_from_back(s: &str) -> String {
break;
}
}
if ret.is_empty() {
s.to_string()
} else {
ret
}
if ret.is_empty() { s.to_string() } else { ret }
}

fn span_of_first_expr_in_block(block: &ast::Block) -> Option<Span> {
Expand Down
12 changes: 4 additions & 8 deletions clippy_lints/src/open_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,11 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec
..
} = *span
{
if lit {
Argument::True
} else {
Argument::False
}
if lit { Argument::True } else { Argument::False }
} else {
return; // The function is called with a literal
// which is not a boolean literal. This is theoretically
// possible, but not very likely.
// The function is called with a literal which is not a boolean literal.
// This is theoretically possible, but not very likely.
return;
}
},
_ => Argument::Unknown,
Expand Down
6 changes: 1 addition & 5 deletions clippy_utils/src/camel_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ pub fn until(s: &str) -> usize {
return i;
}
}
if up {
last_i
} else {
s.len()
}
if up { last_i } else { s.len() }
}

/// Returns index of the last camel-case component of `s`.
Expand Down
12 changes: 6 additions & 6 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,12 +1563,12 @@ pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool {
/// ```
pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool {
use rustc_trait_selection::traits;
let predicates =
cx.tcx
.predicates_of(did)
.predicates
.iter()
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
let predicates = cx
.tcx
.predicates_of(did)
.predicates
.iter()
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
traits::impossible_predicates(
cx.tcx,
traits::elaborate_predicates(cx.tcx, predicates)
Expand Down
6 changes: 1 addition & 5 deletions clippy_utils/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ fn extract_clone_suggestions<'tcx>(
abort: false,
};
visitor.visit_body(body);
if visitor.abort {
None
} else {
Some(visitor.spans)
}
if visitor.abort { None } else { Some(visitor.spans) }
}

struct PtrCloneVisitor<'a, 'tcx> {
Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ match_block_trailing_comma = true
wrap_comments = true
edition = "2018"
error_on_line_overflow = true
version = "Two"
4 changes: 3 additions & 1 deletion tests/lint_message_convention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ fn lint_message_convention() {
eprintln!("\n\n");
});

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.");
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."
);
eprintln!("Check out the rustc-dev-guide for more information:");
eprintln!("https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure\n\n\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ enum Flags {
FIN,
}

struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
// `GccLlvmSomething`
// linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
// `GccLlvmSomething`
struct GCCLLVMSomething;

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ LL | FIN,
| ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin`

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

error: aborting due to 11 previous errors
Expand Down
6 changes: 1 addition & 5 deletions tests/ui/auxiliary/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ macro_rules! try_err {
pub fn try_err_fn() -> Result<i32, i32> {
let err: i32 = 1;
// To avoid warnings during rustfix
if true {
Err(err)?
} else {
Ok(2)
}
if true { Err(err)? } else { Ok(2) }
}
};
}
Expand Down
33 changes: 12 additions & 21 deletions tests/ui/blocks_in_if_conditions.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
#![warn(clippy::nonminimal_bool)]

macro_rules! blocky {
() => {{
true
}};
() => {{ true }};
}

macro_rules! blocky_too {
Expand Down Expand Up @@ -34,20 +32,12 @@ fn condition_has_block() -> i32 {
}

fn condition_has_block_with_single_expression() -> i32 {
if true {
6
} else {
10
}
if true { 6 } else { 10 }
}

fn condition_is_normal() -> i32 {
let x = 3;
if x == 3 {
6
} else {
10
}
if x == 3 { 6 } else { 10 }
}

fn condition_is_unsafe_block() {
Expand All @@ -61,14 +51,15 @@ fn condition_is_unsafe_block() {

fn block_in_assert() {
let opt = Some(42);
assert!(opt
.as_ref()
.map(|val| {
let mut v = val * 2;
v -= 1;
v * 3
})
.is_some());
assert!(
opt.as_ref()
.map(|val| {
let mut v = val * 2;
v -= 1;
v * 3
})
.is_some()
);
}

fn main() {}
33 changes: 12 additions & 21 deletions tests/ui/blocks_in_if_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
#![warn(clippy::nonminimal_bool)]

macro_rules! blocky {
() => {{
true
}};
() => {{ true }};
}

macro_rules! blocky_too {
Expand Down Expand Up @@ -34,20 +32,12 @@ fn condition_has_block() -> i32 {
}

fn condition_has_block_with_single_expression() -> i32 {
if { true } {
6
} else {
10
}
if { true } { 6 } else { 10 }
}

fn condition_is_normal() -> i32 {
let x = 3;
if true && x == 3 {
6
} else {
10
}
if true && x == 3 { 6 } else { 10 }
}

fn condition_is_unsafe_block() {
Expand All @@ -61,14 +51,15 @@ fn condition_is_unsafe_block() {

fn block_in_assert() {
let opt = Some(42);
assert!(opt
.as_ref()
.map(|val| {
let mut v = val * 2;
v -= 1;
v * 3
})
.is_some());
assert!(
opt.as_ref()
.map(|val| {
let mut v = val * 2;
v -= 1;
v * 3
})
.is_some()
);
}

fn main() {}
10 changes: 5 additions & 5 deletions tests/ui/blocks_in_if_conditions.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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`
--> $DIR/blocks_in_if_conditions.rs:26:5
--> $DIR/blocks_in_if_conditions.rs:24:5
|
LL | / if {
LL | | let x = 3;
Expand All @@ -17,15 +17,15 @@ LL | }; if res {
|

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

error: this boolean expression can be simplified
--> $DIR/blocks_in_if_conditions.rs:46:8
--> $DIR/blocks_in_if_conditions.rs:40:8
|
LL | if true && x == 3 {
LL | if true && x == 3 { 6 } else { 10 }
| ^^^^^^^^^^^^^^ help: try: `x == 3`
|
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
Expand Down
14 changes: 8 additions & 6 deletions tests/ui/checked_unwrap/simple_conditionals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ fn main() {
}
if x.is_ok() {
x = Err(());
x.unwrap(); // not unnecessary because of mutation of x
// it will always panic but the lint is not smart enough to see this (it only
// checks if conditions).
// not unnecessary because of mutation of x
// it will always panic but the lint is not smart enough to see this (it only
// checks if conditions).
x.unwrap();
} else {
x = Ok(());
x.unwrap_err(); // not unnecessary because of mutation of x
// it will always panic but the lint is not smart enough to see this (it
// only checks if conditions).
// not unnecessary because of mutation of x
// it will always panic but the lint is not smart enough to see this (it
// only checks if conditions).
x.unwrap_err();
}

assert!(x.is_ok(), "{:?}", x.unwrap_err()); // ok, it's a common test pattern
Expand Down
1 change: 1 addition & 0 deletions tests/ui/crashes/ice-6256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ impl dyn TT {
fn func(&self) {}
}

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

0 comments on commit ada8c72

Please sign in to comment.