diff --git a/tests/auxiliary/test_macro.rs b/tests/auxiliary/test_macro.rs index 497fedff15e..d5fef588971 100644 --- a/tests/auxiliary/test_macro.rs +++ b/tests/auxiliary/test_macro.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - pub trait A {} macro_rules! __implicit_hasher_test_macro { diff --git a/tests/run-pass/associated-constant-ice.rs b/tests/run-pass/associated-constant-ice.rs index bc9a0b3b6d5..df84009c889 100644 --- a/tests/run-pass/associated-constant-ice.rs +++ b/tests/run-pass/associated-constant-ice.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - pub trait Trait { const CONSTANT: u8; } diff --git a/tests/run-pass/cc_seme.rs b/tests/run-pass/cc_seme.rs index 215b4096b56..7e1f13d4460 100644 --- a/tests/run-pass/cc_seme.rs +++ b/tests/run-pass/cc_seme.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #[allow(dead_code)] enum Baz { One, @@ -19,7 +18,7 @@ struct Test { b: Baz, } -fn main() { } +fn main() {} pub fn foo() { use Baz::*; @@ -27,10 +26,7 @@ pub fn foo() { match x { Test { t: Some(_), b: One } => unreachable!(), - Test { - t: Some(42), - b: Two, - } => unreachable!(), + Test { t: Some(42), b: Two } => unreachable!(), Test { t: None, .. } => unreachable!(), Test { .. } => unreachable!(), } diff --git a/tests/run-pass/enum-glob-import-crate.rs b/tests/run-pass/enum-glob-import-crate.rs index df8b32cde2b..6e64f174e4c 100644 --- a/tests/run-pass/enum-glob-import-crate.rs +++ b/tests/run-pass/enum-glob-import-crate.rs @@ -7,12 +7,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::all)] #![allow(unused_imports)] use std::*; -fn main() { } +fn main() {} diff --git a/tests/run-pass/ice-1588.rs b/tests/run-pass/ice-1588.rs index a54c77cce73..87f2afaa602 100644 --- a/tests/run-pass/ice-1588.rs +++ b/tests/run-pass/ice-1588.rs @@ -7,17 +7,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(clippy::all)] fn main() { match 1 { - 1 => {} + 1 => {}, 2 => { [0; 1]; - } - _ => {} + }, + _ => {}, } } diff --git a/tests/run-pass/ice-1782.rs b/tests/run-pass/ice-1782.rs index 446aaacb2ee..ddb4367c914 100644 --- a/tests/run-pass/ice-1782.rs +++ b/tests/run-pass/ice-1782.rs @@ -7,20 +7,28 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![allow(dead_code, unused_variables)] /// Should not trigger an ICE in `SpanlessEq` / `consts::constant` /// /// Issue: https://github.com/rust-lang/rust-clippy/issues/1782 - use std::{mem, ptr}; fn spanless_eq_ice() { let txt = "something"; match txt { - "something" => unsafe { ptr::write(ptr::null_mut() as *mut u32, mem::transmute::<[u8; 4], _>([0, 0, 0, 255])) }, - _ => unsafe { ptr::write(ptr::null_mut() as *mut u32, mem::transmute::<[u8; 4], _>([13, 246, 24, 255])) }, + "something" => unsafe { + ptr::write( + ptr::null_mut() as *mut u32, + mem::transmute::<[u8; 4], _>([0, 0, 0, 255]), + ) + }, + _ => unsafe { + ptr::write( + ptr::null_mut() as *mut u32, + mem::transmute::<[u8; 4], _>([13, 246, 24, 255]), + ) + }, } } diff --git a/tests/run-pass/ice-1969.rs b/tests/run-pass/ice-1969.rs index 848d9743dcd..2a0cdb19fce 100644 --- a/tests/run-pass/ice-1969.rs +++ b/tests/run-pass/ice-1969.rs @@ -7,12 +7,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(clippy::all)] -fn main() { } +fn main() {} pub trait Convert { type Action: From<*const f64>; diff --git a/tests/run-pass/ice-2499.rs b/tests/run-pass/ice-2499.rs index 30e8fa657f2..804f416800c 100644 --- a/tests/run-pass/ice-2499.rs +++ b/tests/run-pass/ice-2499.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(dead_code, clippy::char_lit_as_u8, clippy::needless_bool)] /// Should not trigger an ICE in `SpanlessHash` / `consts::constant` @@ -20,15 +17,17 @@ fn f(s: &[u8]) -> bool { let t = s[0] as char; match t { - 'E' | 'W' => {} - 'T' => if s[0..4] != ['0' as u8; 4] { - return false; - } else { - return true; + 'E' | 'W' => {}, + 'T' => { + if s[0..4] != ['0' as u8; 4] { + return false; + } else { + return true; + } }, _ => { return false; - } + }, } true } diff --git a/tests/run-pass/ice-2594.rs b/tests/run-pass/ice-2594.rs index 738636b5e40..e91b71b3a1c 100644 --- a/tests/run-pass/ice-2594.rs +++ b/tests/run-pass/ice-2594.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![allow(dead_code, unused_variables)] /// Should not trigger an ICE in `SpanlessHash` / `consts::constant` @@ -21,7 +20,7 @@ fn spanless_hash_ice() { match txt { "something" => { let mut headers = [empty_header; 1]; - } + }, "" => (), _ => (), } diff --git a/tests/run-pass/ice-2727.rs b/tests/run-pass/ice-2727.rs index 420be4c7112..9d00f2bacd0 100644 --- a/tests/run-pass/ice-2727.rs +++ b/tests/run-pass/ice-2727.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - pub fn f(new: fn()) { new(); } diff --git a/tests/run-pass/ice-2760.rs b/tests/run-pass/ice-2760.rs index fe7138b7f28..533cc3b952a 100644 --- a/tests/run-pass/ice-2760.rs +++ b/tests/run-pass/ice-2760.rs @@ -7,11 +7,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - -#![allow(unused_variables, clippy::blacklisted_name, - clippy::needless_pass_by_value, dead_code)] +#![allow( + unused_variables, + clippy::blacklisted_name, + clippy::needless_pass_by_value, + dead_code +)] // This should not compile-fail with: // diff --git a/tests/run-pass/ice-2774.rs b/tests/run-pass/ice-2774.rs index 9959ec46d24..ae51f036207 100644 --- a/tests/run-pass/ice-2774.rs +++ b/tests/run-pass/ice-2774.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - use std::collections::HashSet; // See https://github.com/rust-lang/rust-clippy/issues/2774 @@ -26,18 +23,14 @@ pub struct Foo {} // This should not cause a 'cannot relate bound region' ICE pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) { let mut foos = HashSet::new(); - foos.extend( - bars.iter().map(|b| &b.foo) - ); + foos.extend(bars.iter().map(|b| &b.foo)); } #[allow(clippy::implicit_hasher)] // Also this should not cause a 'cannot relate bound region' ICE pub fn add_barfoos_to_foos2(bars: &HashSet<&Bar>) { let mut foos = HashSet::new(); - foos.extend( - bars.iter().map(|b| &b.foo) - ); + foos.extend(bars.iter().map(|b| &b.foo)); } fn main() {} diff --git a/tests/run-pass/ice-2865.rs b/tests/run-pass/ice-2865.rs index 1713915745a..970ac5bd3a8 100644 --- a/tests/run-pass/ice-2865.rs +++ b/tests/run-pass/ice-2865.rs @@ -7,10 +7,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #[allow(dead_code)] struct Ice { - size: String + size: String, } impl<'a> From for Ice { diff --git a/tests/run-pass/ice-3151.rs b/tests/run-pass/ice-3151.rs index 8e1b7b9a178..7a26f4c3925 100644 --- a/tests/run-pass/ice-3151.rs +++ b/tests/run-pass/ice-3151.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #[derive(Clone)] pub struct HashMap { hash_builder: S, @@ -17,7 +16,7 @@ pub struct HashMap { #[derive(Clone)] pub struct RawTable { size: usize, - val: V + val: V, } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/tests/run-pass/ice-700.rs b/tests/run-pass/ice-700.rs index cb6ba21e72b..b839ac2a214 100644 --- a/tests/run-pass/ice-700.rs +++ b/tests/run-pass/ice-700.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::all)] fn core() {} diff --git a/tests/run-pass/ice_exacte_size.rs b/tests/run-pass/ice_exacte_size.rs index 74eda792e75..b2b331bd342 100644 --- a/tests/run-pass/ice_exacte_size.rs +++ b/tests/run-pass/ice_exacte_size.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::all)] #[allow(dead_code)] diff --git a/tests/run-pass/if_same_then_else.rs b/tests/run-pass/if_same_then_else.rs index cc95262fe3c..0241d2adcf7 100644 --- a/tests/run-pass/if_same_then_else.rs +++ b/tests/run-pass/if_same_then_else.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::if_same_then_else)] fn main() {} diff --git a/tests/run-pass/issue-2862.rs b/tests/run-pass/issue-2862.rs index 298ce088cea..a5342492045 100644 --- a/tests/run-pass/issue-2862.rs +++ b/tests/run-pass/issue-2862.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - pub trait FooMap { fn map B>(&self, f: F) -> B; } diff --git a/tests/run-pass/issue-825.rs b/tests/run-pass/issue-825.rs index 576d53757cf..9f1195a4ac0 100644 --- a/tests/run-pass/issue-825.rs +++ b/tests/run-pass/issue-825.rs @@ -7,14 +7,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![allow(warnings)] // this should compile in a reasonable amount of time fn rust_type_id(name: &str) { - if "bool" == &name[..] || "uint" == &name[..] || "u8" == &name[..] || "u16" == &name[..] || "u32" == &name[..] - || "f32" == &name[..] || "f64" == &name[..] || "i8" == &name[..] || "i16" == &name[..] - || "i32" == &name[..] || "i64" == &name[..] || "Self" == &name[..] || "str" == &name[..] + if "bool" == &name[..] + || "uint" == &name[..] + || "u8" == &name[..] + || "u16" == &name[..] + || "u32" == &name[..] + || "f32" == &name[..] + || "f64" == &name[..] + || "i8" == &name[..] + || "i16" == &name[..] + || "i32" == &name[..] + || "i64" == &name[..] + || "Self" == &name[..] + || "str" == &name[..] { unreachable!(); } diff --git a/tests/run-pass/issues_loop_mut_cond.rs b/tests/run-pass/issues_loop_mut_cond.rs index 893866a2a34..a81f8f55dc8 100644 --- a/tests/run-pass/issues_loop_mut_cond.rs +++ b/tests/run-pass/issues_loop_mut_cond.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![allow(dead_code)] /// Issue: https://github.com/rust-lang/rust-clippy/issues/2596 diff --git a/tests/run-pass/match_same_arms_const.rs b/tests/run-pass/match_same_arms_const.rs index bd180e9cad9..661f2ac1dc7 100644 --- a/tests/run-pass/match_same_arms_const.rs +++ b/tests/run-pass/match_same_arms_const.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::match_same_arms)] const PRICE_OF_SWEETS: u32 = 5; @@ -21,7 +18,7 @@ pub fn price(thing: &str) -> u32 { "rolo" => PRICE_OF_SWEETS, "advice" => PRICE_OF_KINDNESS, "juice" => PRICE_OF_DRINKS, - _ => panic!() + _ => panic!(), } } diff --git a/tests/run-pass/mut_mut_macro.rs b/tests/run-pass/mut_mut_macro.rs index 8859009479c..f1a2cad3ae7 100644 --- a/tests/run-pass/mut_mut_macro.rs +++ b/tests/run-pass/mut_mut_macro.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::mut_mut, clippy::zero_ptr, clippy::cmp_nan)] #![allow(dead_code)] diff --git a/tests/run-pass/needless_borrow_fp.rs b/tests/run-pass/needless_borrow_fp.rs index ad4b04864e4..81b77855711 100644 --- a/tests/run-pass/needless_borrow_fp.rs +++ b/tests/run-pass/needless_borrow_fp.rs @@ -7,16 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #[deny(clippy::all)] - #[derive(Debug)] pub enum Error { - Type( - &'static str, - ), + Type(&'static str), } fn main() {} diff --git a/tests/run-pass/needless_lifetimes_impl_trait.rs b/tests/run-pass/needless_lifetimes_impl_trait.rs index 0514d7ab008..9648f530c2a 100644 --- a/tests/run-pass/needless_lifetimes_impl_trait.rs +++ b/tests/run-pass/needless_lifetimes_impl_trait.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::needless_lifetimes)] #![allow(dead_code)] diff --git a/tests/run-pass/procedural_macro.rs b/tests/run-pass/procedural_macro.rs index a9c9dd06b42..9ac47599ea0 100644 --- a/tests/run-pass/procedural_macro.rs +++ b/tests/run-pass/procedural_macro.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #[macro_use] extern crate clippy_mini_macro_test; @@ -17,6 +16,5 @@ fn main() { println!("{:?}", x); } - #[derive(ClippyMiniMacroTest, Debug)] -struct Foo; \ No newline at end of file +struct Foo; diff --git a/tests/run-pass/regressions.rs b/tests/run-pass/regressions.rs index 9be3bab185c..b109eecf624 100644 --- a/tests/run-pass/regressions.rs +++ b/tests/run-pass/regressions.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(clippy::blacklisted_name)] pub fn foo(bar: *const u8) { diff --git a/tests/run-pass/returns.rs b/tests/run-pass/returns.rs index cc7678d603b..045cf001eb2 100644 --- a/tests/run-pass/returns.rs +++ b/tests/run-pass/returns.rs @@ -7,11 +7,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #[deny(warnings)] fn cfg_return() -> i32 { - #[cfg(unix)] return 1; - #[cfg(not(unix))] return 2; + #[cfg(unix)] + return 1; + #[cfg(not(unix))] + return 2; } #[deny(warnings)] diff --git a/tests/run-pass/single-match-else.rs b/tests/run-pass/single-match-else.rs index cf032c65703..80fc88f30df 100644 --- a/tests/run-pass/single-match-else.rs +++ b/tests/run-pass/single-match-else.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::single_match_else)] fn main() { diff --git a/tests/run-pass/used_underscore_binding_macro.rs b/tests/run-pass/used_underscore_binding_macro.rs index 68bd6922062..8b6c6557b49 100644 --- a/tests/run-pass/used_underscore_binding_macro.rs +++ b/tests/run-pass/used_underscore_binding_macro.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(clippy::useless_attribute)] //issue #2910 #[macro_use] diff --git a/tests/run-pass/whitelist/conf_whitelisted.rs b/tests/run-pass/whitelist/conf_whitelisted.rs index 168f09a095a..e7f5ddb561f 100644 --- a/tests/run-pass/whitelist/conf_whitelisted.rs +++ b/tests/run-pass/whitelist/conf_whitelisted.rs @@ -7,5 +7,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - fn main() {} diff --git a/tests/ui-toml/bad_toml/conf_bad_toml.rs b/tests/ui-toml/bad_toml/conf_bad_toml.rs index 10c0f0004e4..31781277ae8 100644 --- a/tests/ui-toml/bad_toml/conf_bad_toml.rs +++ b/tests/ui-toml/bad_toml/conf_bad_toml.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - // error-pattern: error reading Clippy's configuration file - - - fn main() {} diff --git a/tests/ui-toml/bad_toml_type/conf_bad_type.rs b/tests/ui-toml/bad_toml_type/conf_bad_type.rs index 021a839d9ef..2307bfff21c 100644 --- a/tests/ui-toml/bad_toml_type/conf_bad_type.rs +++ b/tests/ui-toml/bad_toml_type/conf_bad_type.rs @@ -7,10 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -// error-pattern: error reading Clippy's configuration file: `blacklisted-names` is expected to be a `Vec < String >` but is a `integer` - - - +// error-pattern: error reading Clippy's configuration file: `blacklisted-names` is expected to be a +// `Vec < String >` but is a `integer` fn main() {} diff --git a/tests/ui-toml/toml_blacklist/conf_french_blacklisted_name.rs b/tests/ui-toml/toml_blacklist/conf_french_blacklisted_name.rs index ad81b82b2c5..b00a21b3f2f 100644 --- a/tests/ui-toml/toml_blacklist/conf_french_blacklisted_name.rs +++ b/tests/ui-toml/toml_blacklist/conf_french_blacklisted_name.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(dead_code)] #![allow(clippy::single_match)] #![allow(unused_variables)] diff --git a/tests/ui-toml/toml_trivially_copy/test.rs b/tests/ui-toml/toml_trivially_copy/test.rs index eb09d6dfc5c..39de0de0dc7 100644 --- a/tests/ui-toml/toml_trivially_copy/test.rs +++ b/tests/ui-toml/toml_trivially_copy/test.rs @@ -7,8 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - #![allow(clippy::many_single_char_names)] #[derive(Copy, Clone)] @@ -17,11 +15,9 @@ #[derive(Copy, Clone)] struct Bar(u32); -fn good(a: &mut u32, b: u32, c: &Bar, d: &u32) { -} +fn good(a: &mut u32, b: u32, c: &Bar, d: &u32) {} -fn bad(x: &u16, y: &Foo) { -} +fn bad(x: &u16, y: &Foo) {} fn main() { let (mut a, b, c, d, x, y) = (0, 0, Bar(0), 0, 0, Foo(0)); diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs b/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs index 60e8e4fc29a..c8e6268e95d 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - // error-pattern: error reading Clippy's configuration file: unknown key `foobar` - - - fn main() {} diff --git a/tests/ui/absurd-extreme-comparisons.rs b/tests/ui/absurd-extreme-comparisons.rs index a93027162e5..666c4325706 100644 --- a/tests/ui/absurd-extreme-comparisons.rs +++ b/tests/ui/absurd-extreme-comparisons.rs @@ -8,7 +8,13 @@ // except according to those terms. #![warn(clippy::absurd_extreme_comparisons)] -#![allow(unused, clippy::eq_op, clippy::no_effect, clippy::unnecessary_operation, clippy::needless_pass_by_value)] +#![allow( + unused, + clippy::eq_op, + clippy::no_effect, + clippy::unnecessary_operation, + clippy::needless_pass_by_value +)] #[rustfmt::skip] fn main() { diff --git a/tests/ui/approx_const.rs b/tests/ui/approx_const.rs index b2f50cc2ce3..8eefb6af01d 100644 --- a/tests/ui/approx_const.rs +++ b/tests/ui/approx_const.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[warn(clippy::approx_constant)] #[allow(unused, clippy::shadow_unrelated, clippy::similar_names, clippy::unreadable_literal)] fn main() { diff --git a/tests/ui/arithmetic.rs b/tests/ui/arithmetic.rs index 39aef5a4a56..00de38039a7 100644 --- a/tests/ui/arithmetic.rs +++ b/tests/ui/arithmetic.rs @@ -7,9 +7,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![warn(clippy::integer_arithmetic, clippy::float_arithmetic)] -#![allow(unused, clippy::shadow_reuse, clippy::shadow_unrelated, clippy::no_effect, clippy::unnecessary_operation)] +#![allow( + unused, + clippy::shadow_reuse, + clippy::shadow_unrelated, + clippy::no_effect, + clippy::unnecessary_operation +)] #[rustfmt::skip] fn main() { diff --git a/tests/ui/assign_ops.rs b/tests/ui/assign_ops.rs index 419e63b2c62..75cd7543823 100644 --- a/tests/ui/assign_ops.rs +++ b/tests/ui/assign_ops.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #[allow(dead_code, unused_assignments)] #[warn(clippy::assign_op_pattern)] fn main() { diff --git a/tests/ui/assign_ops2.rs b/tests/ui/assign_ops2.rs index 4f9fbc80aaa..24d0d77a20d 100644 --- a/tests/ui/assign_ops2.rs +++ b/tests/ui/assign_ops2.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[allow(unused_assignments)] #[warn(clippy::misrefactored_assign_op, clippy::assign_op_pattern)] fn main() { @@ -65,6 +61,4 @@ fn cow_add_assign() { // this should not as cow Add is not commutative buf = cows + buf; println!("{}", buf); - } - diff --git a/tests/ui/attrs.rs b/tests/ui/attrs.rs index 1d0c23905bd..413c30a1945 100644 --- a/tests/ui/attrs.rs +++ b/tests/ui/attrs.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::inline_always, clippy::deprecated_semver)] #[inline(always)] @@ -30,22 +26,27 @@ fn false_positive_stmt() { #[inline(always)] fn empty_and_false_positive_stmt() { - ; unreachable!(); } #[deprecated(since = "forever")] -pub const SOME_CONST : u8 = 42; +pub const SOME_CONST: u8 = 42; #[deprecated(since = "1")] -pub const ANOTHER_CONST : u8 = 23; +pub const ANOTHER_CONST: u8 = 23; #[deprecated(since = "0.1.1")] -pub const YET_ANOTHER_CONST : u8 = 0; +pub const YET_ANOTHER_CONST: u8 = 0; fn main() { test_attr_lint(); - if false { false_positive_expr() } - if false { false_positive_stmt() } - if false { empty_and_false_positive_stmt() } + if false { + false_positive_expr() + } + if false { + false_positive_stmt() + } + if false { + empty_and_false_positive_stmt() + } } diff --git a/tests/ui/author.rs b/tests/ui/author.rs index f151d50f2f2..4b7729e23b1 100644 --- a/tests/ui/author.rs +++ b/tests/ui/author.rs @@ -7,11 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - fn main() { - #[clippy::author] let x: char = 0x45 as char; } diff --git a/tests/ui/author/call.rs b/tests/ui/author/call.rs index 3dcf8da5c72..40cc0d7a919 100644 --- a/tests/ui/author/call.rs +++ b/tests/ui/author/call.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - fn main() { #[clippy::author] let _ = ::std::cmp::min(3, 4); diff --git a/tests/ui/author/for_loop.rs b/tests/ui/author/for_loop.rs index a27322b3205..4acd0b452bb 100644 --- a/tests/ui/author/for_loop.rs +++ b/tests/ui/author/for_loop.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![feature(stmt_expr_attributes)] fn main() { diff --git a/tests/ui/author/matches.rs b/tests/ui/author/matches.rs index 956404f3490..4c220dded8a 100644 --- a/tests/ui/author/matches.rs +++ b/tests/ui/author/matches.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![feature(tool_attributes)] fn main() { diff --git a/tests/ui/bit_masks.rs b/tests/ui/bit_masks.rs index db5a6885c9e..bda952db723 100644 --- a/tests/ui/bit_masks.rs +++ b/tests/ui/bit_masks.rs @@ -7,15 +7,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - -const THREE_BITS : i64 = 7; -const EVEN_MORE_REDIRECTION : i64 = THREE_BITS; +const THREE_BITS: i64 = 7; +const EVEN_MORE_REDIRECTION: i64 = THREE_BITS; #[warn(clippy::bad_bit_mask)] -#[allow(clippy::ineffective_bit_mask, clippy::identity_op, clippy::no_effect, clippy::unnecessary_operation)] +#[allow( + clippy::ineffective_bit_mask, + clippy::identity_op, + clippy::no_effect, + clippy::unnecessary_operation +)] fn main() { let x = 5; diff --git a/tests/ui/blacklisted_name.rs b/tests/ui/blacklisted_name.rs index 285438810d9..fef73e9d84f 100644 --- a/tests/ui/blacklisted_name.rs +++ b/tests/ui/blacklisted_name.rs @@ -7,11 +7,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - -#![allow(dead_code, clippy::similar_names, clippy::single_match, clippy::toplevel_ref_arg, unused_mut, unused_variables)] +#![allow( + dead_code, + clippy::similar_names, + clippy::single_match, + clippy::toplevel_ref_arg, + unused_mut, + unused_variables +)] #![warn(clippy::blacklisted_name)] fn test(foo: ()) {} diff --git a/tests/ui/block_in_if_condition.rs b/tests/ui/block_in_if_condition.rs index 94611811841..eaaf5e050bf 100644 --- a/tests/ui/block_in_if_condition.rs +++ b/tests/ui/block_in_if_condition.rs @@ -7,33 +7,28 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::block_in_if_condition_expr)] #![warn(clippy::block_in_if_condition_stmt)] #![allow(unused, clippy::let_and_return)] #![warn(clippy::nonminimal_bool)] - macro_rules! blocky { - () => {{true}} + () => {{ + true + }}; } macro_rules! blocky_too { () => {{ let r = true; r - }} + }}; } fn macro_if() { - if blocky!() { - } + if blocky!() {} - if blocky_too!() { - } + if blocky_too!() {} } fn condition_has_block() -> i32 { @@ -55,7 +50,7 @@ fn condition_has_block_with_single_expression() -> i32 { } } -fn predicate bool, T>(pfn: F, val:T) -> bool { +fn predicate bool, T>(pfn: F, val: T) -> bool { pfn(val) } @@ -65,11 +60,24 @@ fn pred_test() { // this is a sneaky case, where the block isn't directly in the condition, but is actually // inside a closure that the condition is using. same principle applies. add some extra // expressions to make sure linter isn't confused by them. - if v == 3 && sky == "blue" && predicate(|x| { let target = 3; x == target }, v) { - } + if v == 3 + && sky == "blue" + && predicate( + |x| { + let target = 3; + x == target + }, + v, + ) + {} - if predicate(|x| { let target = 3; x == target }, v) { - } + if predicate( + |x| { + let target = 3; + x == target + }, + v, + ) {} } fn condition_is_normal() -> i32 { @@ -82,9 +90,7 @@ fn condition_is_normal() -> i32 { } fn closure_without_block() { - if predicate(|x| x == 3, 6) { - - } + if predicate(|x| x == 3, 6) {} } fn condition_is_unsafe_block() { @@ -96,8 +102,7 @@ fn condition_is_unsafe_block() { } } -fn main() { -} +fn main() {} fn macro_in_closure() { let option = Some(true); diff --git a/tests/ui/bool_comparison.rs b/tests/ui/bool_comparison.rs index 8ab8b3f9281..30b5acf2d97 100644 --- a/tests/ui/bool_comparison.rs +++ b/tests/ui/bool_comparison.rs @@ -7,19 +7,47 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[warn(clippy::bool_comparison)] fn main() { let x = true; - if x == true { "yes" } else { "no" }; - if x == false { "yes" } else { "no" }; - if true == x { "yes" } else { "no" }; - if false == x { "yes" } else { "no" }; - if x != true { "yes" } else { "no" }; - if x != false { "yes" } else { "no" }; - if true != x { "yes" } else { "no" }; - if false != x { "yes" } else { "no" }; + if x == true { + "yes" + } else { + "no" + }; + if x == false { + "yes" + } else { + "no" + }; + if true == x { + "yes" + } else { + "no" + }; + if false == x { + "yes" + } else { + "no" + }; + if x != true { + "yes" + } else { + "no" + }; + if x != false { + "yes" + } else { + "no" + }; + if true != x { + "yes" + } else { + "no" + }; + if false != x { + "yes" + } else { + "no" + }; } diff --git a/tests/ui/booleans.rs b/tests/ui/booleans.rs index e63b6a75e8f..8eb1b52577c 100644 --- a/tests/ui/booleans.rs +++ b/tests/ui/booleans.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::nonminimal_bool, clippy::logic_bug)] #[allow(unused, clippy::many_single_char_names)] @@ -71,58 +68,78 @@ fn methods_with_negation() { // Simplified versions of https://github.com/rust-lang/rust-clippy/issues/2638 // clippy::nonminimal_bool should only check the built-in Result and Some type, not // any other types like the following. -enum CustomResultOk { Ok, Err(E) } -enum CustomResultErr { Ok, Err(E) } -enum CustomSomeSome { Some(T), None } -enum CustomSomeNone { Some(T), None } +enum CustomResultOk { + Ok, + Err(E), +} +enum CustomResultErr { + Ok, + Err(E), +} +enum CustomSomeSome { + Some(T), + None, +} +enum CustomSomeNone { + Some(T), + None, +} impl CustomResultOk { - pub fn is_ok(&self) -> bool { true } + pub fn is_ok(&self) -> bool { + true + } } impl CustomResultErr { - pub fn is_err(&self) -> bool { true } + pub fn is_err(&self) -> bool { + true + } } impl CustomSomeSome { - pub fn is_some(&self) -> bool { true } + pub fn is_some(&self) -> bool { + true + } } impl CustomSomeNone { - pub fn is_none(&self) -> bool { true } + pub fn is_none(&self) -> bool { + true + } } fn dont_warn_for_custom_methods_with_negation() { let res = CustomResultOk::Err("Error"); // Should not warn and suggest 'is_err()' because the type does not // implement is_err(). - if !res.is_ok() { } + if !res.is_ok() {} let res = CustomResultErr::Err("Error"); // Should not warn and suggest 'is_ok()' because the type does not // implement is_ok(). - if !res.is_err() { } + if !res.is_err() {} let res = CustomSomeSome::Some("thing"); // Should not warn and suggest 'is_none()' because the type does not // implement is_none(). - if !res.is_some() { } + if !res.is_some() {} let res = CustomSomeNone::Some("thing"); // Should not warn and suggest 'is_some()' because the type does not // implement is_some(). - if !res.is_none() { } + if !res.is_none() {} } // Only Built-in Result and Some types should suggest the negated alternative fn warn_for_built_in_methods_with_negation() { let res: Result = Ok(1); - if !res.is_ok() { } - if !res.is_err() { } + if !res.is_ok() {} + if !res.is_err() {} let res = Some(1); - if !res.is_some() { } - if !res.is_none() { } + if !res.is_some() {} + if !res.is_none() {} } #[allow(clippy::neg_cmp_op_on_partial_ord)] diff --git a/tests/ui/borrow_box.rs b/tests/ui/borrow_box.rs index dbcd42a692c..cf204150f8b 100644 --- a/tests/ui/borrow_box.rs +++ b/tests/ui/borrow_box.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![deny(clippy::borrowed_box)] #![allow(clippy::blacklisted_name)] #![allow(unused_variables)] @@ -25,7 +21,7 @@ pub fn test2() { } struct Test3<'a> { - foo: &'a Box + foo: &'a Box, } trait Test4 { @@ -49,7 +45,7 @@ pub fn test6() { } struct Test7<'a> { - foo: &'a Box + foo: &'a Box, } trait Test8 { @@ -71,7 +67,7 @@ pub fn test10() { } struct Test11<'a> { - foo: &'a Box + foo: &'a Box, } trait Test12 { @@ -84,7 +80,7 @@ fn test4(a: &Box) { } } -fn main(){ +fn main() { test1(&mut Box::new(false)); test2(); test5(&mut (Box::new(false) as Box)); diff --git a/tests/ui/box_vec.rs b/tests/ui/box_vec.rs index bf505c85abc..48523054097 100644 --- a/tests/ui/box_vec.rs +++ b/tests/ui/box_vec.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::all)] #![allow(clippy::boxed_local, clippy::needless_pass_by_value)] #![allow(clippy::blacklisted_name)] @@ -18,7 +14,7 @@ macro_rules! boxit { ($init:expr, $x:ty) => { let _: Box<$x> = Box::new($init); - } + }; } fn test_macro() { @@ -28,7 +24,8 @@ pub fn test(foo: Box>) { println!("{:?}", foo.get(0)) } -pub fn test2(foo: Box)>) { // pass if #31 is fixed +pub fn test2(foo: Box)>) { + // pass if #31 is fixed foo(vec![1, 2, 3]) } @@ -36,7 +33,7 @@ pub fn test_local_not_linted() { let _: Box>; } -fn main(){ +fn main() { test(Box::new(Vec::new())); test2(Box::new(|v| println!("{:?}", v))); test_macro(); diff --git a/tests/ui/builtin-type-shadow.rs b/tests/ui/builtin-type-shadow.rs index e43a2789ce1..66a7e318f8a 100644 --- a/tests/ui/builtin-type-shadow.rs +++ b/tests/ui/builtin-type-shadow.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::builtin_type_shadow)] fn foo(a: u32) -> u32 { @@ -17,5 +14,4 @@ fn foo(a: u32) -> u32 { // ^ rustc's type error } -fn main() { -} +fn main() {} diff --git a/tests/ui/bytecount.rs b/tests/ui/bytecount.rs index 170666d1f18..6bc9b5ddecd 100644 --- a/tests/ui/bytecount.rs +++ b/tests/ui/bytecount.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[deny(clippy::naive_bytecount)] fn main() { let x = vec![0_u8; 16]; diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index 9976a4aa96a..45e878e9d80 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -7,11 +7,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - -#[warn(clippy::cast_precision_loss, clippy::cast_possible_truncation, clippy::cast_sign_loss, clippy::cast_possible_wrap, clippy::cast_lossless)] +#[warn( + clippy::cast_precision_loss, + clippy::cast_possible_truncation, + clippy::cast_sign_loss, + clippy::cast_possible_wrap, + clippy::cast_lossless +)] #[allow(clippy::no_effect, clippy::unnecessary_operation)] fn main() { // Test clippy::cast_precision_loss @@ -49,7 +51,7 @@ fn main() { false as bool; &1i32 as &i32; // Should not trigger - let v = vec!(1); + let v = vec![1]; &v as &[i32]; 1.0 as f64; 1 as u64; diff --git a/tests/ui/cast_alignment.rs b/tests/ui/cast_alignment.rs index a1a2e1c9a8f..efc56ea2bbc 100644 --- a/tests/ui/cast_alignment.rs +++ b/tests/ui/cast_alignment.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - //! Test casts for alignment issues #![feature(libc)] diff --git a/tests/ui/cast_lossless_float.rs b/tests/ui/cast_lossless_float.rs index 468774dd88b..e52a756c003 100644 --- a/tests/ui/cast_lossless_float.rs +++ b/tests/ui/cast_lossless_float.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #[warn(clippy::cast_lossless)] #[allow(clippy::no_effect, clippy::unnecessary_operation)] fn main() { diff --git a/tests/ui/cast_lossless_integer.rs b/tests/ui/cast_lossless_integer.rs index 4f7432de620..593ffdd2766 100644 --- a/tests/ui/cast_lossless_integer.rs +++ b/tests/ui/cast_lossless_integer.rs @@ -7,8 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - #[warn(clippy::cast_lossless)] #[allow(clippy::no_effect, clippy::unnecessary_operation)] fn main() { diff --git a/tests/ui/cast_size.rs b/tests/ui/cast_size.rs index fddf9669a8f..8f691104c51 100644 --- a/tests/ui/cast_size.rs +++ b/tests/ui/cast_size.rs @@ -7,10 +7,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - -#[warn(clippy::cast_precision_loss, clippy::cast_possible_truncation, clippy::cast_sign_loss, clippy::cast_possible_wrap, clippy::cast_lossless)] +#[warn( + clippy::cast_precision_loss, + clippy::cast_possible_truncation, + clippy::cast_sign_loss, + clippy::cast_possible_wrap, + clippy::cast_lossless +)] #[allow(clippy::no_effect, clippy::unnecessary_operation)] fn main() { // Casting from *size diff --git a/tests/ui/char_lit_as_u8.rs b/tests/ui/char_lit_as_u8.rs index d684fcf5746..663962afeae 100644 --- a/tests/ui/char_lit_as_u8.rs +++ b/tests/ui/char_lit_as_u8.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::char_lit_as_u8)] #![allow(unused_variables)] fn main() { diff --git a/tests/ui/checked_unwrap.rs b/tests/ui/checked_unwrap.rs index 383fd82240b..4d250a80e90 100644 --- a/tests/ui/checked_unwrap.rs +++ b/tests/ui/checked_unwrap.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] #![allow(clippy::if_same_then_else)] @@ -43,11 +40,11 @@ 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). + // it will always panic but the lint is not smart enough to see this (it only checks if conditions). } 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). + // it will always panic but the lint is not smart enough to see this (it only checks if conditions). } } diff --git a/tests/ui/clone_on_copy_impl.rs b/tests/ui/clone_on_copy_impl.rs index a1353abd92b..058cbf7a16c 100644 --- a/tests/ui/clone_on_copy_impl.rs +++ b/tests/ui/clone_on_copy_impl.rs @@ -7,9 +7,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -use std::marker::PhantomData; use std::fmt; +use std::marker::PhantomData; pub struct Key { #[doc(hidden)] diff --git a/tests/ui/clone_on_copy_mut.rs b/tests/ui/clone_on_copy_mut.rs index 81d70eb9458..82f411d5c9d 100644 --- a/tests/ui/clone_on_copy_mut.rs +++ b/tests/ui/clone_on_copy_mut.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - pub fn dec_read_dec(i: &mut i32) -> i32 { *i -= 1; let ret = *i; diff --git a/tests/ui/cmp_nan.rs b/tests/ui/cmp_nan.rs index 4b62d0e53f1..d6bdb5894d5 100644 --- a/tests/ui/cmp_nan.rs +++ b/tests/ui/cmp_nan.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[warn(clippy::cmp_nan)] #[allow(clippy::float_cmp, clippy::no_effect, clippy::unnecessary_operation)] fn main() { diff --git a/tests/ui/cmp_null.rs b/tests/ui/cmp_null.rs index 03f0367a640..37615c9e113 100644 --- a/tests/ui/cmp_null.rs +++ b/tests/ui/cmp_null.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::cmp_null)] #![allow(unused_mut)] @@ -17,12 +14,12 @@ fn main() { let x = 0; - let p : *const usize = &x; + let p: *const usize = &x; if p == ptr::null() { println!("This is surprising!"); } let mut y = 0; - let mut m : *mut usize = &mut y; + let mut m: *mut usize = &mut y; if m == ptr::null_mut() { println!("This is surprising, too!"); } diff --git a/tests/ui/cmp_owned.rs b/tests/ui/cmp_owned.rs index dc3d62ddfa6..53de5136105 100644 --- a/tests/ui/cmp_owned.rs +++ b/tests/ui/cmp_owned.rs @@ -7,14 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[warn(clippy::cmp_owned)] #[allow(clippy::unnecessary_operation)] fn main() { - fn with_to_string(x : &str) { + fn with_to_string(x: &str) { x != "foo".to_string(); "foo".to_string() != x; diff --git a/tests/ui/collapsible_if.rs b/tests/ui/collapsible_if.rs index bd6e0c07946..6828743abf3 100644 --- a/tests/ui/collapsible_if.rs +++ b/tests/ui/collapsible_if.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #[rustfmt::skip] #[warn(clippy::collapsible_if)] fn main() { diff --git a/tests/ui/complex_types.rs b/tests/ui/complex_types.rs index e735bf8e487..9d75de62d74 100644 --- a/tests/ui/complex_types.rs +++ b/tests/ui/complex_types.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::all)] #![allow(unused, clippy::needless_pass_by_value)] #![feature(associated_type_defaults)] @@ -32,19 +29,21 @@ enum E { impl S { const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); - fn impl_method(&self, p: Vec>>) { } + fn impl_method(&self, p: Vec>>) {} } trait T { const A: Vec>>; type B = Vec>>; fn method(&self, p: Vec>>); - fn def_method(&self, p: Vec>>) { } + fn def_method(&self, p: Vec>>) {} } -fn test1() -> Vec>> { vec![] } +fn test1() -> Vec>> { + vec![] +} -fn test2(_x: Vec>>) { } +fn test2(_x: Vec>>) {} fn test3() { let _y: Vec>> = vec![]; @@ -67,5 +66,4 @@ struct D { ), } -fn main() { -} +fn main() {} diff --git a/tests/ui/const_static_lifetime.rs b/tests/ui/const_static_lifetime.rs index 2b6a5dc249a..3e1aa94f969 100644 --- a/tests/ui/const_static_lifetime.rs +++ b/tests/ui/const_static_lifetime.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #[derive(Debug)] struct Foo {} diff --git a/tests/ui/copies.rs b/tests/ui/copies.rs index 5c4bbecf822..00e1d726207 100644 --- a/tests/ui/copies.rs +++ b/tests/ui/copies.rs @@ -7,13 +7,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(clippy::blacklisted_name, clippy::collapsible_if, clippy::cyclomatic_complexity, clippy::eq_op, clippy::needless_continue, - clippy::needless_return, clippy::never_loop, clippy::no_effect, clippy::zero_divided_by_zero, clippy::unused_unit)] - - +#![allow( + clippy::blacklisted_name, + clippy::collapsible_if, + clippy::cyclomatic_complexity, + clippy::eq_op, + clippy::needless_continue, + clippy::needless_return, + clippy::never_loop, + clippy::no_effect, + clippy::zero_divided_by_zero, + clippy::unused_unit +)] fn bar(_: T) {} -fn foo() -> bool { unimplemented!() } +fn foo() -> bool { + unimplemented!() +} struct Foo { bar: u8, @@ -37,8 +47,8 @@ fn if_same_then_else() -> Result<&'static str, ()> { ..10; 0..=10; foo(); - } - else { //~ ERROR same body as `if` block + } else { + //~ ERROR same body as `if` block Foo { bar: 42 }; 0..10; ..; @@ -50,30 +60,26 @@ fn if_same_then_else() -> Result<&'static str, ()> { if true { Foo { bar: 42 }; - } - else { + } else { Foo { bar: 43 }; } if true { (); - } - else { + } else { () } if true { 0..10; - } - else { + } else { 0..=10; } if true { foo(); foo(); - } - else { + } else { foo(); } @@ -84,18 +90,19 @@ fn if_same_then_else() -> Result<&'static str, ()> { if true { a += 7; } - a = -31-a; + a = -31 - a; a - } - _ => { //~ ERROR match arms have same body + }, + _ => { + //~ ERROR match arms have same body foo(); let mut a = 42 + [23].len() as i32; if true { a += 7; } - a = -31-a; + a = -31 - a; a - } + }, }; let _ = match Abc::A { @@ -110,8 +117,8 @@ fn if_same_then_else() -> Result<&'static str, ()> { let _ = if true { 42 - } - else { //~ ERROR same body as `if` block + } else { + //~ ERROR same body as `if` block 42 }; @@ -124,8 +131,8 @@ fn if_same_then_else() -> Result<&'static str, ()> { continue; } } - } - else { //~ ERROR same body as `if` block + } else { + //~ ERROR same body as `if` block for _ in &[42] { let foo: &Option<_> = &Some::(42); if true { @@ -137,25 +144,19 @@ fn if_same_then_else() -> Result<&'static str, ()> { } if true { - let bar = if true { - 42 - } - else { - 43 - }; + let bar = if true { 42 } else { 43 }; - while foo() { break; } + while foo() { + break; + } bar + 1; - } - else { //~ ERROR same body as `if` block - let bar = if true { - 42 - } - else { - 43 - }; + } else { + //~ ERROR same body as `if` block + let bar = if true { 42 } else { 43 }; - while foo() { break; } + while foo() { + break; + } bar + 1; } @@ -166,11 +167,9 @@ fn if_same_then_else() -> Result<&'static str, ()> { 10..=15 => 3, _ => 4, }; - } - else if false { + } else if false { foo(); - } - else if foo() { + } else if foo() { let _ = match 42 { 42 => 1, a if a > 0 => 2, @@ -181,64 +180,57 @@ fn if_same_then_else() -> Result<&'static str, ()> { if true { if let Some(a) = Some(42) {} - } - else { //~ ERROR same body as `if` block + } else { + //~ ERROR same body as `if` block if let Some(a) = Some(42) {} } if true { if let (1, .., 3) = (1, 2, 3) {} - } - else { //~ ERROR same body as `if` block + } else { + //~ ERROR same body as `if` block if let (1, .., 3) = (1, 2, 3) {} } if true { if let (1, .., 3) = (1, 2, 3) {} - } - else { + } else { if let (.., 3) = (1, 2, 3) {} } if true { if let (1, .., 3) = (1, 2, 3) {} - } - else { + } else { if let (.., 4) = (1, 2, 3) {} } if true { if let (1, .., 3) = (1, 2, 3) {} - } - else { + } else { if let (.., 1, 3) = (1, 2, 3) {} } if true { if let Some(42) = None {} - } - else { + } else { if let Option::Some(42) = None {} } if true { if let Some(42) = None:: {} - } - else { + } else { if let Some(42) = None {} } if true { if let Some(42) = None:: {} - } - else { + } else { if let Some(42) = None:: {} } if true { if let Some(a) = Some(42) {} - } - else { + } else { if let Some(a) = Some(43) {} } @@ -288,41 +280,36 @@ fn if_same_then_else() -> Result<&'static str, ()> { _ => 0, }; - let _ = if true { - 0.0 - } else { //~ ERROR same body as `if` block - 0.0 - }; - - let _ = if true { - -0.0 - } else { //~ ERROR same body as `if` block - -0.0 - }; - let _ = if true { 0.0 } else { + //~ ERROR same body as `if` block + 0.0 + }; + + let _ = if true { + -0.0 + } else { + //~ ERROR same body as `if` block -0.0 }; + let _ = if true { 0.0 } else { -0.0 }; + // Different NaNs - let _ = if true { - 0.0 / 0.0 - } else { - std::f32::NAN - }; + let _ = if true { 0.0 / 0.0 } else { std::f32::NAN }; // Same NaNs let _ = if true { std::f32::NAN - } else { //~ ERROR same body as `if` block + } else { + //~ ERROR same body as `if` block std::f32::NAN }; let _ = match Some(()) { Some(()) => 0.0, - None => -0.0 + None => -0.0, }; match (Some(42), Some("")) { @@ -333,20 +320,18 @@ fn if_same_then_else() -> Result<&'static str, ()> { if true { try!(Ok("foo")); - } - else { //~ ERROR same body as `if` block + } else { + //~ ERROR same body as `if` block try!(Ok("foo")); } if true { let foo = ""; return Ok(&foo[0..]); - } - else if false { + } else if false { let foo = "bar"; return Ok(&foo[0..]); - } - else { + } else { let foo = ""; return Ok(&foo[0..]); } @@ -359,22 +344,20 @@ fn ifs_same_cond() { let b = false; if b { - } - else if b { //~ ERROR ifs same condition + } else if b { + //~ ERROR ifs same condition } if a == 1 { - } - else if a == 1 { //~ ERROR ifs same condition + } else if a == 1 { + //~ ERROR ifs same condition } - if 2*a == 1 { - } - else if 2*a == 2 { - } - else if 2*a == 1 { //~ ERROR ifs same condition - } - else if a == 1 { + if 2 * a == 1 { + } else if 2 * a == 2 { + } else if 2 * a == 1 { + //~ ERROR ifs same condition + } else if a == 1 { } // See #659 @@ -387,14 +370,14 @@ fn ifs_same_cond() { }; let mut v = vec![1]; - if v.pop() == None { // ok, functions - } - else if v.pop() == None { + if v.pop() == None { + // ok, functions + } else if v.pop() == None { } - if v.len() == 42 { // ok, functions - } - else if v.len() == 42 { + if v.len() == 42 { + // ok, functions + } else if v.len() == 42 { } } diff --git a/tests/ui/copy_iterator.rs b/tests/ui/copy_iterator.rs index b5684f183eb..22d3e138898 100644 --- a/tests/ui/copy_iterator.rs +++ b/tests/ui/copy_iterator.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::copy_iterator)] #[derive(Copy, Clone)] diff --git a/tests/ui/cstring.rs b/tests/ui/cstring.rs index 6121166debe..5fe915a8368 100644 --- a/tests/ui/cstring.rs +++ b/tests/ui/cstring.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - fn main() {} #[allow(clippy::result_unwrap_used)] diff --git a/tests/ui/cyclomatic_complexity.rs b/tests/ui/cyclomatic_complexity.rs index a9a2391f150..fff67762924 100644 --- a/tests/ui/cyclomatic_complexity.rs +++ b/tests/ui/cyclomatic_complexity.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![allow(clippy::all)] #![warn(clippy::cyclomatic_complexity)] #![allow(unused)] @@ -181,8 +180,8 @@ fn bar() { #[test] #[clippy::cyclomatic_complexity = "0"] -/// Tests are usually complex but simple at the same time. `clippy::cyclomatic_complexity` used to give -/// lots of false-positives in tests. +/// Tests are usually complex but simple at the same time. `clippy::cyclomatic_complexity` used to +/// give lots of false-positives in tests. fn dont_warn_on_tests() { match 99 { 0 => println!("hi"), @@ -278,7 +277,6 @@ fn cake() { println!("whee"); } - #[clippy::cyclomatic_complexity = "0"] pub fn read_file(input_path: &str) -> String { use std::fs::File; @@ -288,7 +286,7 @@ pub fn read_file(input_path: &str) -> String { Ok(f) => f, Err(err) => { panic!("Can't open {}: {}", input_path, err); - } + }, }; let mut bytes = Vec::new(); @@ -297,14 +295,14 @@ pub fn read_file(input_path: &str) -> String { Ok(..) => {}, Err(_) => { panic!("Can't read {}", input_path); - } + }, }; match String::from_utf8(bytes) { Ok(contents) => contents, Err(_) => { panic!("{} is not UTF-8 encoded", input_path); - } + }, } } @@ -313,8 +311,7 @@ enum Void {} #[clippy::cyclomatic_complexity = "0"] fn void(void: Void) { if true { - match void { - } + match void {} } } diff --git a/tests/ui/cyclomatic_complexity_attr_used.rs b/tests/ui/cyclomatic_complexity_attr_used.rs index 63d4e65a977..b1da9649f90 100644 --- a/tests/ui/cyclomatic_complexity_attr_used.rs +++ b/tests/ui/cyclomatic_complexity_attr_used.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::cyclomatic_complexity)] #![warn(unused)] diff --git a/tests/ui/decimal_literal_representation.rs b/tests/ui/decimal_literal_representation.rs index c52fcd826ca..c196b27a3a6 100644 --- a/tests/ui/decimal_literal_representation.rs +++ b/tests/ui/decimal_literal_representation.rs @@ -7,24 +7,22 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[warn(clippy::decimal_literal_representation)] #[allow(unused_variables)] fn main() { - let good = ( // Hex: - 127, // 0x7F - 256, // 0x100 - 511, // 0x1FF - 2048, // 0x800 - 4090, // 0xFFA - 16_371, // 0x3FF3 - 61_683, // 0xF0F3 - 2_131_750_925, // 0x7F0F_F00D + let good = ( + // Hex: + 127, // 0x7F + 256, // 0x100 + 511, // 0x1FF + 2048, // 0x800 + 4090, // 0xFFA + 16_371, // 0x3FF3 + 61_683, // 0xF0F3 + 2_131_750_925, // 0x7F0F_F00D ); - let bad = ( // Hex: + let bad = ( + // Hex: 32_773, // 0x8005 65_280, // 0xFF00 2_131_750_927, // 0x7F0F_F00F diff --git a/tests/ui/default_trait_access.rs b/tests/ui/default_trait_access.rs index 331ad03f9a2..eaa367b0cb3 100644 --- a/tests/ui/default_trait_access.rs +++ b/tests/ui/default_trait_access.rs @@ -7,14 +7,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::default_trait_access)] +use std::default; use std::default::Default as D2; use std::string; -use std::default; fn main() { let s1: String = Default::default(); diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs index a7e95ad5dde..7a1657424ed 100644 --- a/tests/ui/deprecated.rs +++ b/tests/ui/deprecated.rs @@ -7,18 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[warn(str_to_string)] - #[warn(string_to_string)] - #[warn(unstable_as_slice)] - #[warn(unstable_as_mut_slice)] - #[warn(misaligned_transmute)] fn main() {} diff --git a/tests/ui/derive.rs b/tests/ui/derive.rs index 521a2e323fc..a6020b61337 100644 --- a/tests/ui/derive.rs +++ b/tests/ui/derive.rs @@ -7,11 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![feature(untagged_unions)] - #![allow(dead_code)] #![warn(clippy::expl_impl_clone_on_copy)] @@ -21,21 +17,27 @@ struct Foo; impl PartialEq for Foo { - fn eq(&self, _: &u64) -> bool { true } + fn eq(&self, _: &u64) -> bool { + true + } } #[derive(Hash)] struct Bar; impl PartialEq for Bar { - fn eq(&self, _: &Bar) -> bool { true } + fn eq(&self, _: &Bar) -> bool { + true + } } #[derive(Hash)] struct Baz; impl PartialEq for Baz { - fn eq(&self, _: &Baz) -> bool { true } + fn eq(&self, _: &Baz) -> bool { + true + } } #[derive(PartialEq)] @@ -49,7 +51,9 @@ fn hash(&self, _: &mut H) {} struct Qux; impl Clone for Qux { - fn clone(&self) -> Self { Qux } + fn clone(&self) -> Self { + Qux + } } // looks like unions don't support deriving Clone for now @@ -60,9 +64,7 @@ union Union { impl Clone for Union { fn clone(&self) -> Self { - Union { - a: 42, - } + Union { a: 42 } } } @@ -73,7 +75,9 @@ struct Lt<'a> { } impl<'a> Clone for Lt<'a> { - fn clone(&self) -> Self { unimplemented!() } + fn clone(&self) -> Self { + unimplemented!() + } } // Ok, `Clone` cannot be derived because of the big array @@ -83,7 +87,9 @@ struct BigArray { } impl Clone for BigArray { - fn clone(&self) -> Self { unimplemented!() } + fn clone(&self) -> Self { + unimplemented!() + } } // Ok, function pointers are not always Clone @@ -93,7 +99,9 @@ struct FnPtr { } impl Clone for FnPtr { - fn clone(&self) -> Self { unimplemented!() } + fn clone(&self) -> Self { + unimplemented!() + } } // Ok, generics @@ -103,7 +111,9 @@ struct Generic { } impl Clone for Generic { - fn clone(&self) -> Self { unimplemented!() } + fn clone(&self) -> Self { + unimplemented!() + } } fn main() {} diff --git a/tests/ui/diverging_sub_expression.rs b/tests/ui/diverging_sub_expression.rs index a47c96759ac..3399dba7189 100644 --- a/tests/ui/diverging_sub_expression.rs +++ b/tests/ui/diverging_sub_expression.rs @@ -7,21 +7,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![feature(never_type)] - #![warn(clippy::diverging_sub_expression)] #![allow(clippy::match_same_arms, clippy::logic_bug)] #[allow(clippy::empty_loop)] -fn diverge() -> ! { loop {} } +fn diverge() -> ! { + loop {} +} struct A; impl A { - fn foo(&self) -> ! { diverge() } + fn foo(&self) -> ! { + diverge() + } } #[allow(unused_variables, clippy::unnecessary_operation, clippy::short_circuit_statement)] diff --git a/tests/ui/dlist.rs b/tests/ui/dlist.rs index cf16777b77a..dfc8be24a8b 100644 --- a/tests/ui/dlist.rs +++ b/tests/ui/dlist.rs @@ -7,13 +7,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![feature(alloc)] #![feature(associated_type_defaults)] - - #![warn(clippy::linkedlist)] #![allow(dead_code, clippy::needless_pass_by_value)] @@ -23,13 +18,13 @@ trait Foo { type Baz = LinkedList; fn foo(LinkedList); - const BAR : Option>; + const BAR: Option>; } // ok, we don’t want to warn for implementations, see #605 impl Foo for LinkedList { fn foo(_: LinkedList) {} - const BAR : Option> = None; + const BAR: Option> = None; } struct Bar; @@ -49,7 +44,7 @@ pub fn test_local_not_linted() { let _: LinkedList; } -fn main(){ +fn main() { test(LinkedList::new()); test_local_not_linted(); } diff --git a/tests/ui/double_comparison.rs b/tests/ui/double_comparison.rs index 555f35884f9..70b837a75b6 100644 --- a/tests/ui/double_comparison.rs +++ b/tests/ui/double_comparison.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - fn main() { let x = 1; let y = 2; diff --git a/tests/ui/double_neg.rs b/tests/ui/double_neg.rs index 3785c09060b..7d65122cb5e 100644 --- a/tests/ui/double_neg.rs +++ b/tests/ui/double_neg.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[warn(clippy::double_neg)] fn main() { let x = 1; diff --git a/tests/ui/drop_forget_copy.rs b/tests/ui/drop_forget_copy.rs index 44e9ae0e044..2ea8954ff59 100644 --- a/tests/ui/drop_forget_copy.rs +++ b/tests/ui/drop_forget_copy.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::drop_copy, clippy::forget_copy)] #![allow(clippy::toplevel_ref_arg, clippy::drop_ref, clippy::forget_ref, unused_mut)] @@ -18,18 +14,21 @@ use std::vec::Vec; #[derive(Copy, Clone)] -struct SomeStruct { -} +struct SomeStruct {} struct AnotherStruct { x: u8, y: u8, - z: Vec + z: Vec, } impl Clone for AnotherStruct { - fn clone(& self) -> AnotherStruct { - AnotherStruct{x: self.x, y: self.y, z: self.z.clone()} + fn clone(&self) -> AnotherStruct { + AnotherStruct { + x: self.x, + y: self.y, + z: self.z.clone(), + } } } @@ -52,7 +51,11 @@ fn main() { forget(s4); forget(s5); - let a1 = AnotherStruct {x: 255, y: 0, z: vec![1, 2, 3]}; + let a1 = AnotherStruct { + x: 255, + y: 0, + z: vec![1, 2, 3], + }; let a2 = &a1; let mut a3 = a1.clone(); let ref a4 = a1; diff --git a/tests/ui/drop_forget_ref.rs b/tests/ui/drop_forget_ref.rs index 0aee38d3cbf..6821d403322 100644 --- a/tests/ui/drop_forget_ref.rs +++ b/tests/ui/drop_forget_ref.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::drop_ref, clippy::forget_ref)] #![allow(clippy::toplevel_ref_arg, clippy::similar_names, clippy::needless_pass_by_value)] diff --git a/tests/ui/duplicate_underscore_argument.rs b/tests/ui/duplicate_underscore_argument.rs index 27329965f0c..da4e2a6dc8a 100644 --- a/tests/ui/duplicate_underscore_argument.rs +++ b/tests/ui/duplicate_underscore_argument.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::duplicate_underscore_argument)] #[allow(dead_code, unused)] diff --git a/tests/ui/duration_subsec.rs b/tests/ui/duration_subsec.rs index c8db599a840..8c2dade34c0 100644 --- a/tests/ui/duration_subsec.rs +++ b/tests/ui/duration_subsec.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::duration_subsec)] use std::time::Duration; diff --git a/tests/ui/else_if_without_else.rs b/tests/ui/else_if_without_else.rs index caaa024ff6b..0776eae310c 100644 --- a/tests/ui/else_if_without_else.rs +++ b/tests/ui/else_if_without_else.rs @@ -7,15 +7,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::all)] #![warn(clippy::else_if_without_else)] -fn bla1() -> bool { unimplemented!() } -fn bla2() -> bool { unimplemented!() } -fn bla3() -> bool { unimplemented!() } +fn bla1() -> bool { + unimplemented!() +} +fn bla2() -> bool { + unimplemented!() +} +fn bla3() -> bool { + unimplemented!() +} fn main() { if bla1() { @@ -48,7 +51,8 @@ fn main() { if bla1() { println!("if"); - } else if bla2() { //~ ERROR else if without else + } else if bla2() { + //~ ERROR else if without else println!("else if"); } @@ -56,7 +60,8 @@ fn main() { println!("if"); } else if bla2() { println!("else if 1"); - } else if bla3() { //~ ERROR else if without else + } else if bla3() { + //~ ERROR else if without else println!("else if 2"); } } diff --git a/tests/ui/empty_enum.rs b/tests/ui/empty_enum.rs index b60f5491a93..b47afc822f8 100644 --- a/tests/ui/empty_enum.rs +++ b/tests/ui/empty_enum.rs @@ -7,14 +7,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(dead_code)] #![warn(clippy::empty_enum)] enum Empty {} -fn main() { -} +fn main() {} diff --git a/tests/ui/entry.rs b/tests/ui/entry.rs index 0ee6d799222..6c826716650 100644 --- a/tests/ui/entry.rs +++ b/tests/ui/entry.rs @@ -7,11 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(unused, clippy::needless_pass_by_value)] - #![warn(clippy::map_entry)] use std::collections::{BTreeMap, HashMap}; @@ -20,36 +16,65 @@ fn foo() {} fn insert_if_absent0(m: &mut HashMap, k: K, v: V) { - if !m.contains_key(&k) { m.insert(k, v); } + if !m.contains_key(&k) { + m.insert(k, v); + } } fn insert_if_absent1(m: &mut HashMap, k: K, v: V) { - if !m.contains_key(&k) { foo(); m.insert(k, v); } + if !m.contains_key(&k) { + foo(); + m.insert(k, v); + } } fn insert_if_absent2(m: &mut HashMap, k: K, v: V) { - if !m.contains_key(&k) { m.insert(k, v) } else { None }; + if !m.contains_key(&k) { + m.insert(k, v) + } else { + None + }; } fn insert_if_present2(m: &mut HashMap, k: K, v: V) { - if m.contains_key(&k) { None } else { m.insert(k, v) }; + if m.contains_key(&k) { + None + } else { + m.insert(k, v) + }; } fn insert_if_absent3(m: &mut HashMap, k: K, v: V) { - if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None }; + if !m.contains_key(&k) { + foo(); + m.insert(k, v) + } else { + None + }; } fn insert_if_present3(m: &mut HashMap, k: K, v: V) { - if m.contains_key(&k) { None } else { foo(); m.insert(k, v) }; + if m.contains_key(&k) { + None + } else { + foo(); + m.insert(k, v) + }; } fn insert_in_btreemap(m: &mut BTreeMap, k: K, v: V) { - if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None }; + if !m.contains_key(&k) { + foo(); + m.insert(k, v) + } else { + None + }; } fn insert_other_if_absent(m: &mut HashMap, k: K, o: K, v: V) { - if !m.contains_key(&k) { m.insert(o, v); } + if !m.contains_key(&k) { + m.insert(o, v); + } } -fn main() { -} +fn main() {} diff --git a/tests/ui/enum_glob_use.rs b/tests/ui/enum_glob_use.rs index 9b7d4518c66..dde2896e415 100644 --- a/tests/ui/enum_glob_use.rs +++ b/tests/ui/enum_glob_use.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::all, clippy::pedantic)] #![allow(unused_imports, dead_code, clippy::missing_docs_in_private_items)] @@ -34,8 +31,7 @@ mod tests { } #[allow(non_snake_case)] -mod CamelCaseName { -} +mod CamelCaseName {} use CamelCaseName::*; diff --git a/tests/ui/enum_variants.rs b/tests/ui/enum_variants.rs index 34c69854b75..0c8f3a36a3d 100644 --- a/tests/ui/enum_variants.rs +++ b/tests/ui/enum_variants.rs @@ -7,19 +7,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![feature(non_ascii_idents)] - #![warn(clippy::all, clippy::pub_enum_variant_names)] enum FakeCallType { - CALL, CREATE + CALL, + CREATE, } enum FakeCallType2 { - CALL, CREATELL + CALL, + CREATELL, } enum Foo { @@ -49,7 +47,8 @@ enum BadCallType { CallTypeDestroy, } -enum TwoCallType { // no error +enum TwoCallType { + // no error CallTypeCall, CallTypeCreate, } @@ -60,7 +59,8 @@ enum Consts { ConstantLie, } -enum Two { // no error here +enum Two { + // no error here ConstantInt, ConstantInfer, } diff --git a/tests/ui/enums_clike.rs b/tests/ui/enums_clike.rs index 5513a9506aa..9c1cf8e8614 100644 --- a/tests/ui/enums_clike.rs +++ b/tests/ui/enums_clike.rs @@ -7,14 +7,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - // ignore-x86 - #![warn(clippy::all)] - #![allow(unused)] #[repr(usize)] @@ -62,5 +57,4 @@ trait Trait { } */ -fn main() { -} +fn main() {} diff --git a/tests/ui/erasing_op.rs b/tests/ui/erasing_op.rs index 696c58f98ae..d7166213194 100644 --- a/tests/ui/erasing_op.rs +++ b/tests/ui/erasing_op.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[allow(clippy::no_effect)] #[warn(clippy::erasing_op)] fn main() { diff --git a/tests/ui/escape_analysis.rs b/tests/ui/escape_analysis.rs index b35071546e7..cc65c6e6306 100644 --- a/tests/ui/escape_analysis.rs +++ b/tests/ui/escape_analysis.rs @@ -8,7 +8,6 @@ // except according to those terms. #![feature(box_syntax)] - #![allow(clippy::borrowed_box, clippy::needless_pass_by_value, clippy::unused_unit)] #![warn(clippy::boxed_local)] @@ -16,7 +15,7 @@ struct A; impl A { - fn foo(&self){} + fn foo(&self) {} } trait Z { @@ -29,8 +28,7 @@ fn bar(&self) { } } -fn main() { -} +fn main() {} fn ok_box_trait(boxed_trait: &Box) { let boxed_local = boxed_trait; @@ -85,11 +83,9 @@ fn nowarn_pass() { take_box(&bx); // fn needs &Box } - fn take_box(x: &Box) {} fn take_ref(x: &A) {} - fn nowarn_ref_take() { // false positive, should actually warn let x = box A; @@ -100,14 +96,15 @@ fn nowarn_ref_take() { fn nowarn_match() { let x = box A; // moved into a match match x { - y => drop(y) + y => drop(y), } } fn warn_match() { let x = box A; - match &x { // not moved - ref y => () + match &x { + // not moved + ref y => (), } } @@ -115,12 +112,12 @@ fn nowarn_large_array() { // should not warn, is large array // and should not be on stack let x = box [1; 10000]; - match &x { // not moved - ref y => () + match &x { + // not moved + ref y => (), } } - /// ICE regression test pub trait Foo { type Item; @@ -134,8 +131,7 @@ pub struct PeekableSeekable { _peeked: I::Item, } -pub fn new(_needs_name: Box>) -> () { -} +pub fn new(_needs_name: Box>) -> () {} /// Regression for #916, #1123 /// diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index dd41433d2db..7b39d1c4054 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -7,10 +7,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - -#![allow(unused, clippy::no_effect, clippy::redundant_closure_call, clippy::many_single_char_names, clippy::needless_pass_by_value, clippy::option_map_unit_fn, clippy::trivially_copy_pass_by_ref)] +#![allow( + unused, + clippy::no_effect, + clippy::redundant_closure_call, + clippy::many_single_char_names, + clippy::needless_pass_by_value, + clippy::option_map_unit_fn, + clippy::trivially_copy_pass_by_ref +)] #![warn(clippy::redundant_closure, clippy::needless_borrow)] fn main() { @@ -32,25 +37,31 @@ fn main() { Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref> { Box::new(v) }); } -fn meta(f: F) where F: Fn(u8) { +fn meta(f: F) +where + F: Fn(u8), +{ f(1u8) } -fn foo(_: u8) { -} +fn foo(_: u8) {} fn foo2(_: u8) -> u8 { 1u8 } fn all(x: &[X], y: &X, f: F) -> bool -where F: Fn(&X, &X) -> bool { +where + F: Fn(&X, &X) -> bool, +{ x.iter().all(|e| f(e, y)) } -fn below(x: &u8, y: &u8) -> bool { x < y } +fn below(x: &u8, y: &u8) -> bool { + x < y +} -unsafe fn unsafe_fn(_: u8) { } +unsafe fn unsafe_fn(_: u8) {} fn divergent(_: u8) -> ! { unimplemented!() diff --git a/tests/ui/eval_order_dependence.rs b/tests/ui/eval_order_dependence.rs index ee8f834fe56..82110d5e4f3 100644 --- a/tests/ui/eval_order_dependence.rs +++ b/tests/ui/eval_order_dependence.rs @@ -7,52 +7,112 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[warn(clippy::eval_order_dependence)] -#[allow(unused_assignments, unused_variables, clippy::many_single_char_names, clippy::no_effect, dead_code, clippy::blacklisted_name)] +#[allow( + unused_assignments, + unused_variables, + clippy::many_single_char_names, + clippy::no_effect, + dead_code, + clippy::blacklisted_name +)] fn main() { let mut x = 0; - let a = { x = 1; 1 } + x; + let a = { + x = 1; + 1 + } + x; // Example from iss#277 - x += { x = 20; 2 }; + x += { + x = 20; + 2 + }; // Does it work in weird places? // ...in the base for a struct expression? - struct Foo { a: i32, b: i32 }; + struct Foo { + a: i32, + b: i32, + }; let base = Foo { a: 4, b: 5 }; - let foo = Foo { a: x, .. { x = 6; base } }; + let foo = Foo { + a: x, + ..{ + x = 6; + base + } + }; // ...inside a closure? let closure = || { let mut x = 0; - x += { x = 20; 2 }; + x += { + x = 20; + 2 + }; }; // ...not across a closure? let mut y = 0; - let b = (y, || { y = 1 }); + let b = (y, || y = 1); // && and || evaluate left-to-right. - let a = { x = 1; true } && (x == 3); - let a = { x = 1; true } || (x == 3); + let a = { + x = 1; + true + } && (x == 3); + let a = { + x = 1; + true + } || (x == 3); // Make sure we don't get confused by alpha conversion. - let a = { let mut x = 1; x = 2; 1 } + x; + let a = { + let mut x = 1; + x = 2; + 1 + } + x; // No warning if we don't read the variable... - x = { x = 20; 2 }; + x = { + x = 20; + 2 + }; // ...if the assignment is in a closure... - let b = { || { x = 1; }; 1 } + x; + let b = { + || { + x = 1; + }; + 1 + } + x; // ... or the access is under an address. - let b = ({ let p = &x; 1 }, { x = 1; x }); + let b = ( + { + let p = &x; + 1 + }, + { + x = 1; + x + }, + ); // Limitation: l-values other than simple variables don't trigger // the warning. let mut tup = (0, 0); - let c = { tup.0 = 1; 1 } + tup.0; + let c = { + tup.0 = 1; + 1 + } + tup.0; // Limitation: you can get away with a read under address-of. let mut z = 0; - let b = (&{ z = x; x }, { x = 3; x }); + let b = ( + &{ + z = x; + x + }, + { + x = 3; + x + }, + ); } diff --git a/tests/ui/excessive_precision.rs b/tests/ui/excessive_precision.rs index 5945298da9f..59b252a3a80 100644 --- a/tests/ui/excessive_precision.rs +++ b/tests/ui/excessive_precision.rs @@ -7,8 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - #![warn(clippy::excessive_precision)] #![allow(clippy::print_literal)] diff --git a/tests/ui/expect_fun_call.rs b/tests/ui/expect_fun_call.rs index cf764c43694..8afffa4d843 100644 --- a/tests/ui/expect_fun_call.rs +++ b/tests/ui/expect_fun_call.rs @@ -16,7 +16,9 @@ fn expect_fun_call() { struct Foo; impl Foo { - fn new() -> Self { Foo } + fn new() -> Self { + Foo + } fn expect(&self, msg: &str) { panic!("{}", msg) diff --git a/tests/ui/explicit_counter_loop.rs b/tests/ui/explicit_counter_loop.rs index eaed606b89e..75d905659d9 100644 --- a/tests/ui/explicit_counter_loop.rs +++ b/tests/ui/explicit_counter_loop.rs @@ -26,9 +26,11 @@ fn main() { mod issue_1219 { pub fn test() { // should not trigger the lint because variable is used after the loop #473 - let vec = vec![1,2,3]; + let vec = vec![1, 2, 3]; let mut index = 0; - for _v in &vec { index += 1 } + for _v in &vec { + index += 1 + } println!("index: {}", index); // should not trigger the lint because the count is conditional #1219 diff --git a/tests/ui/explicit_write.rs b/tests/ui/explicit_write.rs index 8c1e35daa48..10a4bca9f49 100644 --- a/tests/ui/explicit_write.rs +++ b/tests/ui/explicit_write.rs @@ -7,12 +7,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::explicit_write)] - fn stdout() -> String { String::new() } diff --git a/tests/ui/fallible_impl_from.rs b/tests/ui/fallible_impl_from.rs index f50d5999de6..0d8c369660b 100644 --- a/tests/ui/fallible_impl_from.rs +++ b/tests/ui/fallible_impl_from.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::fallible_impl_from)] // docs example @@ -20,7 +17,6 @@ fn from(s: String) -> Self { } } - struct Valid(Vec); impl<'a> From<&'a str> for Valid { @@ -34,7 +30,6 @@ fn from(i: usize) -> Valid { } } - struct Invalid; impl From for Invalid { diff --git a/tests/ui/filter_methods.rs b/tests/ui/filter_methods.rs index 33441d728ca..7ca74fd4b99 100644 --- a/tests/ui/filter_methods.rs +++ b/tests/ui/filter_methods.rs @@ -7,31 +7,27 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::missing_docs_in_private_items)] fn main() { - let _: Vec<_> = vec![5; 6].into_iter() - .filter(|&x| x == 0) - .map(|x| x * 2) - .collect(); + let _: Vec<_> = vec![5; 6].into_iter().filter(|&x| x == 0).map(|x| x * 2).collect(); - let _: Vec<_> = vec![5_i8; 6].into_iter() - .filter(|&x| x == 0) - .flat_map(|x| x.checked_mul(2)) - .collect(); + let _: Vec<_> = vec![5_i8; 6] + .into_iter() + .filter(|&x| x == 0) + .flat_map(|x| x.checked_mul(2)) + .collect(); - let _: Vec<_> = vec![5_i8; 6].into_iter() - .filter_map(|x| x.checked_mul(2)) - .flat_map(|x| x.checked_mul(2)) - .collect(); + let _: Vec<_> = vec![5_i8; 6] + .into_iter() + .filter_map(|x| x.checked_mul(2)) + .flat_map(|x| x.checked_mul(2)) + .collect(); - let _: Vec<_> = vec![5_i8; 6].into_iter() - .filter_map(|x| x.checked_mul(2)) - .map(|x| x.checked_mul(2)) - .collect(); + let _: Vec<_> = vec![5_i8; 6] + .into_iter() + .filter_map(|x| x.checked_mul(2)) + .map(|x| x.checked_mul(2)) + .collect(); } diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index 5619539fb5a..2d55e30a2d3 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -7,31 +7,41 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::float_cmp)] #![allow(unused, clippy::no_effect, clippy::unnecessary_operation, clippy::cast_lossless)] use std::ops::Add; -const ZERO : f32 = 0.0; -const ONE : f32 = ZERO + 1.0; +const ZERO: f32 = 0.0; +const ONE: f32 = ZERO + 1.0; -fn twice(x : T) -> T where T : Add, T : Copy { +fn twice(x: T) -> T +where + T: Add, + T: Copy, +{ x + x } fn eq_fl(x: f32, y: f32) -> bool { - if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn + if x.is_nan() { + y.is_nan() + } else { + x == y + } // no error, inside "eq" fn } fn fl_eq(x: f32, y: f32) -> bool { - if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn + if x.is_nan() { + y.is_nan() + } else { + x == y + } // no error, inside "eq" fn } -struct X { val: f32 } +struct X { + val: f32, +} impl PartialEq for X { fn eq(&self, o: &X) -> bool { @@ -59,7 +69,7 @@ fn main() { ONE as f64 != 2.0; ONE as f64 != 0.0; // no error, comparison with zero is ok - let x : f64 = 1.0; + let x: f64 = 1.0; x == 1.0; x != 0f64; // no error, comparison with zero is ok @@ -71,7 +81,7 @@ fn main() { x <= 0.0; x >= 0.0; - let xs : [f32; 1] = [0.0]; + let xs: [f32; 1] = [0.0]; let a: *const f32 = xs.as_ptr(); let b: *const f32 = xs.as_ptr(); diff --git a/tests/ui/float_cmp_const.rs b/tests/ui/float_cmp_const.rs index 7cca1df65ae..e02671e0dcc 100644 --- a/tests/ui/float_cmp_const.rs +++ b/tests/ui/float_cmp_const.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::float_cmp_const)] #![allow(clippy::float_cmp)] #![allow(unused, clippy::no_effect, clippy::unnecessary_operation)] @@ -19,7 +15,11 @@ const TWO: f32 = 2.0; fn eq_one(x: f32) -> bool { - if x.is_nan() { false } else { x == ONE } // no error, inside "eq" fn + if x.is_nan() { + false + } else { + x == ONE + } // no error, inside "eq" fn } fn main() { diff --git a/tests/ui/fn_to_numeric_cast.rs b/tests/ui/fn_to_numeric_cast.rs index 50796e13ef6..9b48a965cb3 100644 --- a/tests/ui/fn_to_numeric_cast.rs +++ b/tests/ui/fn_to_numeric_cast.rs @@ -7,13 +7,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - // only-64bit - #![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] -fn foo() -> String { String::new() } +fn foo() -> String { + String::new() +} fn test_function_to_numeric_cast() { let _ = foo as i8; diff --git a/tests/ui/for_loop.rs b/tests/ui/for_loop.rs index 513a3c0ee42..4747269bccd 100644 --- a/tests/ui/for_loop.rs +++ b/tests/ui/for_loop.rs @@ -25,10 +25,22 @@ fn iter(&self) -> std::slice::Iter { } } -#[warn(clippy::needless_range_loop, clippy::explicit_iter_loop, clippy::explicit_into_iter_loop, clippy::iter_next_loop, clippy::reverse_range_loop, - clippy::for_kv_map)] +#[warn( + clippy::needless_range_loop, + clippy::explicit_iter_loop, + clippy::explicit_into_iter_loop, + clippy::iter_next_loop, + clippy::reverse_range_loop, + clippy::for_kv_map +)] #[warn(clippy::unused_collect)] -#[allow(clippy::linkedlist, clippy::shadow_unrelated, clippy::unnecessary_mut_passed, clippy::cyclomatic_complexity, clippy::similar_names)] +#[allow( + clippy::linkedlist, + clippy::shadow_unrelated, + clippy::unnecessary_mut_passed, + clippy::cyclomatic_complexity, + clippy::similar_names +)] #[allow(clippy::many_single_char_names, unused_variables, clippy::into_iter_on_array)] fn main() { const MAX_LEN: usize = 42; diff --git a/tests/ui/formatting.rs b/tests/ui/formatting.rs index 88f6e497d12..875a74d2508 100644 --- a/tests/ui/formatting.rs +++ b/tests/ui/formatting.rs @@ -7,59 +7,57 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::all)] #![allow(unused_variables)] #![allow(unused_assignments)] #![allow(clippy::if_same_then_else)] #![allow(clippy::deref_addrof)] -fn foo() -> bool { true } +fn foo() -> bool { + true +} fn main() { // weird `else if` formatting: - if foo() { - } if foo() { - } + if foo() {} + if foo() {} - let _ = { // if as the last expression + let _ = { + // if as the last expression let _ = 0; + if foo() {} if foo() { - } if foo() { - } - else { + } else { } }; - let _ = { // if in the middle of a block + let _ = { + // if in the middle of a block + if foo() {} if foo() { - } if foo() { - } - else { + } else { } let _ = 0; }; if foo() { - } else - if foo() { // the span of the above error should continue here + } else if foo() { + // the span of the above error should continue here } if foo() { - } - else - if foo() { // the span of the above error should continue here + } else if foo() { + // the span of the above error should continue here } // those are ok: + if foo() {} + if foo() {} + if foo() { - } - if foo() { + } else if foo() { } if foo() { @@ -67,22 +65,16 @@ fn main() { } if foo() { + } else if foo() { } - else if foo() { - } - - if foo() { - } - else if - foo() {} // weird op_eq formatting: let mut a = 42; - a =- 35; - a =* &191; + a = -35; + a = *&191; let mut b = true; - b =! false; + b = !false; // those are ok: a = -35; @@ -91,37 +83,30 @@ fn main() { // possible missing comma in an array let _ = &[ - -1, -2, -3 // <= no comma here - -4, -5, -6 + -1, + -2, + -3 // <= no comma here + -4, + -5, + -6, ]; let _ = &[ - -1, -2, -3 // <= no comma here - *4, -5, -6 + -1, + -2, + -3 // <= no comma here + *4, + -5, + -6, ]; // those are ok: - let _ = &[ - -1, -2, -3, - -4, -5, -6 - ]; - let _ = &[ - -1, -2, -3, - -4, -5, -6, - ]; - let _ = &[ - 1 + 2, 3 + - 4, 5 + 6, - ]; + let _ = &[-1, -2, -3, -4, -5, -6]; + let _ = &[-1, -2, -3, -4, -5, -6]; + let _ = &[1 + 2, 3 + 4, 5 + 6]; // don't lint for bin op without unary equiv // issue 3244 - vec![ - 1 - / 2, - ]; + vec![1 / 2]; // issue 3396 - vec![ - true - | false, - ]; + vec![true | false]; } diff --git a/tests/ui/functions.rs b/tests/ui/functions.rs index f5ba0f791ee..41963294815 100644 --- a/tests/ui/functions.rs +++ b/tests/ui/functions.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::all)] #![allow(dead_code)] #![allow(unused_unsafe)] @@ -18,11 +14,20 @@ // TOO_MANY_ARGUMENTS fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {} -fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) { -} +fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} // don't lint extern fns -extern fn extern_fn(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} +extern "C" fn extern_fn( + _one: u32, + _two: u32, + _three: &str, + _four: bool, + _five: f32, + _six: f32, + _seven: bool, + _eight: (), +) { +} pub trait Foo { fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool); diff --git a/tests/ui/fxhash.rs b/tests/ui/fxhash.rs index fe4b80807c0..2299714132f 100644 --- a/tests/ui/fxhash.rs +++ b/tests/ui/fxhash.rs @@ -7,16 +7,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::default_hash_types)] #![feature(rustc_private)] extern crate rustc_data_structures; -use std::collections::{HashMap, HashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use std::collections::{HashMap, HashSet}; fn main() { let _map: HashMap = HashMap::default(); diff --git a/tests/ui/get_unwrap.rs b/tests/ui/get_unwrap.rs index 7b672c0748c..e8789db6fc1 100644 --- a/tests/ui/get_unwrap.rs +++ b/tests/ui/get_unwrap.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![allow(unused_mut)] use std::collections::BTreeMap; @@ -20,8 +19,12 @@ struct GetFalsePositive { } impl GetFalsePositive { - fn get(&self, pos: usize) -> Option<&u32> { self.arr.get(pos) } - fn get_mut(&mut self, pos: usize) -> Option<&mut u32> { self.arr.get_mut(pos) } + fn get(&self, pos: usize) -> Option<&u32> { + self.arr.get(pos) + } + fn get_mut(&mut self, pos: usize) -> Option<&mut u32> { + self.arr.get_mut(pos) + } } fn main() { @@ -33,7 +36,8 @@ fn main() { let mut some_btreemap: BTreeMap = BTreeMap::from_iter(vec![(1, 'a'), (2, 'b')]); let mut false_positive = GetFalsePositive { arr: [0, 1, 2] }; - { // Test `get().unwrap()` + { + // Test `get().unwrap()` let _ = boxed_slice.get(1).unwrap(); let _ = some_slice.get(0).unwrap(); let _ = some_vec.get(0).unwrap(); @@ -43,7 +47,8 @@ fn main() { let _ = false_positive.get(0).unwrap(); } - { // Test `get_mut().unwrap()` + { + // Test `get_mut().unwrap()` *boxed_slice.get_mut(0).unwrap() = 1; *some_slice.get_mut(0).unwrap() = 1; *some_vec.get_mut(0).unwrap() = 1; @@ -54,7 +59,8 @@ fn main() { *false_positive.get_mut(0).unwrap() = 1; } - { // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` + { + // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` let _ = some_vec.get(0..1).unwrap().to_vec(); let _ = some_vec.get_mut(0..1).unwrap().to_vec(); } diff --git a/tests/ui/ice-2636.rs b/tests/ui/ice-2636.rs index 3ef9ea8f69f..caf8c89390d 100644 --- a/tests/ui/ice-2636.rs +++ b/tests/ui/ice-2636.rs @@ -29,4 +29,3 @@ fn main() { let a = Foo::A; test_hash!(&a, A => 0, B => 1, C => 2); } - diff --git a/tests/ui/identity_conversion.rs b/tests/ui/identity_conversion.rs index b5cb92c6d5a..6ba191b0b84 100644 --- a/tests/ui/identity_conversion.rs +++ b/tests/ui/identity_conversion.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::identity_conversion)] fn test_generic(val: T) -> T { diff --git a/tests/ui/identity_op.rs b/tests/ui/identity_op.rs index 07a4ef8f3eb..c8874250a04 100644 --- a/tests/ui/identity_op.rs +++ b/tests/ui/identity_op.rs @@ -7,15 +7,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +const ONE: i64 = 1; +const NEG_ONE: i64 = -1; +const ZERO: i64 = 0; - - - -const ONE : i64 = 1; -const NEG_ONE : i64 = -1; -const ZERO : i64 = 0; - -#[allow(clippy::eq_op, clippy::no_effect, clippy::unnecessary_operation, clippy::double_parens)] +#[allow( + clippy::eq_op, + clippy::no_effect, + clippy::unnecessary_operation, + clippy::double_parens +)] #[warn(clippy::identity_op)] fn main() { let x = 0; @@ -25,19 +26,19 @@ fn main() { x + 1; 0 + x; 1 + x; - x - ZERO; //no error, as we skip lookups (for now) + x - ZERO; //no error, as we skip lookups (for now) x | (0); - ((ZERO)) | x; //no error, as we skip lookups (for now) + (ZERO) | x; //no error, as we skip lookups (for now) x * 1; 1 * x; - x / ONE; //no error, as we skip lookups (for now) + x / ONE; //no error, as we skip lookups (for now) - x / 2; //no false positive + x / 2; //no false positive - x & NEG_ONE; //no error, as we skip lookups (for now) + x & NEG_ONE; //no error, as we skip lookups (for now) -1 & x; - let u : u8 = 0; + let u: u8 = 0; u & 255; } diff --git a/tests/ui/if_not_else.rs b/tests/ui/if_not_else.rs index 23895c0ab52..0179381fdc3 100644 --- a/tests/ui/if_not_else.rs +++ b/tests/ui/if_not_else.rs @@ -7,13 +7,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::all)] #![warn(clippy::if_not_else)] -fn bla() -> bool { unimplemented!() } +fn bla() -> bool { + unimplemented!() +} fn main() { if !bla() { diff --git a/tests/ui/impl.rs b/tests/ui/impl.rs index 38c0a484091..398a8ccce44 100644 --- a/tests/ui/impl.rs +++ b/tests/ui/impl.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(dead_code)] #![warn(clippy::multiple_inherent_impl)] diff --git a/tests/ui/implicit_hasher.rs b/tests/ui/implicit_hasher.rs index a6be909c0cc..ddcd8bcd755 100644 --- a/tests/ui/implicit_hasher.rs +++ b/tests/ui/implicit_hasher.rs @@ -7,12 +7,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![allow(unused)] -use std::collections::{HashMap, HashSet}; use std::cmp::Eq; -use std::hash::{Hash, BuildHasher}; +use std::collections::{HashMap, HashSet}; +use std::hash::{BuildHasher, Hash}; pub trait Foo: Sized { fn make() -> (Self, Self); @@ -49,7 +48,6 @@ fn make() -> (Self, Self) { } } - impl Foo for HashSet { fn make() -> (Self, Self) { (HashSet::new(), HashSet::with_capacity(10)) @@ -72,8 +70,7 @@ fn make() -> (Self, Self) { } } -pub fn foo(_map: &mut HashMap, _set: &mut HashSet) { -} +pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} macro_rules! gen { (impl) => { @@ -85,19 +82,19 @@ fn make() -> (Self, Self) { }; (fn $name:ident) => { - pub fn $name(_map: &mut HashMap, _set: &mut HashSet) { - } - } + pub fn $name(_map: &mut HashMap, _set: &mut HashSet) {} + }; } -gen!(impl); +gen!(impl ); gen!(fn bar); // When the macro is in a different file, the suggestion spans can't be combined properly // and should not cause an ICE // See #2707 #[macro_use] -#[path = "../auxiliary/test_macro.rs"] pub mod test_macro; +#[path = "../auxiliary/test_macro.rs"] +pub mod test_macro; __implicit_hasher_test_macro!(impl for HashMap where V: test_macro::A); fn main() {} diff --git a/tests/ui/implicit_return.rs b/tests/ui/implicit_return.rs index 73cf2908833..3bff92cf492 100644 --- a/tests/ui/implicit_return.rs +++ b/tests/ui/implicit_return.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::implicit_return)] fn test_end_of_fn() -> bool { @@ -34,9 +30,7 @@ fn test_if_block() -> bool { fn test_match(x: bool) -> bool { match x { true => false, - false => { - true - } + false => true, } } @@ -48,9 +42,7 @@ fn test_loop() -> bool { } fn test_closure() { - let _ = || { - true - }; + let _ = || true; let _ = || true; } diff --git a/tests/ui/inconsistent_digit_grouping.rs b/tests/ui/inconsistent_digit_grouping.rs index 941fbe5154a..31e34135bfc 100644 --- a/tests/ui/inconsistent_digit_grouping.rs +++ b/tests/ui/inconsistent_digit_grouping.rs @@ -7,12 +7,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #[warn(clippy::inconsistent_digit_grouping)] #[allow(unused_variables)] fn main() { - let good = (123, 1_234, 1_2345_6789, 123_f32, 1_234.12_f32, 1_234.123_4_f32, 1.123_456_7_f32); + let good = ( + 123, + 1_234, + 1_2345_6789, + 123_f32, + 1_234.12_f32, + 1_234.123_4_f32, + 1.123_456_7_f32, + ); let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); } diff --git a/tests/ui/indexing_slicing.rs b/tests/ui/indexing_slicing.rs index ff154091bb8..a9e697e519f 100644 --- a/tests/ui/indexing_slicing.rs +++ b/tests/ui/indexing_slicing.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![feature(plugin)] #![warn(clippy::indexing_slicing)] #![warn(clippy::out_of_bounds_indexing)] diff --git a/tests/ui/infallible_destructuring_match.rs b/tests/ui/infallible_destructuring_match.rs index 62036cbc107..37ae19497d1 100644 --- a/tests/ui/infallible_destructuring_match.rs +++ b/tests/ui/infallible_destructuring_match.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![feature(exhaustive_patterns, never_type)] #![allow(clippy::let_and_return)] diff --git a/tests/ui/infinite_iter.rs b/tests/ui/infinite_iter.rs index 68c10acb2be..8f41e3ae98d 100644 --- a/tests/ui/infinite_iter.rs +++ b/tests/ui/infinite_iter.rs @@ -7,12 +7,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - use std::iter::repeat; #[allow(clippy::trivially_copy_pass_by_ref)] -fn square_is_lower_64(x: &u32) -> bool { x * x < 64 } +fn square_is_lower_64(x: &u32) -> bool { + x * x < 64 +} #[allow(clippy::maybe_infinite_iter)] #[deny(clippy::infinite_iter)] @@ -20,10 +19,17 @@ fn infinite_iters() { repeat(0_u8).collect::>(); // infinite iter (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter (0..8_u64).chain(0..).max(); // infinite iter - (0_usize..).chain([0usize, 1, 2].iter().cloned()).skip_while(|x| *x != 42).min(); // infinite iter - (0..8_u32).rev().cycle().map(|x| x + 1_u32).for_each(|x| println!("{}", x)); // infinite iter + (0_usize..) + .chain([0usize, 1, 2].iter().cloned()) + .skip_while(|x| *x != 42) + .min(); // infinite iter + (0..8_u32) + .rev() + .cycle() + .map(|x| x + 1_u32) + .for_each(|x| println!("{}", x)); // infinite iter (0..3_u32).flat_map(|x| x..).sum::(); // infinite iter - (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter + (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter (0..42_u64).by_ref().last(); // not an infinite, because ranges are double-ended (0..).next(); // iterator is not exhausted @@ -33,7 +39,12 @@ fn infinite_iters() { fn potential_infinite_iters() { (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter - (1..).scan(0, |state, x| { *state += x; Some(*state) }).min(); // maybe infinite iter + (1..) + .scan(0, |state, x| { + *state += x; + Some(*state) + }) + .min(); // maybe infinite iter (0..).find(|x| *x == 24); // maybe infinite iter (0..).position(|x| x == 24); // maybe infinite iter (0..).any(|x| x == 24); // maybe infinite iter diff --git a/tests/ui/infinite_loop.rs b/tests/ui/infinite_loop.rs index 869b34e8ade..f9310321593 100644 --- a/tests/ui/infinite_loop.rs +++ b/tests/ui/infinite_loop.rs @@ -7,17 +7,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(clippy::trivially_copy_pass_by_ref)] - -fn fn_val(i: i32) -> i32 { unimplemented!() } -fn fn_constref(i: &i32) -> i32 { unimplemented!() } -fn fn_mutref(i: &mut i32) { unimplemented!() } -fn fooi() -> i32 { unimplemented!() } -fn foob() -> bool { unimplemented!() } +fn fn_val(i: i32) -> i32 { + unimplemented!() +} +fn fn_constref(i: &i32) -> i32 { + unimplemented!() +} +fn fn_mutref(i: &mut i32) { + unimplemented!() +} +fn fooi() -> i32 { + unimplemented!() +} +fn foob() -> bool { + unimplemented!() +} #[allow(clippy::many_single_char_names)] fn immutable_condition() { @@ -143,12 +149,15 @@ fn consts() { use std::cell::Cell; -fn maybe_i_mutate(i: &Cell) { unimplemented!() } +fn maybe_i_mutate(i: &Cell) { + unimplemented!() +} fn internally_mutable() { let b = Cell::new(true); - while b.get() { // b cannot be silently coerced to `bool` + while b.get() { + // b cannot be silently coerced to `bool` maybe_i_mutate(&b); println!("OK - Method call within condition"); } diff --git a/tests/ui/inline_fn_without_body.rs b/tests/ui/inline_fn_without_body.rs index 8434d33f65e..d97e6d69941 100644 --- a/tests/ui/inline_fn_without_body.rs +++ b/tests/ui/inline_fn_without_body.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::inline_fn_without_body)] #![allow(clippy::inline_always)] @@ -18,15 +14,14 @@ trait Foo { #[inline] fn default_inline(); - #[inline(always)]fn always_inline(); + #[inline(always)] + fn always_inline(); #[inline(never)] fn never_inline(); #[inline] - fn has_body() { - } + fn has_body() {} } -fn main() { -} +fn main() {} diff --git a/tests/ui/int_plus_one.rs b/tests/ui/int_plus_one.rs index 8a0405321d0..ce6cd7888ee 100644 --- a/tests/ui/int_plus_one.rs +++ b/tests/ui/int_plus_one.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[allow(clippy::no_effect, clippy::unnecessary_operation)] #[warn(clippy::int_plus_one)] fn main() { diff --git a/tests/ui/into_iter_on_ref.rs b/tests/ui/into_iter_on_ref.rs index 72aa6341a50..212234f0346 100644 --- a/tests/ui/into_iter_on_ref.rs +++ b/tests/ui/into_iter_on_ref.rs @@ -5,21 +5,21 @@ use std::collections::*; fn main() { - for _ in &[1,2,3] {} + for _ in &[1, 2, 3] {} for _ in vec![X, X] {} for _ in &vec![X, X] {} - for _ in [1,2,3].into_iter() {} //~ ERROR equivalent to .iter() + for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter() - let _ = [1,2,3].into_iter(); //~ ERROR equivalent to .iter() - let _ = vec![1,2,3].into_iter(); - let _ = (&vec![1,2,3]).into_iter(); //~ WARN equivalent to .iter() - let _ = vec![1,2,3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter() + let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter() + let _ = vec![1, 2, 3].into_iter(); + let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter() + let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter() let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() - let _ = (&&&&&&&[1,2,3]).into_iter(); //~ ERROR equivalent to .iter() - let _ = (&&&&mut &&&[1,2,3]).into_iter(); //~ ERROR equivalent to .iter() - let _ = (&mut &mut &mut [1,2,3]).into_iter(); //~ ERROR equivalent to .iter_mut() + let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() + let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() + let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter_mut() let _ = (&Some(4)).into_iter(); //~ WARN equivalent to .iter() let _ = (&mut Some(5)).into_iter(); //~ WARN equivalent to .iter_mut() diff --git a/tests/ui/invalid_ref.rs b/tests/ui/invalid_ref.rs index 9fb6c7fd4b7..0ec356280b6 100644 --- a/tests/ui/invalid_ref.rs +++ b/tests/ui/invalid_ref.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(unused)] #![feature(core_intrinsics)] @@ -18,8 +14,8 @@ use std::intrinsics::{init, uninit}; fn main() { - let x = 1; - unsafe { + let x = 1; + unsafe { ref_to_zeroed_std(&x); ref_to_zeroed_core(&x); ref_to_zeroed_intr(&x); @@ -34,43 +30,41 @@ fn main() { } unsafe fn ref_to_zeroed_std(t: &T) { - let ref_zero: &T = std::mem::zeroed(); // warning + let ref_zero: &T = std::mem::zeroed(); // warning } unsafe fn ref_to_zeroed_core(t: &T) { - let ref_zero: &T = core::mem::zeroed(); // warning + let ref_zero: &T = core::mem::zeroed(); // warning } unsafe fn ref_to_zeroed_intr(t: &T) { - let ref_zero: &T = std::intrinsics::init(); // warning + let ref_zero: &T = std::intrinsics::init(); // warning } unsafe fn ref_to_uninit_std(t: &T) { - let ref_uninit: &T = std::mem::uninitialized(); // warning + let ref_uninit: &T = std::mem::uninitialized(); // warning } unsafe fn ref_to_uninit_core(t: &T) { - let ref_uninit: &T = core::mem::uninitialized(); // warning + let ref_uninit: &T = core::mem::uninitialized(); // warning } unsafe fn ref_to_uninit_intr(t: &T) { - let ref_uninit: &T = std::intrinsics::uninit(); // warning + let ref_uninit: &T = std::intrinsics::uninit(); // warning } fn some_ref() { - let some_ref = &1; + let some_ref = &1; } unsafe fn std_zeroed_no_ref() { - let mem_zero: usize = std::mem::zeroed(); // no warning + let mem_zero: usize = std::mem::zeroed(); // no warning } unsafe fn core_zeroed_no_ref() { - let mem_zero: usize = core::mem::zeroed(); // no warning + let mem_zero: usize = core::mem::zeroed(); // no warning } unsafe fn intr_init_no_ref() { let mem_zero: usize = std::intrinsics::init(); // no warning } - - diff --git a/tests/ui/invalid_upcast_comparisons.rs b/tests/ui/invalid_upcast_comparisons.rs index 3e62f11006d..60f877b1ebe 100644 --- a/tests/ui/invalid_upcast_comparisons.rs +++ b/tests/ui/invalid_upcast_comparisons.rs @@ -7,14 +7,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::invalid_upcast_comparisons)] -#![allow(unused, clippy::eq_op, clippy::no_effect, clippy::unnecessary_operation, clippy::cast_lossless)] +#![allow( + unused, + clippy::eq_op, + clippy::no_effect, + clippy::unnecessary_operation, + clippy::cast_lossless +)] -fn mk_value() -> T { unimplemented!() } +fn mk_value() -> T { + unimplemented!() +} fn main() { let u32: u32 = mk_value(); @@ -55,7 +59,6 @@ fn main() { 1337 != (u8 as i32); 1337 != (u8 as u32); - // Those are Ok: (u8 as u32) > 20; 42 == (u8 as i32); diff --git a/tests/ui/issue-3145.rs b/tests/ui/issue-3145.rs index 74a11925a76..5c6392811b9 100644 --- a/tests/ui/issue-3145.rs +++ b/tests/ui/issue-3145.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - fn main() { println!("{}" a); //~ERROR expected token: `,` } diff --git a/tests/ui/issue_2356.rs b/tests/ui/issue_2356.rs index 070808f7b69..a54da0b6a96 100644 --- a/tests/ui/issue_2356.rs +++ b/tests/ui/issue_2356.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::while_let_on_iterator)] use std::iter::Iterator; diff --git a/tests/ui/item_after_statement.rs b/tests/ui/item_after_statement.rs index a4cc42f0d72..fca19350558 100644 --- a/tests/ui/item_after_statement.rs +++ b/tests/ui/item_after_statement.rs @@ -7,24 +7,27 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::items_after_statements)] fn ok() { - fn foo() { println!("foo"); } + fn foo() { + println!("foo"); + } foo(); } fn last() { foo(); - fn foo() { println!("foo"); } + fn foo() { + println!("foo"); + } } fn main() { foo(); - fn foo() { println!("foo"); } + fn foo() { + println!("foo"); + } foo(); } @@ -33,7 +36,9 @@ fn mac() { println!("{}", a); // do not lint this, because it needs to be after `a` macro_rules! b { - () => {{ a = 6 }} + () => {{ + a = 6 + }}; } b!(); println!("{}", a); diff --git a/tests/ui/large_digit_groups.rs b/tests/ui/large_digit_groups.rs index aad5c205041..80153efcb93 100644 --- a/tests/ui/large_digit_groups.rs +++ b/tests/ui/large_digit_groups.rs @@ -7,12 +7,25 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #[warn(clippy::large_digit_groups)] #[allow(unused_variables)] fn main() { - let good = (0b1011_i64, 0o1_234_u32, 0x1_234_567, 1_2345_6789, 1234_f32, 1_234.12_f32, 1_234.123_f32, 1.123_4_f32); - let bad = (0b1_10110_i64, 0x1_23456_78901_usize, 1_23456_f32, 1_23456.12_f32, 1_23456.12345_f32, 1_23456.12345_6_f32); + let good = ( + 0b1011_i64, + 0o1_234_u32, + 0x1_234_567, + 1_2345_6789, + 1234_f32, + 1_234.12_f32, + 1_234.123_f32, + 1.123_4_f32, + ); + let bad = ( + 0b1_10110_i64, + 0x1_23456_78901_usize, + 1_23456_f32, + 1_23456.12_f32, + 1_23456.12345_f32, + 1_23456.12345_6_f32, + ); } diff --git a/tests/ui/large_enum_variant.rs b/tests/ui/large_enum_variant.rs index 419cb0ab428..29a73e68d43 100644 --- a/tests/ui/large_enum_variant.rs +++ b/tests/ui/large_enum_variant.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(dead_code)] #![allow(unused_variables)] #![warn(clippy::large_enum_variant)] diff --git a/tests/ui/len_zero.rs b/tests/ui/len_zero.rs index bc82e0bca04..7f4ba4f1523 100644 --- a/tests/ui/len_zero.rs +++ b/tests/ui/len_zero.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::len_without_is_empty, clippy::len_zero)] #![allow(dead_code, unused)] diff --git a/tests/ui/let_if_seq.rs b/tests/ui/let_if_seq.rs index 080fa3b24b8..26fdc46ac17 100644 --- a/tests/ui/let_if_seq.rs +++ b/tests/ui/let_if_seq.rs @@ -7,15 +7,20 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - -#![allow(unused_variables, unused_assignments, clippy::similar_names, clippy::blacklisted_name)] +#![allow( + unused_variables, + unused_assignments, + clippy::similar_names, + clippy::blacklisted_name +)] #![warn(clippy::useless_let_if_seq)] -fn f() -> bool { true } -fn g(x: i32) -> i32 { x + 1 } +fn f() -> bool { + true +} +fn g(x: i32) -> i32 { + x + 1 +} fn issue985() -> i32 { let mut x = 42; @@ -73,8 +78,7 @@ fn main() { if f() { f(); bar = 42; - } - else { + } else { f(); } diff --git a/tests/ui/let_return.rs b/tests/ui/let_return.rs index 317aaf42b5c..eb012133376 100644 --- a/tests/ui/let_return.rs +++ b/tests/ui/let_return.rs @@ -7,11 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(unused)] - #![warn(clippy::let_and_return)] fn test() -> i32 { @@ -52,5 +48,4 @@ fn test_nowarn_4() -> i32 { x } -fn main() { -} +fn main() {} diff --git a/tests/ui/let_unit.rs b/tests/ui/let_unit.rs index d77bc8712bf..89cb190cc96 100644 --- a/tests/ui/let_unit.rs +++ b/tests/ui/let_unit.rs @@ -7,23 +7,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::let_unit_value)] #![allow(unused_variables)] macro_rules! let_and_return { ($n:expr) => {{ let ret = $n; - }} + }}; } fn main() { let _x = println!("x"); - let _y = 1; // this is fine - let _z = ((), 1); // this as well + let _y = 1; // this is fine + let _z = ((), 1); // this as well if true { let _a = (); } diff --git a/tests/ui/lifetimes.rs b/tests/ui/lifetimes.rs index 77f25afe023..110868404bd 100644 --- a/tests/ui/lifetimes.rs +++ b/tests/ui/lifetimes.rs @@ -7,63 +7,89 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::needless_lifetimes, clippy::extra_unused_lifetimes)] #![allow(dead_code, clippy::needless_pass_by_value, clippy::trivially_copy_pass_by_ref)] -fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) { } +fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} -fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) { } +fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {} -fn same_lifetime_on_input<'a>(_x: &'a u8, _y: &'a u8) { } // no error, same lifetime on two params +fn same_lifetime_on_input<'a>(_x: &'a u8, _y: &'a u8) {} // no error, same lifetime on two params -fn only_static_on_input(_x: &u8, _y: &u8, _z: &'static u8) { } // no error, static involved +fn only_static_on_input(_x: &u8, _y: &u8, _z: &'static u8) {} // no error, static involved -fn mut_and_static_input(_x: &mut u8, _y: &'static str) { } +fn mut_and_static_input(_x: &mut u8, _y: &'static str) {} -fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { x } +fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { + x +} -fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 { x } // no error, multiple input refs +fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 { + x +} // no error, multiple input refs -fn multiple_in_and_out_2<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { x } // no error, multiple input refs +fn multiple_in_and_out_2<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { + x +} // no error, multiple input refs -fn in_static_and_out<'a>(x: &'a u8, _y: &'static u8) -> &'a u8 { x } // no error, static involved +fn in_static_and_out<'a>(x: &'a u8, _y: &'static u8) -> &'a u8 { + x +} // no error, static involved -fn deep_reference_1<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { Ok(x) } // no error +fn deep_reference_1<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { + Ok(x) +} // no error -fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { x.unwrap() } // no error, two input refs +fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { + x.unwrap() +} // no error, two input refs -fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { Ok(x) } +fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { + Ok(x) +} // where clause, but without lifetimes -fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> where T: Copy { Ok(x) } +fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> +where + T: Copy, +{ + Ok(x) +} type Ref<'r> = &'r u8; -fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) { } // no error, same lifetime on two params +fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) {} // no error, same lifetime on two params -fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) { } +fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} -fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) { } // no error, bounded lifetime +fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) {} // no error, bounded lifetime -fn lifetime_param_4<'a, 'b>(_x: Ref<'a>, _y: &'b u8) where 'b: 'a { } // no error, bounded lifetime +fn lifetime_param_4<'a, 'b>(_x: Ref<'a>, _y: &'b u8) +where + 'b: 'a, +{ +} // no error, bounded lifetime struct Lt<'a, I: 'static> { - x: &'a I + x: &'a I, } fn fn_bound<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> - where F: Fn(Lt<'a, I>) -> Lt<'a, I> // no error, fn bound references 'a -{ unreachable!() } +where + F: Fn(Lt<'a, I>) -> Lt<'a, I>, // no error, fn bound references 'a +{ + unreachable!() +} fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> - where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I> -{ unreachable!() } +where + for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>, +{ + unreachable!() +} -fn fn_bound_3<'a, F: FnOnce(&'a i32)>(x: &'a i32, f: F) { // no error, see below +fn fn_bound_3<'a, F: FnOnce(&'a i32)>(x: &'a i32, f: F) { + // no error, see below f(x); } @@ -76,7 +102,11 @@ fn fn_bound_3_cannot_elide() { // no error, multiple input refs fn fn_bound_4<'a, F: FnOnce() -> &'a ()>(cond: bool, x: &'a (), f: F) -> &'a () { - if cond { x } else { f() } + if cond { + x + } else { + f() + } } struct X { @@ -84,13 +114,17 @@ struct X { } impl X { - fn self_and_out<'s>(&'s self) -> &'s u8 { &self.x } + fn self_and_out<'s>(&'s self) -> &'s u8 { + &self.x + } - fn self_and_in_out<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { &self.x } // no error, multiple input refs + fn self_and_in_out<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { + &self.x + } // no error, multiple input refs - fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) { } + fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} - fn self_and_same_in<'s>(&'s self, _x: &'s u8) { } // no error, same lifetimes on two params + fn self_and_same_in<'s>(&'s self, _x: &'s u8) {} // no error, same lifetimes on two params } struct Foo<'a>(&'a u8); @@ -104,50 +138,80 @@ fn already_elided<'a>(_: &u8, _: &'a u8) -> &'a u8 { unimplemented!() } -fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { unimplemented!() } +fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { + unimplemented!() +} // no warning, two input lifetimes (named on the reference, anonymous on Foo) -fn struct_with_lt2<'a>(_foo: &'a Foo) -> &'a str { unimplemented!() } +fn struct_with_lt2<'a>(_foo: &'a Foo) -> &'a str { + unimplemented!() +} // no warning, two input lifetimes (anonymous on the reference, named on Foo) -fn struct_with_lt3<'a>(_foo: &Foo<'a> ) -> &'a str { unimplemented!() } +fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { + unimplemented!() +} // no warning, two input lifetimes -fn struct_with_lt4<'a, 'b>(_foo: &'a Foo<'b> ) -> &'a str { unimplemented!() } +fn struct_with_lt4<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { + unimplemented!() +} trait WithLifetime<'a> {} type WithLifetimeAlias<'a> = WithLifetime<'a>; // should not warn because it won't build without the lifetime -fn trait_obj_elided<'a>(_arg: &'a WithLifetime) -> &'a str { unimplemented!() } +fn trait_obj_elided<'a>(_arg: &'a WithLifetime) -> &'a str { + unimplemented!() +} // this should warn because there is no lifetime on Drop, so this would be // unambiguous if we elided the lifetime -fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { unimplemented!() } +fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { + unimplemented!() +} type FooAlias<'a> = Foo<'a>; -fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() } +fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { + unimplemented!() +} // no warning, two input lifetimes (named on the reference, anonymous on Foo) -fn alias_with_lt2<'a>(_foo: &'a FooAlias) -> &'a str { unimplemented!() } +fn alias_with_lt2<'a>(_foo: &'a FooAlias) -> &'a str { + unimplemented!() +} // no warning, two input lifetimes (anonymous on the reference, named on Foo) -fn alias_with_lt3<'a>(_foo: &FooAlias<'a> ) -> &'a str { unimplemented!() } +fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { + unimplemented!() +} // no warning, two input lifetimes -fn alias_with_lt4<'a, 'b>(_foo: &'a FooAlias<'b> ) -> &'a str { unimplemented!() } +fn alias_with_lt4<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { + unimplemented!() +} -fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() } +fn named_input_elided_output<'a>(_arg: &'a str) -> &str { + unimplemented!() +} -fn elided_input_named_output<'a>(_arg: &str) -> &'a str { unimplemented!() } +fn elided_input_named_output<'a>(_arg: &str) -> &'a str { + unimplemented!() +} -fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() } -fn trait_bound<'a, T: WithLifetime<'a>>(_: &'a u8, _: T) { unimplemented!() } +fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { + unimplemented!() +} +fn trait_bound<'a, T: WithLifetime<'a>>(_: &'a u8, _: T) { + unimplemented!() +} // don't warn on these, see #292 -fn trait_bound_bug<'a, T: WithLifetime<'a>>() { unimplemented!() } +fn trait_bound_bug<'a, T: WithLifetime<'a>>() { + unimplemented!() +} // #740 struct Test { @@ -160,7 +224,6 @@ fn iter<'a>(&'a self) -> Box + 'a> { } } - trait LintContext<'a> {} fn f<'a, T: LintContext<'a>>(_: &T) {} @@ -172,9 +235,11 @@ fn test<'a>(x: &'a [u8]) -> u8 { // #3284 - Give a hint regarding lifetime in return type -struct Cow<'a> { x: &'a str, } -fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { unimplemented!() } - - -fn main() { +struct Cow<'a> { + x: &'a str, } +fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { + unimplemented!() +} + +fn main() {} diff --git a/tests/ui/lint_without_lint_pass.rs b/tests/ui/lint_without_lint_pass.rs index c7e11840a37..1f2fcd8faf6 100644 --- a/tests/ui/lint_without_lint_pass.rs +++ b/tests/ui/lint_without_lint_pass.rs @@ -1,5 +1,4 @@ #![deny(clippy::internal)] - #![feature(rustc_private)] #[macro_use] @@ -28,5 +27,4 @@ fn get_lints(&self) -> lint::LintArray { } } -fn main() { -} +fn main() {} diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index 162d8a484b4..e6fb37f8120 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -7,8 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::missing_docs_in_private_items)] diff --git a/tests/ui/map_flatten.rs b/tests/ui/map_flatten.rs index 1b5c20069d1..99b90a0df79 100644 --- a/tests/ui/map_flatten.rs +++ b/tests/ui/map_flatten.rs @@ -7,8 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::missing_docs_in_private_items)] diff --git a/tests/ui/match_bool.rs b/tests/ui/match_bool.rs index 7548b83764d..fe5e94cf458 100644 --- a/tests/ui/match_bool.rs +++ b/tests/ui/match_bool.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - fn match_bool() { let test: bool = true; @@ -24,31 +23,40 @@ fn match_bool() { match test { true => (), - false => { println!("Noooo!"); } + false => { + println!("Noooo!"); + }, }; match test { - false => { println!("Noooo!"); } + false => { + println!("Noooo!"); + }, _ => (), }; match test && test { - false => { println!("Noooo!"); } + false => { + println!("Noooo!"); + }, _ => (), }; match test { - false => { println!("Noooo!"); } - true => { println!("Yes!"); } + false => { + println!("Noooo!"); + }, + true => { + println!("Yes!"); + }, }; // Not linted match option { - 1 ... 10 => 1, - 11 ... 20 => 2, + 1...10 => 1, + 11...20 => 2, _ => 3, }; } -fn main() { -} +fn main() {} diff --git a/tests/ui/match_overlapping_arm.rs b/tests/ui/match_overlapping_arm.rs index 1f2c3f8a891..5350f933ae5 100644 --- a/tests/ui/match_overlapping_arm.rs +++ b/tests/ui/match_overlapping_arm.rs @@ -14,54 +14,54 @@ /// Tests for match_overlapping_arm fn overlapping() { - const FOO : u64 = 2; + const FOO: u64 = 2; match 42 { - 0 ... 10 => println!("0 ... 10"), - 0 ... 11 => println!("0 ... 11"), + 0...10 => println!("0 ... 10"), + 0...11 => println!("0 ... 11"), _ => (), } match 42 { - 0 ... 5 => println!("0 ... 5"), - 6 ... 7 => println!("6 ... 7"), - FOO ... 11 => println!("0 ... 11"), + 0...5 => println!("0 ... 5"), + 6...7 => println!("6 ... 7"), + FOO...11 => println!("0 ... 11"), _ => (), } match 42 { 2 => println!("2"), - 0 ... 5 => println!("0 ... 5"), + 0...5 => println!("0 ... 5"), _ => (), } match 42 { 2 => println!("2"), - 0 ... 2 => println!("0 ... 2"), + 0...2 => println!("0 ... 2"), _ => (), } match 42 { - 0 ... 10 => println!("0 ... 10"), - 11 ... 50 => println!("11 ... 50"), + 0...10 => println!("0 ... 10"), + 11...50 => println!("11 ... 50"), _ => (), } match 42 { 2 => println!("2"), - 0 .. 2 => println!("0 .. 2"), + 0..2 => println!("0 .. 2"), _ => (), } match 42 { - 0 .. 10 => println!("0 .. 10"), - 10 .. 50 => println!("10 .. 50"), + 0..10 => println!("0 .. 10"), + 10..50 => println!("10 .. 50"), _ => (), } match 42 { - 0 .. 11 => println!("0 .. 11"), - 0 ... 11 => println!("0 ... 11"), + 0..11 => println!("0 .. 11"), + 0...11 => println!("0 ... 11"), _ => (), } diff --git a/tests/ui/matches.rs b/tests/ui/matches.rs index e5b8f6f4c1c..8038433c564 100644 --- a/tests/ui/matches.rs +++ b/tests/ui/matches.rs @@ -7,18 +7,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - #![feature(exclusive_range_pattern)] - - #![warn(clippy::all)] #![allow(unused, clippy::redundant_pattern_matching)] #![warn(clippy::match_same_arms)] - -fn dummy() { -} +fn dummy() {} fn ref_pats() { { @@ -27,12 +21,13 @@ fn ref_pats() { &Some(v) => println!("{:?}", v), &None => println!("none"), } - match v { // this doesn't trigger, we have a different pattern + match v { + // this doesn't trigger, we have a different pattern &Some(v) => println!("some"), other => println!("other"), } } - let tup =& (1, 2); + let tup = &(1, 2); match tup { &(v, 1) => println!("{}", v), _ => println!("none"), @@ -66,73 +61,77 @@ fn match_wild_err_arm() { match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), - Err(_) => panic!("err") + Err(_) => panic!("err"), } match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), - Err(_) => {panic!()} + Err(_) => panic!(), } match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), - Err(_) => {panic!();} + Err(_) => { + panic!(); + }, } // allowed when not with `panic!` block match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), - Err(_) => println!("err") + Err(_) => println!("err"), } // allowed when used with `unreachable!` match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), - Err(_) => {unreachable!()} + Err(_) => unreachable!(), } match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), - Err(_) => unreachable!() + Err(_) => unreachable!(), } match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), - Err(_) => {unreachable!();} + Err(_) => { + unreachable!(); + }, } // no warning because of the guard match x { - Ok(x) if x*x == 64 => println!("ok"), + Ok(x) if x * x == 64 => println!("ok"), Ok(_) => println!("ok"), - Err(_) => println!("err") + Err(_) => println!("err"), } // this used to be a false positive, see #1996 match x { Ok(3) => println!("ok"), - Ok(x) if x*x == 64 => println!("ok 64"), + Ok(x) if x * x == 64 => println!("ok 64"), Ok(_) => println!("ok"), - Err(_) => println!("err") + Err(_) => println!("err"), } match (x, Some(1i32)) { (Ok(x), Some(_)) => println!("ok {}", x), (Ok(_), Some(x)) => println!("ok {}", x), - _ => println!("err") + _ => println!("err"), } // no warning because of the different types for x match (x, Some(1.0f64)) { (Ok(x), Some(_)) => println!("ok {}", x), (Ok(_), Some(x)) => println!("ok {}", x), - _ => println!("err") + _ => println!("err"), } // because of a bug, no warning was generated for this case before #2251 @@ -140,7 +139,9 @@ fn match_wild_err_arm() { Ok(_tmp) => println!("ok"), Ok(3) => println!("ok"), Ok(_) => println!("ok"), - Err(_) => {unreachable!();} + Err(_) => { + unreachable!(); + }, } } @@ -156,8 +157,6 @@ fn match_as_ref() { None => None, Some(ref mut v) => Some(v), }; - } -fn main() { -} +fn main() {} diff --git a/tests/ui/mem_discriminant.rs b/tests/ui/mem_discriminant.rs index 5ddd90ac8b5..9d2d6f9503a 100644 --- a/tests/ui/mem_discriminant.rs +++ b/tests/ui/mem_discriminant.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![deny(clippy::mem_discriminant_non_enum)] use std::mem; @@ -35,7 +34,9 @@ fn main() { mem::discriminant(&rro); macro_rules! mem_discriminant_but_in_a_macro { - ($param:expr) => (mem::discriminant($param)) + ($param:expr) => { + mem::discriminant($param) + }; } mem_discriminant_but_in_a_macro!(&rro); diff --git a/tests/ui/mem_forget.rs b/tests/ui/mem_forget.rs index 266c5c267f8..b46f7007cd0 100644 --- a/tests/ui/mem_forget.rs +++ b/tests/ui/mem_forget.rs @@ -7,16 +7,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - - -use std::sync::Arc; use std::rc::Rc; +use std::sync::Arc; -use std::mem::forget as forgetSomething; use std::mem as memstuff; +use std::mem::forget as forgetSomething; #[warn(clippy::mem_forget)] #[allow(clippy::forget_copy)] diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index 2b6e6f2ce67..edd3c031857 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -7,8 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - #![warn(clippy::all, clippy::style, clippy::mem_replace_option_with_none)] use std::mem; diff --git a/tests/ui/min_max.rs b/tests/ui/min_max.rs index b4ca46231e0..cf68bb61100 100644 --- a/tests/ui/min_max.rs +++ b/tests/ui/min_max.rs @@ -7,17 +7,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::all)] -use std::cmp::{min, max}; -use std::cmp::min as my_min; use std::cmp::max as my_max; +use std::cmp::min as my_min; +use std::cmp::{max, min}; -const LARGE : usize = 3; +const LARGE: usize = 3; fn main() { let x; diff --git a/tests/ui/missing-doc.rs b/tests/ui/missing-doc.rs index 6e7dfbfa37a..5de2ada5a41 100644 --- a/tests/ui/missing-doc.rs +++ b/tests/ui/missing-doc.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - /* This file incorporates work covered by the following copyright and * permission notice: * Copyright 2013 The Rust Project Developers. See the COPYRIGHT @@ -23,17 +20,14 @@ * except according to those terms. */ - - #![warn(clippy::missing_docs_in_private_items)] - // When denying at the crate level, be sure to not get random warnings from the // injected intrinsics by the compiler. #![allow(dead_code)] #![feature(associated_type_defaults)] //! Some garbage docs for the crate here -#![doc="More garbage"] +#![doc = "More garbage"] type Typedef = String; pub type PubTypedef = String; @@ -61,7 +55,8 @@ pub mod pub_module_no_dox {} pub fn foo() {} pub fn foo2() {} fn foo3() {} -#[allow(clippy::missing_docs_in_private_items)] pub fn foo4() {} +#[allow(clippy::missing_docs_in_private_items)] +pub fn foo4() {} /// dox pub trait A { @@ -84,7 +79,7 @@ fn foo_with_impl(&self) {} #[allow(clippy::missing_docs_in_private_items)] pub trait D { - fn dummy(&self) { } + fn dummy(&self) {} } /// dox @@ -110,7 +105,8 @@ pub fn foo() {} /// dox pub fn foo1() {} fn foo2() {} - #[allow(clippy::missing_docs_in_private_items)] pub fn foo3() {} + #[allow(clippy::missing_docs_in_private_items)] + pub fn foo3() {} } #[allow(clippy::missing_docs_in_private_items)] @@ -136,17 +132,12 @@ pub fn baz() {} } enum Baz { - BazA { - a: isize, - b: isize - }, - BarB + BazA { a: isize, b: isize }, + BarB, } pub enum PubBaz { - PubBazA { - a: isize, - }, + PubBazA { a: isize }, } /// dox @@ -160,15 +151,12 @@ pub enum PubBaz2 { #[allow(clippy::missing_docs_in_private_items)] pub enum PubBaz3 { - PubBaz3A { - b: isize - }, + PubBaz3A { b: isize }, } #[doc(hidden)] pub fn baz() {} - const FOO: u32 = 0; /// dox pub const FOO1: u32 = 0; @@ -178,7 +166,6 @@ pub fn baz() {} pub const FOO3: u32 = 0; pub const FOO4: u32 = 0; - static BAR: u32 = 0; /// dox pub static BAR1: u32 = 0; @@ -188,7 +175,6 @@ pub fn baz() {} pub static BAR3: u32 = 0; pub static BAR4: u32 = 0; - mod internal_impl { /// dox pub fn documented() {} @@ -206,9 +192,9 @@ fn also_undocumented2() {} /// dox pub mod public_interface { pub use internal_impl::documented as foo; + pub use internal_impl::globbed::*; pub use internal_impl::undocumented1 as bar; pub use internal_impl::{documented, undocumented2}; - pub use internal_impl::globbed::*; } fn main() {} diff --git a/tests/ui/missing_inline.rs b/tests/ui/missing_inline.rs index 0b86c4e5cfe..c9e946e14e6 100644 --- a/tests/ui/missing_inline.rs +++ b/tests/ui/missing_inline.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - /* This file incorporates work covered by the following copyright and * permission notice: * Copyright 2013 The Rust Project Developers. See the COPYRIGHT @@ -32,7 +29,7 @@ pub type PubTypedef = String; struct Foo {} // ok -pub struct PubFoo { } // ok +pub struct PubFoo {} // ok enum FooE {} // ok pub enum PubFooE {} // ok @@ -41,8 +38,10 @@ pub mod pub_module {} // ok fn foo() {} pub fn pub_foo() {} // missing #[inline] -#[inline] pub fn pub_foo_inline() {} // ok -#[inline(always)] pub fn pub_foo_inline_always() {} // ok +#[inline] +pub fn pub_foo_inline() {} // ok +#[inline(always)] +pub fn pub_foo_inline_always() {} // ok #[allow(clippy::missing_inline_in_public_items)] pub fn pub_foo_no_inline() {} @@ -52,11 +51,11 @@ trait Bar { fn Bar_b() {} // ok } - pub trait PubBar { fn PubBar_a(); // ok fn PubBar_b() {} // missing #[inline] - #[inline] fn PubBar_c() {} // ok + #[inline] + fn PubBar_c() {} // ok } // none of these need inline because Foo is not exported diff --git a/tests/ui/module_inception.rs b/tests/ui/module_inception.rs index 0676c4c29f0..730055931c4 100644 --- a/tests/ui/module_inception.rs +++ b/tests/ui/module_inception.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::module_inception)] mod foo { @@ -27,8 +24,7 @@ mod bar {} // No warning. See . mod bar { #[allow(clippy::module_inception)] - mod bar { - } + mod bar {} } fn main() {} diff --git a/tests/ui/modulo_one.rs b/tests/ui/modulo_one.rs index f1576447708..f7c0c16abad 100644 --- a/tests/ui/modulo_one.rs +++ b/tests/ui/modulo_one.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::modulo_one)] #![allow(clippy::no_effect, clippy::unnecessary_operation)] diff --git a/tests/ui/mut_from_ref.rs b/tests/ui/mut_from_ref.rs index 0a68d449d92..8a9da42083d 100644 --- a/tests/ui/mut_from_ref.rs +++ b/tests/ui/mut_from_ref.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(unused, clippy::trivially_copy_pass_by_ref)] #![warn(clippy::mut_from_ref)] diff --git a/tests/ui/mut_mut.rs b/tests/ui/mut_mut.rs index bed872902af..e8239007cb3 100644 --- a/tests/ui/mut_mut.rs +++ b/tests/ui/mut_mut.rs @@ -7,26 +7,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(unused, clippy::no_effect, clippy::unnecessary_operation)] #![warn(clippy::mut_mut)] - - - -fn fun(x : &mut &mut u32) -> bool { +fn fun(x: &mut &mut u32) -> bool { **x > 0 } -fn less_fun(x : *mut *mut u32) { - let y = x; +fn less_fun(x: *mut *mut u32) { + let y = x; } macro_rules! mut_ptr { - ($p:expr) => { &mut $p } + ($p:expr) => { + &mut $p + }; } #[allow(unused_mut, unused_variables)] @@ -37,12 +32,12 @@ fn main() { } if fun(x) { - let y : &mut &mut u32 = &mut &mut 2; + let y: &mut &mut u32 = &mut &mut 2; **y + **x; } if fun(x) { - let y : &mut &mut &mut u32 = &mut &mut &mut 2; + let y: &mut &mut &mut u32 = &mut &mut &mut 2; ***y + **x; } diff --git a/tests/ui/mut_range_bound.rs b/tests/ui/mut_range_bound.rs index edc86b5d6ac..23dddcdd158 100644 --- a/tests/ui/mut_range_bound.rs +++ b/tests/ui/mut_range_bound.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(unused)] fn main() { @@ -25,29 +21,38 @@ fn main() { fn mut_range_bound_upper() { let mut m = 4; - for i in 0..m { m = 5; } // warning + for i in 0..m { + m = 5; + } // warning } fn mut_range_bound_lower() { let mut m = 4; - for i in m..10 { m *= 2; } // warning + for i in m..10 { + m *= 2; + } // warning } fn mut_range_bound_both() { let mut m = 4; let mut n = 6; - for i in m..n { m = 5; n = 7; } // warning (1 for each mutated bound) + for i in m..n { + m = 5; + n = 7; + } // warning (1 for each mutated bound) } fn mut_range_bound_no_mutation() { let mut m = 4; - for i in 0..m { continue; } // no warning + for i in 0..m { + continue; + } // no warning } fn mut_borrow_range_bound() { let mut m = 4; for i in 0..m { - let n = &mut m; // warning + let n = &mut m; // warning *n += 1; } } @@ -55,12 +60,13 @@ fn mut_borrow_range_bound() { fn immut_borrow_range_bound() { let mut m = 4; for i in 0..m { - let n = &m; // should be no warning? + let n = &m; // should be no warning? } } - fn immut_range_bound() { let m = 4; - for i in 0..m { continue; } // no warning + for i in 0..m { + continue; + } // no warning } diff --git a/tests/ui/mut_reference.rs b/tests/ui/mut_reference.rs index d63b854fd09..882ed7e1dd3 100644 --- a/tests/ui/mut_reference.rs +++ b/tests/ui/mut_reference.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(unused_variables, clippy::trivially_copy_pass_by_ref)] fn takes_an_immutable_reference(a: &i32) {} @@ -19,11 +15,9 @@ fn takes_a_mutable_reference(a: &mut i32) {} struct MyStruct; impl MyStruct { - fn takes_an_immutable_reference(&self, a: &i32) { - } + fn takes_an_immutable_reference(&self, a: &i32) {} - fn takes_a_mutable_reference(&self, a: &mut i32) { - } + fn takes_a_mutable_reference(&self, a: &mut i32) {} } #[warn(clippy::unnecessary_mut_passed)] @@ -37,7 +31,6 @@ fn main() { let my_struct = MyStruct; my_struct.takes_an_immutable_reference(&mut 42); - // No error // Functions diff --git a/tests/ui/mutex_atomic.rs b/tests/ui/mutex_atomic.rs index 87b4ac9d8e3..5c4e180408c 100644 --- a/tests/ui/mutex_atomic.rs +++ b/tests/ui/mutex_atomic.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::all)] #![warn(clippy::mutex_integer)] diff --git a/tests/ui/needless_bool.rs b/tests/ui/needless_bool.rs index 98c2e0767d6..c82f102c294 100644 --- a/tests/ui/needless_bool.rs +++ b/tests/ui/needless_bool.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![warn(clippy::needless_bool)] use std::cell::Cell; @@ -38,12 +37,36 @@ pub fn trigger(&self, key: &str) -> bool { fn main() { let x = true; let y = false; - if x { true } else { true }; - if x { false } else { false }; - if x { true } else { false }; - if x { false } else { true }; - if x && y { false } else { true }; - if x { x } else { false }; // would also be questionable, but we don't catch this yet + if x { + true + } else { + true + }; + if x { + false + } else { + false + }; + if x { + true + } else { + false + }; + if x { + false + } else { + true + }; + if x && y { + false + } else { + true + }; + if x { + x + } else { + false + }; // would also be questionable, but we don't catch this yet bool_ret(x); bool_ret2(x); bool_ret3(x); @@ -57,50 +80,73 @@ fn main() { #[allow(clippy::if_same_then_else, clippy::needless_return)] fn bool_ret(x: bool) -> bool { - if x { return true } else { return true }; + if x { + return true; + } else { + return true; + }; } #[allow(clippy::if_same_then_else, clippy::needless_return)] fn bool_ret2(x: bool) -> bool { - if x { return false } else { return false }; + if x { + return false; + } else { + return false; + }; } #[allow(clippy::needless_return)] fn bool_ret3(x: bool) -> bool { - if x { return true } else { return false }; + if x { + return true; + } else { + return false; + }; } #[allow(clippy::needless_return)] fn bool_ret5(x: bool, y: bool) -> bool { - if x && y { return true } else { return false }; + if x && y { + return true; + } else { + return false; + }; } #[allow(clippy::needless_return)] fn bool_ret4(x: bool) -> bool { - if x { return false } else { return true }; + if x { + return false; + } else { + return true; + }; } #[allow(clippy::needless_return)] fn bool_ret6(x: bool, y: bool) -> bool { - if x && y { return false } else { return true }; + if x && y { + return false; + } else { + return true; + }; } fn needless_bool(x: bool) { - if x == true { }; + if x == true {}; } fn needless_bool2(x: bool) { - if x == false { }; + if x == false {}; } fn needless_bool3(x: bool) { - bool_comparison_trigger! { test_one: false, false; test_three: false, false; test_two: true, true; } - - if x == true { }; - if x == false { }; + + if x == true {}; + if x == false {}; } diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index 29e6ccca94d..bfc6e82cb55 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - use std::borrow::Cow; #[allow(clippy::trivially_copy_pass_by_ref)] @@ -41,7 +38,7 @@ fn main() { }; } -fn f(y: &T) -> T { +fn f(y: &T) -> T { *y } diff --git a/tests/ui/needless_borrowed_ref.rs b/tests/ui/needless_borrowed_ref.rs index ca3e60bd7e7..3897c86f53a 100644 --- a/tests/ui/needless_borrowed_ref.rs +++ b/tests/ui/needless_borrowed_ref.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[warn(clippy::needless_borrowed_reference)] #[allow(unused_variables)] fn main() { @@ -51,8 +47,6 @@ fn foo(a: &Animal, b: &Animal) { match (a, b) { (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref' // ^ and ^ should *not* be linted - (&Animal::Dog(ref a), &Animal::Dog(_)) => () - // ^ should *not* be linted + (&Animal::Dog(ref a), &Animal::Dog(_)) => (), // ^ should *not* be linted } } - diff --git a/tests/ui/needless_collect.rs b/tests/ui/needless_collect.rs index 91ebd354146..df449e3184f 100644 --- a/tests/ui/needless_collect.rs +++ b/tests/ui/needless_collect.rs @@ -7,10 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - -use std::collections::{HashMap, HashSet, BTreeSet}; +use std::collections::{BTreeSet, HashMap, HashSet}; #[warn(clippy::needless_collect)] #[allow(unused_variables, clippy::iter_cloned_collect)] diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs index 3d91132ea62..6d9b9499dce 100644 --- a/tests/ui/needless_continue.rs +++ b/tests/ui/needless_continue.rs @@ -7,16 +7,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - macro_rules! zero { - ($x:expr) => ($x == 0); + ($x:expr) => { + $x == 0 + }; } macro_rules! nonzero { - ($x:expr) => (!zero!($x)); + ($x:expr) => { + !zero!($x) + }; } #[warn(clippy::needless_continue)] @@ -27,9 +27,9 @@ fn main() { if i % 2 == 0 && i % 3 == 0 { println!("{}", i); - println!("{}", i+1); + println!("{}", i + 1); if i % 5 == 0 { - println!("{}", i+2); + println!("{}", i + 2); } let i = 0; println!("bar {} ", i); diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs index 48b7b42cc8c..ec9df9fb3d3 100644 --- a/tests/ui/needless_pass_by_value.rs +++ b/tests/ui/needless_pass_by_value.rs @@ -7,11 +7,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::needless_pass_by_value)] -#![allow(dead_code, clippy::single_match, clippy::redundant_pattern_matching, clippy::many_single_char_names, clippy::option_option)] +#![allow( + dead_code, + clippy::single_match, + clippy::redundant_pattern_matching, + clippy::many_single_char_names, + clippy::option_option +)] use std::borrow::Borrow; use std::convert::AsRef; @@ -92,24 +95,19 @@ fn issue_2114(s: String, t: String, u: Vec, v: Vec) { impl S { fn foo( - self, // taking `self` by value is always allowed + self, + // taking `self` by value is always allowed s: String, t: String, ) -> usize { s.len() + t.capacity() } - fn bar( - _t: T, // Ok, since `&T: Serialize` too + fn bar(_t: T // Ok, since `&T: Serialize` too ) { } - fn baz( - &self, - _u: U, - _s: Self, - ) { - } + fn baz(&self, _u: U, _s: Self) {} } trait FalsePositive { @@ -120,7 +118,9 @@ fn visit_string(s: String) { } // shouldn't warn on extern funcs -extern "C" fn ext(x: String) -> usize { x.len() } +extern "C" fn ext(x: String) -> usize { + x.len() +} // whitelist RangeArgument fn range>(range: T) { diff --git a/tests/ui/needless_pass_by_value_proc_macro.rs b/tests/ui/needless_pass_by_value_proc_macro.rs index f8f279ccb66..28f71d98fe7 100644 --- a/tests/ui/needless_pass_by_value_proc_macro.rs +++ b/tests/ui/needless_pass_by_value_proc_macro.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![crate_type = "proc-macro"] #![warn(clippy::needless_pass_by_value)] @@ -18,4 +15,6 @@ use proc_macro::TokenStream; #[proc_macro_derive(Foo)] -pub fn foo(_input: TokenStream) -> TokenStream { unimplemented!() } +pub fn foo(_input: TokenStream) -> TokenStream { + unimplemented!() +} diff --git a/tests/ui/needless_range_loop.rs b/tests/ui/needless_range_loop.rs index c1992bba548..f3d47eede48 100644 --- a/tests/ui/needless_range_loop.rs +++ b/tests/ui/needless_range_loop.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - fn calc_idx(i: usize) -> usize { (i + i + 20) % 4 } @@ -51,7 +50,7 @@ fn main() { let g = vec![1, 2, 3, 4, 5, 6]; let glen = g.len(); for i in 0..glen { - let x: u32 = g[i+1..].iter().sum(); + let x: u32 = g[i + 1..].iter().sum(); println!("{}", g[i] + x); } assert_eq!(g, vec![20, 18, 15, 11, 6, 0]); @@ -59,7 +58,7 @@ fn main() { let mut g = vec![1, 2, 3, 4, 5, 6]; let glen = g.len(); for i in 0..glen { - g[i] = g[i+1..].iter().sum(); + g[i] = g[i + 1..].iter().sum(); } assert_eq!(g, vec![20, 18, 15, 11, 6, 0]); @@ -77,7 +76,7 @@ fn main() { vec[i] += 1; } - let arr = [1,2,3]; + let arr = [1, 2, 3]; for i in 0..3 { println!("{}", arr[i]); diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index 9380f7c48a5..101be5946f4 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::needless_return)] fn test_end_of_fn() -> bool { @@ -22,7 +18,7 @@ fn test_end_of_fn() -> bool { } fn test_no_semicolon() -> bool { - return true + return true; } fn test_if_block() -> bool { @@ -38,7 +34,7 @@ fn test_match(x: bool) -> bool { true => return false, false => { return true; - } + }, } } diff --git a/tests/ui/needless_update.rs b/tests/ui/needless_update.rs index 974f3603fc6..891c446b0ea 100644 --- a/tests/ui/needless_update.rs +++ b/tests/ui/needless_update.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::needless_update)] #![allow(clippy::no_effect)] diff --git a/tests/ui/neg_cmp_op_on_partial_ord.rs b/tests/ui/neg_cmp_op_on_partial_ord.rs index 6d26d2ec6d1..6c132f85f0a 100644 --- a/tests/ui/neg_cmp_op_on_partial_ord.rs +++ b/tests/ui/neg_cmp_op_on_partial_ord.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - //! This test case utilizes `f64` an easy example for `PartialOrd` only types //! but the lint itself actually validates any expression where the left //! operand implements `PartialOrd` but not `Ord`. @@ -18,13 +15,11 @@ #[warn(clippy::neg_cmp_op_on_partial_ord)] fn main() { - let a_value = 1.0; let another_value = 7.0; // --- Bad --- - // Not Less but potentially Greater, Equal or Uncomparable. let _not_less = !(a_value < another_value); @@ -37,12 +32,10 @@ fn main() { // Not Greater or Equal but potentially Less or Uncomparable. let _not_greater_or_equal = !(a_value >= another_value); - // --- Good --- - let _not_less = match a_value.partial_cmp(&another_value) { - None | Some(Ordering::Greater) | Some(Ordering::Equal) => true, + None | Some(Ordering::Greater) | Some(Ordering::Equal) => true, _ => false, }; let _not_less_or_equal = match a_value.partial_cmp(&another_value) { @@ -58,10 +51,8 @@ fn main() { _ => false, }; - // --- Should not trigger --- - let _ = a_value < another_value; let _ = a_value <= another_value; let _ = a_value > another_value; diff --git a/tests/ui/neg_multiply.rs b/tests/ui/neg_multiply.rs index 446af7bbe94..f5f7525922c 100644 --- a/tests/ui/neg_multiply.rs +++ b/tests/ui/neg_multiply.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::neg_multiply)] #![allow(clippy::no_effect, clippy::unnecessary_operation)] diff --git a/tests/ui/never_loop.rs b/tests/ui/never_loop.rs index b952b1197dd..d5a108b0b27 100644 --- a/tests/ui/never_loop.rs +++ b/tests/ui/never_loop.rs @@ -7,17 +7,20 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - -#![allow(clippy::single_match, unused_assignments, unused_variables, clippy::while_immutable_condition)] +#![allow( + clippy::single_match, + unused_assignments, + unused_variables, + clippy::while_immutable_condition +)] fn test1() { let mut x = 0; - loop { // clippy::never_loop + loop { + // clippy::never_loop x += 1; if x == 1 { - return + return; } break; } @@ -28,16 +31,17 @@ fn test2() { loop { x += 1; if x == 1 { - break + break; } } } fn test3() { let mut x = 0; - loop { // never loops + loop { + // never loops x += 1; - break + break; } } @@ -54,24 +58,29 @@ fn test4() { fn test5() { let i = 0; - loop { // never loops - while i == 0 { // never loops - break + loop { + // never loops + while i == 0 { + // never loops + break; } - return - } + return; + } } fn test6() { let mut x = 0; 'outer: loop { x += 1; - loop { // never loops - if x == 5 { break } - continue 'outer - } - return - } + loop { + // never loops + if x == 5 { + break; + } + continue 'outer; + } + return; + } } fn test7() { @@ -82,7 +91,7 @@ fn test7() { 1 => continue, _ => (), } - return + return; } } @@ -99,13 +108,15 @@ fn test8() { fn test9() { let x = Some(1); - while let Some(y) = x { // never loops - return + while let Some(y) = x { + // never loops + return; } } fn test10() { - for x in 0..10 { // never loops + for x in 0..10 { + // never loops match x { 1 => break, _ => return, @@ -118,7 +129,7 @@ fn test11 i32>(mut f: F) { return match f() { 1 => continue, _ => (), - } + }; } } @@ -138,7 +149,8 @@ pub fn test12(a: bool, b: bool) { pub fn test13() { let mut a = true; - loop { // infinite loop + loop { + // infinite loop while a { if true { a = false; @@ -151,11 +163,12 @@ pub fn test13() { pub fn test14() { let mut a = true; - 'outer: while a { // never loops + 'outer: while a { + // never loops while a { if a { a = false; - continue + continue; } } break 'outer; @@ -187,4 +200,3 @@ fn main() { test13(); test14(); } - diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index bed43f550f2..a31f046c084 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -1,7 +1,7 @@ #![warn(clippy::new_ret_no_self)] #![allow(dead_code, clippy::trivially_copy_pass_by_ref)] -fn main(){} +fn main() {} trait R { type Item; @@ -96,82 +96,106 @@ pub fn new(_: String) -> u32 { impl TupleReturnerOk { // should not trigger lint - pub fn new() -> (Self, u32) { unimplemented!(); } + pub fn new() -> (Self, u32) { + unimplemented!(); + } } struct TupleReturnerOk2; impl TupleReturnerOk2 { // should not trigger lint (it doesn't matter which element in the tuple is Self) - pub fn new() -> (u32, Self) { unimplemented!(); } + pub fn new() -> (u32, Self) { + unimplemented!(); + } } struct TupleReturnerOk3; impl TupleReturnerOk3 { // should not trigger lint (tuple can contain multiple Self) - pub fn new() -> (Self, Self) { unimplemented!(); } + pub fn new() -> (Self, Self) { + unimplemented!(); + } } struct TupleReturnerBad; impl TupleReturnerBad { // should trigger lint - pub fn new() -> (u32, u32) { unimplemented!(); } + pub fn new() -> (u32, u32) { + unimplemented!(); + } } struct MutPointerReturnerOk; impl MutPointerReturnerOk { // should not trigger lint - pub fn new() -> *mut Self { unimplemented!(); } + pub fn new() -> *mut Self { + unimplemented!(); + } } struct MutPointerReturnerOk2; impl MutPointerReturnerOk2 { // should not trigger lint - pub fn new() -> *const Self { unimplemented!(); } + pub fn new() -> *const Self { + unimplemented!(); + } } struct MutPointerReturnerBad; impl MutPointerReturnerBad { // should trigger lint - pub fn new() -> *mut V { unimplemented!(); } + pub fn new() -> *mut V { + unimplemented!(); + } } struct GenericReturnerOk; impl GenericReturnerOk { // should not trigger lint - pub fn new() -> Option { unimplemented!(); } + pub fn new() -> Option { + unimplemented!(); + } } struct GenericReturnerBad; impl GenericReturnerBad { // should trigger lint - pub fn new() -> Option { unimplemented!(); } + pub fn new() -> Option { + unimplemented!(); + } } struct NestedReturnerOk; impl NestedReturnerOk { // should not trigger lint - pub fn new() -> (Option, u32) { unimplemented!(); } + pub fn new() -> (Option, u32) { + unimplemented!(); + } } struct NestedReturnerOk2; impl NestedReturnerOk2 { // should not trigger lint - pub fn new() -> ((Self, u32), u32) { unimplemented!(); } + pub fn new() -> ((Self, u32), u32) { + unimplemented!(); + } } struct NestedReturnerOk3; impl NestedReturnerOk3 { // should not trigger lint - pub fn new() -> Option<(Self, u32)> { unimplemented!(); } + pub fn new() -> Option<(Self, u32)> { + unimplemented!(); + } } diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index 16b9bd5c71b..a1818e037a7 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -7,41 +7,46 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![feature(const_fn)] - - #![allow(dead_code)] #![warn(clippy::new_without_default, clippy::new_without_default_derive)] pub struct Foo; impl Foo { - pub fn new() -> Foo { Foo } + pub fn new() -> Foo { + Foo + } } pub struct Bar; impl Bar { - pub fn new() -> Self { Bar } + pub fn new() -> Self { + Bar + } } pub struct Ok; impl Ok { - pub fn new() -> Self { Ok } + pub fn new() -> Self { + Ok + } } impl Default for Ok { - fn default() -> Self { Ok } + fn default() -> Self { + Ok + } } pub struct Params; impl Params { - pub fn new(_: u32) -> Self { Params } + pub fn new(_: u32) -> Self { + Params + } } pub struct GenericsOk { @@ -49,11 +54,15 @@ pub struct GenericsOk { } impl Default for GenericsOk { - fn default() -> Self { unimplemented!(); } + fn default() -> Self { + unimplemented!(); + } } impl<'c, V> GenericsOk { - pub fn new() -> GenericsOk { unimplemented!() } + pub fn new() -> GenericsOk { + unimplemented!() + } } pub struct LtOk<'a> { @@ -61,11 +70,15 @@ pub struct LtOk<'a> { } impl<'b> Default for LtOk<'b> { - fn default() -> Self { unimplemented!(); } + fn default() -> Self { + unimplemented!(); + } } impl<'c> LtOk<'c> { - pub fn new() -> LtOk<'c> { unimplemented!() } + pub fn new() -> LtOk<'c> { + unimplemented!() + } } pub struct LtKo<'a> { @@ -73,26 +86,34 @@ pub struct LtKo<'a> { } impl<'c> LtKo<'c> { - pub fn new() -> LtKo<'c> { unimplemented!() } + pub fn new() -> LtKo<'c> { + unimplemented!() + } // FIXME: that suggestion is missing lifetimes } struct Private; impl Private { - fn new() -> Private { unimplemented!() } // We don't lint private items + fn new() -> Private { + unimplemented!() + } // We don't lint private items } struct Const; impl Const { - pub const fn new() -> Const { Const } // const fns can't be implemented via Default + pub const fn new() -> Const { + Const + } // const fns can't be implemented via Default } pub struct IgnoreGenericNew; impl IgnoreGenericNew { - pub fn new() -> Self { IgnoreGenericNew } // the derived Default does not make sense here as the result depends on T + pub fn new() -> Self { + IgnoreGenericNew + } // the derived Default does not make sense here as the result depends on T } pub trait TraitWithNew: Sized { @@ -104,7 +125,9 @@ fn new() -> Self { pub struct IgnoreUnsafeNew; impl IgnoreUnsafeNew { - pub unsafe fn new() -> Self { IgnoreUnsafeNew } + pub unsafe fn new() -> Self { + IgnoreUnsafeNew + } } #[derive(Default)] diff --git a/tests/ui/no_effect.rs b/tests/ui/no_effect.rs index bee3aeb6f7f..6b51c50dcde 100644 --- a/tests/ui/no_effect.rs +++ b/tests/ui/no_effect.rs @@ -7,12 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![feature(box_syntax)] - - #![warn(clippy::no_effect)] #![allow(dead_code)] #![allow(path_statements)] @@ -23,7 +18,7 @@ struct Unit; struct Tuple(i32); struct Struct { - field: i32 + field: i32, } enum Enum { Tuple(i32), @@ -34,7 +29,7 @@ impl Drop for DropUnit { fn drop(&mut self) {} } struct DropStruct { - field: i32 + field: i32, } impl Drop for DropStruct { fn drop(&mut self) {} @@ -58,11 +53,19 @@ union Union { b: f64, } -fn get_number() -> i32 { 0 } -fn get_struct() -> Struct { Struct { field: 0 } } -fn get_drop_struct() -> DropStruct { DropStruct { field: 0 } } +fn get_number() -> i32 { + 0 +} +fn get_struct() -> Struct { + Struct { field: 0 } +} +fn get_drop_struct() -> DropStruct { + DropStruct { field: 0 } +} -unsafe fn unsafe_fn() -> i32 { 0 } +unsafe fn unsafe_fn() -> i32 { + 0 +} fn main() { let s = get_struct(); diff --git a/tests/ui/non_copy_const.rs b/tests/ui/non_copy_const.rs index 5cbb610fea3..591e1994ee3 100644 --- a/tests/ui/non_copy_const.rs +++ b/tests/ui/non_copy_const.rs @@ -7,17 +7,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![feature(const_string_new, const_vec_new)] #![allow(clippy::ref_in_deref, dead_code)] -use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering}; -use std::cell::Cell; -use std::sync::Once; use std::borrow::Cow; +use std::cell::Cell; use std::fmt::Display; +use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT}; +use std::sync::Once; const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable const CELL: Cell = Cell::new(6); //~ ERROR interior mutable @@ -25,7 +22,9 @@ //~^ ERROR interior mutable macro_rules! declare_const { - ($name:ident: $ty:ty = $e:expr) => { const $name: $ty = $e; }; + ($name:ident: $ty:ty = $e:expr) => { + const $name: $ty = $e; + }; } declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable @@ -136,7 +135,7 @@ fn main() { let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability let _ = ATOMIC_TUPLE.1.into_iter(); let _ = ATOMIC_TUPLE.2; - let _ = &{ATOMIC_TUPLE}; + let _ = &{ ATOMIC_TUPLE }; CELL.set(2); //~ ERROR interior mutability assert_eq!(CELL.get(), 6); //~ ERROR interior mutability diff --git a/tests/ui/non_expressive_names.rs b/tests/ui/non_expressive_names.rs index 67fded14485..86c9edc821d 100644 --- a/tests/ui/non_expressive_names.rs +++ b/tests/ui/non_expressive_names.rs @@ -7,13 +7,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - -#![warn(clippy::all,clippy::similar_names)] +#![warn(clippy::all, clippy::similar_names)] #![allow(unused, clippy::println_empty_string)] - struct Foo { apple: i32, bpple: i32, @@ -29,7 +25,6 @@ fn main() { let cpple: i32; - let a_bar: i32; let b_bar: i32; let c_bar: i32; @@ -54,7 +49,6 @@ fn main() { let blubx: i32; let bluby: i32; - let cake: i32; let cakes: i32; let coke: i32; @@ -81,7 +75,6 @@ fn main() { let parsed: i32; let parsee: i32; - let setter: i32; let getter: i32; let tx1: i32; @@ -92,8 +85,10 @@ fn main() { fn foo() { let Foo { apple, bpple } = unimplemented!(); - let Foo { apple: spring, - bpple: sprang } = unimplemented!(); + let Foo { + apple: spring, + bpple: sprang, + } = unimplemented!(); } #[derive(Clone, Debug)] @@ -132,7 +127,6 @@ fn bla() { { let e: i32; let f: i32; - } match 5 { 1 => println!(""), @@ -149,18 +143,18 @@ fn underscores_and_numbers() { let _1 = 1; //~ERROR Consider a more descriptive name let ____1 = 1; //~ERROR Consider a more descriptive name let __1___2 = 12; //~ERROR Consider a more descriptive name - let _1_ok= 1; + let _1_ok = 1; } fn issue2927() { - let args = 1; - format!("{:?}", 2); + let args = 1; + format!("{:?}", 2); } fn issue3078() { match "a" { stringify!(a) => {}, - _ => {} + _ => {}, } } @@ -171,7 +165,7 @@ fn bar() { let _1 = 1; let ____1 = 1; let __1___2 = 12; - let _1_ok= 1; + let _1_ok = 1; } } diff --git a/tests/ui/ok_expect.rs b/tests/ui/ok_expect.rs index 5d333a72cc0..b121aae788c 100644 --- a/tests/ui/ok_expect.rs +++ b/tests/ui/ok_expect.rs @@ -7,14 +7,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - use std::io; struct MyError(()); // doesn't implement Debug #[derive(Debug)] struct MyErrorWithParam { - x: T + x: T, } fn main() { @@ -26,7 +25,7 @@ fn main() { // the error type implements `Debug` let res2: Result = Ok(0); res2.ok().expect("oh noes!"); - let res3: Result>= Ok(0); + let res3: Result> = Ok(0); res3.ok().expect("whoof"); let res4: Result = Ok(0); res4.ok().expect("argh"); diff --git a/tests/ui/ok_if_let.rs b/tests/ui/ok_if_let.rs index b318a90d883..3ede64ce3aa 100644 --- a/tests/ui/ok_if_let.rs +++ b/tests/ui/ok_if_let.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::if_let_some_result)] fn str_to_int(x: &str) -> i32 { diff --git a/tests/ui/op_ref.rs b/tests/ui/op_ref.rs index bacf9f1057b..1112b6794cf 100644 --- a/tests/ui/op_ref.rs +++ b/tests/ui/op_ref.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(unused_variables, clippy::blacklisted_name)] use std::collections::HashSet; diff --git a/tests/ui/open_options.rs b/tests/ui/open_options.rs index 6b891d72e8b..f4d0af94b3f 100644 --- a/tests/ui/open_options.rs +++ b/tests/ui/open_options.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - use std::fs::OpenOptions; #[allow(unused_must_use)] diff --git a/tests/ui/option_map_unit_fn.rs b/tests/ui/option_map_unit_fn.rs index b023181fcf7..5200ff694a0 100644 --- a/tests/ui/option_map_unit_fn.rs +++ b/tests/ui/option_map_unit_fn.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::option_map_unit_fn)] #![allow(unused)] @@ -39,7 +36,7 @@ fn option_map_unit_fn() { let x = HasOption { field: Some(10) }; x.field.map(plus_one); - let _ : Option<()> = x.field.map(do_nothing); + let _: Option<()> = x.field.map(do_nothing); x.field.map(do_nothing); @@ -48,47 +45,68 @@ fn option_map_unit_fn() { x.field.map(diverge); let captured = 10; - if let Some(value) = x.field { do_nothing(value + captured) }; - let _ : Option<()> = x.field.map(|value| do_nothing(value + captured)); + if let Some(value) = x.field { + do_nothing(value + captured) + }; + let _: Option<()> = x.field.map(|value| do_nothing(value + captured)); x.field.map(|value| x.do_option_nothing(value + captured)); - x.field.map(|value| { x.do_option_plus_one(value + captured); }); - + x.field.map(|value| { + x.do_option_plus_one(value + captured); + }); x.field.map(|value| do_nothing(value + captured)); - x.field.map(|value| { do_nothing(value + captured) }); + x.field.map(|value| do_nothing(value + captured)); - x.field.map(|value| { do_nothing(value + captured); }); - - x.field.map(|value| { { do_nothing(value + captured); } }); + x.field.map(|value| { + do_nothing(value + captured); + }); + x.field.map(|value| { + do_nothing(value + captured); + }); x.field.map(|value| diverge(value + captured)); - x.field.map(|value| { diverge(value + captured) }); + x.field.map(|value| diverge(value + captured)); - x.field.map(|value| { diverge(value + captured); }); - - x.field.map(|value| { { diverge(value + captured); } }); + x.field.map(|value| { + diverge(value + captured); + }); + x.field.map(|value| { + diverge(value + captured); + }); x.field.map(|value| plus_one(value + captured)); - x.field.map(|value| { plus_one(value + captured) }); - x.field.map(|value| { let y = plus_one(value + captured); }); + x.field.map(|value| plus_one(value + captured)); + x.field.map(|value| { + let y = plus_one(value + captured); + }); - x.field.map(|value| { plus_one(value + captured); }); + x.field.map(|value| { + plus_one(value + captured); + }); - x.field.map(|value| { { plus_one(value + captured); } }); + x.field.map(|value| { + plus_one(value + captured); + }); + x.field.map(|ref value| do_nothing(value + captured)); - x.field.map(|ref value| { do_nothing(value + captured) }); + x.field.map(|value| { + do_nothing(value); + do_nothing(value) + }); - - x.field.map(|value| { do_nothing(value); do_nothing(value) }); - - x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); + x.field.map(|value| { + if value > 0 { + do_nothing(value); + do_nothing(value) + } + }); // Suggestion for the let block should be `{ ... }` as it's too difficult to build a // proper suggestion for these cases @@ -96,9 +114,13 @@ fn option_map_unit_fn() { do_nothing(value); do_nothing(value) }); - x.field.map(|value| { do_nothing(value); do_nothing(value); }); + x.field.map(|value| { + do_nothing(value); + do_nothing(value); + }); - // The following should suggest `if let Some(_X) ...` as it's difficult to generate a proper let variable name for them + // The following should suggest `if let Some(_X) ...` as it's difficult to generate a proper let + // variable name for them Some(42).map(diverge); "12".parse::().ok().map(diverge); Some(plus_one(1)).map(do_nothing); @@ -108,5 +130,4 @@ fn option_map_unit_fn() { y.map(do_nothing); } -fn main() { -} +fn main() {} diff --git a/tests/ui/option_option.rs b/tests/ui/option_option.rs index 3cb4fdc27eb..fcfd4e6ea56 100644 --- a/tests/ui/option_option.rs +++ b/tests/ui/option_option.rs @@ -7,9 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -fn input(_: Option>) { -} +fn input(_: Option>) {} fn output() -> Option> { None @@ -40,7 +38,7 @@ trait Trait { enum Enum { Tuple(Option>), - Struct{x: Option>}, + Struct { x: Option> }, } // The lint allows this @@ -69,5 +67,3 @@ fn main() { // The lint allows this let expr = Some(Some(true)); } - - diff --git a/tests/ui/overflow_check_conditional.rs b/tests/ui/overflow_check_conditional.rs index 82fdfe14ab6..a5cff3df9d7 100644 --- a/tests/ui/overflow_check_conditional.rs +++ b/tests/ui/overflow_check_conditional.rs @@ -7,65 +7,29 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(clippy::many_single_char_names)] #![warn(clippy::overflow_check_conditional)] fn main() { - let a: u32 = 1; - let b: u32 = 2; - let c: u32 = 3; - if a + b < a { - - } - if a > a + b { - - } - if a + b < b { - - } - if b > a + b { - - } - if a - b > b { - - } - if b < a - b { - - } - if a - b > a { - - } - if a < a - b { - - } - if a + b < c { - - } - if c > a + b { - - } - if a - b < c { - - } - if c > a - b { - - } - let i = 1.1; - let j = 2.2; - if i + j < i { - - } - if i - j < i { - - } - if i > i + j { - - } - if i - j < i { - - } + let a: u32 = 1; + let b: u32 = 2; + let c: u32 = 3; + if a + b < a {} + if a > a + b {} + if a + b < b {} + if b > a + b {} + if a - b > b {} + if b < a - b {} + if a - b > a {} + if a < a - b {} + if a + b < c {} + if c > a + b {} + if a - b < c {} + if c > a - b {} + let i = 1.1; + let j = 2.2; + if i + j < i {} + if i - j < i {} + if i > i + j {} + if i - j < i {} } diff --git a/tests/ui/panic_unimplemented.rs b/tests/ui/panic_unimplemented.rs index ede2e8f063b..93dec197ff5 100644 --- a/tests/ui/panic_unimplemented.rs +++ b/tests/ui/panic_unimplemented.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::panic_params, clippy::unimplemented)] fn missing() { @@ -46,7 +42,7 @@ fn ok_bracket() { } } -const ONE : u32= 1; +const ONE: u32 = 1; fn ok_nomsg() { assert!({ 1 == ONE }); diff --git a/tests/ui/partialeq_ne_impl.rs b/tests/ui/partialeq_ne_impl.rs index 45aa0decd58..3f9f91c81b1 100644 --- a/tests/ui/partialeq_ne_impl.rs +++ b/tests/ui/partialeq_ne_impl.rs @@ -7,17 +7,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(dead_code)] struct Foo; impl PartialEq for Foo { - fn eq(&self, _: &Foo) -> bool { true } - fn ne(&self, _: &Foo) -> bool { false } + fn eq(&self, _: &Foo) -> bool { + true + } + fn ne(&self, _: &Foo) -> bool { + false + } } fn main() {} diff --git a/tests/ui/patterns.rs b/tests/ui/patterns.rs index 41e9ec8ca81..e10afdb86b8 100644 --- a/tests/ui/patterns.rs +++ b/tests/ui/patterns.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(unused)] #![warn(clippy::all)] @@ -17,10 +14,10 @@ fn main() { let v = Some(true); match v { Some(x) => (), - y @ _ => (), + y @ _ => (), } match v { - Some(x) => (), - y @ None => (), // no error + Some(x) => (), + y @ None => (), // no error } } diff --git a/tests/ui/precedence.rs b/tests/ui/precedence.rs index 4b404022ed4..82009cd3873 100644 --- a/tests/ui/precedence.rs +++ b/tests/ui/precedence.rs @@ -7,21 +7,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[warn(clippy::precedence)] #[allow(clippy::identity_op)] #[allow(clippy::eq_op)] macro_rules! trip { - ($a:expr) => { - match $a & 0b1111_1111i8 { - 0 => println!("a is zero ({})", $a), - _ => println!("a is {}", $a), - } - }; + ($a:expr) => { + match $a & 0b1111_1111i8 { + 0 => println!("a is zero ({})", $a), + _ => println!("a is {}", $a), + } + }; } fn main() { diff --git a/tests/ui/print.rs b/tests/ui/print.rs index 5fa2cfcc315..a43482cba62 100644 --- a/tests/ui/print.rs +++ b/tests/ui/print.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(clippy::print_literal, clippy::write_literal)] #![warn(clippy::print_stdout, clippy::use_debug)] diff --git a/tests/ui/print_literal.rs b/tests/ui/print_literal.rs index 0df26f6d25f..74756384067 100644 --- a/tests/ui/print_literal.rs +++ b/tests/ui/print_literal.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::print_literal)] fn main() { @@ -18,17 +15,17 @@ fn main() { println!("Hello"); let world = "world"; println!("Hello {}", world); - println!("Hello {world}", world=world); + println!("Hello {world}", world = world); println!("3 in hex is {:X}", 3); println!("2 + 1 = {:.4}", 3); println!("2 + 1 = {:5.4}", 3); println!("Debug test {:?}", "hello, world"); println!("{0:8} {1:>8}", "hello", "world"); println!("{1:8} {0:>8}", "hello", "world"); - println!("{foo:8} {bar:>8}", foo="hello", bar="world"); - println!("{bar:8} {foo:>8}", foo="hello", bar="world"); - println!("{number:>width$}", number=1, width=6); - println!("{number:>0width$}", number=1, width=6); + println!("{foo:8} {bar:>8}", foo = "hello", bar = "world"); + println!("{bar:8} {foo:>8}", foo = "hello", bar = "world"); + println!("{number:>width$}", number = 1, width = 6); + println!("{number:>0width$}", number = 1, width = 6); // these should throw warnings println!("{} of {:b} people know binary, the other half doesn't", 1, 2); @@ -45,6 +42,6 @@ fn main() { println!("{1} {0}", "hello", "world"); // named args shouldn't change anything either - println!("{foo} {bar}", foo="hello", bar="world"); - println!("{bar} {foo}", foo="hello", bar="world"); + println!("{foo} {bar}", foo = "hello", bar = "world"); + println!("{bar} {foo}", foo = "hello", bar = "world"); } diff --git a/tests/ui/print_with_newline.rs b/tests/ui/print_with_newline.rs index 2dd08a5b88d..351fd60bc36 100644 --- a/tests/ui/print_with_newline.rs +++ b/tests/ui/print_with_newline.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(clippy::print_literal)] #![warn(clippy::print_with_newline)] diff --git a/tests/ui/println_empty_string.rs b/tests/ui/println_empty_string.rs index afc37b1bec7..19a0389762a 100644 --- a/tests/ui/println_empty_string.rs +++ b/tests/ui/println_empty_string.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - fn main() { println!(); println!(""); diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index df0bde14960..0d7a829888e 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(unused, clippy::many_single_char_names)] #![warn(clippy::ptr_arg)] @@ -19,7 +16,8 @@ fn do_vec(x: &Vec) { //Nothing here } -fn do_vec_mut(x: &mut Vec) { // no error here +fn do_vec_mut(x: &mut Vec) { + // no error here //Nothing here } @@ -27,12 +25,12 @@ fn do_str(x: &String) { //Nothing here either } -fn do_str_mut(x: &mut String) { // no error here +fn do_str_mut(x: &mut String) { + // no error here //Nothing here either } -fn main() { -} +fn main() {} trait Foo { type Item; @@ -62,9 +60,7 @@ fn str_cloned(x: &String) -> String { let a = x.clone(); let b = x.clone(); let c = b.clone(); - let d = a.clone() - .clone() - .clone(); + let d = a.clone().clone().clone(); x.clone() } @@ -75,13 +71,14 @@ fn false_positive_capacity(x: &Vec, y: &String) { } fn false_positive_capacity_too(x: &String) -> String { - if x.capacity() > 1024 { panic!("Too large!"); } + if x.capacity() > 1024 { + panic!("Too large!"); + } x.clone() } #[allow(dead_code)] -fn test_cow_with_ref(c: &Cow<[i32]>) { -} +fn test_cow_with_ref(c: &Cow<[i32]>) {} #[allow(dead_code)] fn test_cow(c: Cow<[i32]>) { @@ -93,4 +90,6 @@ trait Foo2 { } // no error for &self references where self is of type String (#2293) -impl Foo2 for String { fn do_string(&self) {} } +impl Foo2 for String { + fn do_string(&self) {} +} diff --git a/tests/ui/ptr_offset_with_cast.rs b/tests/ui/ptr_offset_with_cast.rs index a6f86a230f3..2c9e47d3f32 100644 --- a/tests/ui/ptr_offset_with_cast.rs +++ b/tests/ui/ptr_offset_with_cast.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - fn main() { let vec = vec![b'a', b'b', b'c']; let ptr = vec.as_ptr(); diff --git a/tests/ui/question_mark.rs b/tests/ui/question_mark.rs index a39ea00cb8b..7f1d06fbd29 100644 --- a/tests/ui/question_mark.rs +++ b/tests/ui/question_mark.rs @@ -7,18 +7,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - fn some_func(a: Option) -> Option { - if a.is_none() { - return None - } + if a.is_none() { + return None; + } - a + a } pub enum SeemsOption { Some(T), - None + None, } impl SeemsOption { @@ -39,25 +38,25 @@ fn returns_something_similar_to_option(a: SeemsOption) -> SeemsOption } pub struct SomeStruct { - pub opt: Option, + pub opt: Option, } impl SomeStruct { - pub fn func(&self) -> Option { - if (self.opt).is_none() { - return None; - } + pub fn func(&self) -> Option { + if (self.opt).is_none() { + return None; + } - self.opt - } + self.opt + } } fn main() { - some_func(Some(42)); - some_func(None); + some_func(Some(42)); + some_func(None); - let some_struct = SomeStruct { opt: Some(54) }; - some_struct.func(); + let some_struct = SomeStruct { opt: Some(54) }; + some_struct.func(); let so = SeemsOption::Some(45); returns_something_similar_to_option(so); diff --git a/tests/ui/range.rs b/tests/ui/range.rs index 8b7f0673e24..1eab67e20d0 100644 --- a/tests/ui/range.rs +++ b/tests/ui/range.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - struct NotARange; impl NotARange { fn step_by(&self, _: u32) {} @@ -31,13 +28,13 @@ fn main() { let y = NotARange; y.step_by(0); - let v1 = vec![1,2,3]; - let v2 = vec![4,5]; + let v1 = vec![1, 2, 3]; + let v2 = vec![4, 5]; let _x = v1.iter().zip(0..v1.len()); let _y = v1.iter().zip(0..v2.len()); // No error // check const eval - let _ = v1.iter().step_by(2/3); + let _ = v1.iter().step_by(2 / 3); } #[allow(unused)] diff --git a/tests/ui/range_plus_minus_one.rs b/tests/ui/range_plus_minus_one.rs index 602743d6914..d8c955ba73f 100644 --- a/tests/ui/range_plus_minus_one.rs +++ b/tests/ui/range_plus_minus_one.rs @@ -7,38 +7,35 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - fn f() -> usize { 42 } #[warn(clippy::range_plus_one)] fn main() { - for _ in 0..2 { } - for _ in 0..=2 { } + for _ in 0..2 {} + for _ in 0..=2 {} - for _ in 0..3+1 { } - for _ in 0..=3+1 { } + for _ in 0..3 + 1 {} + for _ in 0..=3 + 1 {} - for _ in 0..1+5 { } - for _ in 0..=1+5 { } + for _ in 0..1 + 5 {} + for _ in 0..=1 + 5 {} - for _ in 1..1+1 { } - for _ in 1..=1+1 { } + for _ in 1..1 + 1 {} + for _ in 1..=1 + 1 {} - for _ in 0..13+13 { } - for _ in 0..=13-7 { } + for _ in 0..13 + 13 {} + for _ in 0..=13 - 7 {} - for _ in 0..(1+f()) { } - for _ in 0..=(1+f()) { } + for _ in 0..(1 + f()) {} + for _ in 0..=(1 + f()) {} - let _ = ..11-1; - let _ = ..=11-1; - let _ = ..=(11-1); - let _ = (1..11+1); - let _ = (f()+1)..(f()+1); + let _ = ..11 - 1; + let _ = ..=11 - 1; + let _ = ..=(11 - 1); + let _ = (1..11 + 1); + let _ = (f() + 1)..(f() + 1); let mut vec: Vec<()> = std::vec::Vec::new(); vec.drain(..); diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs index deedde38231..d55898748be 100644 --- a/tests/ui/redundant_clone.rs +++ b/tests/ui/redundant_clone.rs @@ -9,8 +9,8 @@ #![warn(clippy::redundant_clone)] -use std::path::Path; use std::ffi::OsString; +use std::path::Path; fn main() { let _ = ["lorem", "ipsum"].join(" ").to_string(); @@ -33,7 +33,8 @@ fn main() { let _ = OsString::new().to_os_string(); // Check that lint level works - #[allow(clippy::redundant_clone)] let _ = String::new().to_string(); + #[allow(clippy::redundant_clone)] + let _ = String::new().to_string(); } #[derive(Clone)] diff --git a/tests/ui/redundant_closure_call.rs b/tests/ui/redundant_closure_call.rs index e68cdc2c1d1..46c56922974 100644 --- a/tests/ui/redundant_closure_call.rs +++ b/tests/ui/redundant_closure_call.rs @@ -7,27 +7,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::redundant_closure_call)] fn main() { - let a = (|| 42)(); + let a = (|| 42)(); - let mut i = 1; - let mut k = (|m| m+1)(i); + let mut i = 1; + let mut k = (|m| m + 1)(i); - k = (|a,b| a*b)(1,5); + k = (|a, b| a * b)(1, 5); - let closure = || 32; - i = closure(); + let closure = || 32; + i = closure(); - let closure = |i| i+1; - i = closure(3); + let closure = |i| i + 1; + i = closure(3); - i = closure(4); + i = closure(4); #[allow(clippy::needless_return)] (|| return 2)(); diff --git a/tests/ui/redundant_field_names.rs b/tests/ui/redundant_field_names.rs index 41e90bba368..68adba92f8a 100644 --- a/tests/ui/redundant_field_names.rs +++ b/tests/ui/redundant_field_names.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::redundant_field_names)] #![allow(unused_variables)] #![feature(inclusive_range, inclusive_range_fields, inclusive_range_methods)] @@ -17,7 +14,7 @@ #[macro_use] extern crate derive_new; -use std::ops::{Range, RangeFrom, RangeTo, RangeInclusive, RangeToInclusive}; +use std::ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive}; mod foo { pub const BAR: u8 = 0; @@ -46,8 +43,8 @@ fn main() { gender: gender, age: age, - name, //should be ok - buzz: fizz, //should be ok + name, //should be ok + buzz: fizz, //should be ok foo: foo::BAR, //should be ok }; diff --git a/tests/ui/redundant_pattern_matching.rs b/tests/ui/redundant_pattern_matching.rs index 50838584f66..3744695a535 100644 --- a/tests/ui/redundant_pattern_matching.rs +++ b/tests/ui/redundant_pattern_matching.rs @@ -7,39 +7,27 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] - fn main() { if let Ok(_) = Ok::(42) {} - if let Err(_) = Err::(42) { - } + if let Err(_) = Err::(42) {} - if let None = None::<()> { - } + if let None = None::<()> {} - if let Some(_) = Some(42) { - } + if let Some(_) = Some(42) {} - if Ok::(42).is_ok() { - } + if Ok::(42).is_ok() {} - if Err::(42).is_err() { - } + if Err::(42).is_err() {} - if None::.is_none() { - } + if None::.is_none() {} - if Some(42).is_some() { - } + if Some(42).is_some() {} - if let Ok(x) = Ok::(42) { + if let Ok(x) = Ok::(42) { println!("{}", x); } diff --git a/tests/ui/reference.rs b/tests/ui/reference.rs index bd0fdd5d5ea..583829aae41 100644 --- a/tests/ui/reference.rs +++ b/tests/ui/reference.rs @@ -7,15 +7,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - fn get_number() -> usize { 10 } -fn get_reference(n : &usize) -> &usize { +fn get_reference(n: &usize) -> &usize { n } @@ -32,7 +28,7 @@ fn main() { let b = *get_reference(&a); - let bytes : Vec = vec![1, 2, 3, 4]; + let bytes: Vec = vec![1, 2, 3, 4]; let b = *&bytes[1..2][0]; //This produces a suggestion of 'let b = (a);' which @@ -41,7 +37,7 @@ fn main() { let b = *(&a); - let b = *((&a)); + let b = *(&a); let b = *&&a; diff --git a/tests/ui/regex.rs b/tests/ui/regex.rs index 2623438c4c4..2d9c3482850 100644 --- a/tests/ui/regex.rs +++ b/tests/ui/regex.rs @@ -7,17 +7,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(unused)] #![warn(clippy::invalid_regex, clippy::trivial_regex, clippy::regex_macro)] extern crate regex; -use regex::{Regex, RegexSet, RegexBuilder}; -use regex::bytes::{Regex as BRegex, RegexSet as BRegexSet, RegexBuilder as BRegexBuilder}; +use regex::bytes::{Regex as BRegex, RegexBuilder as BRegexBuilder, RegexSet as BRegexSet}; +use regex::{Regex, RegexBuilder, RegexSet}; const OPENING_PAREN: &str = "("; const NOT_A_REAL_REGEX: &str = "foobar"; @@ -37,24 +33,15 @@ fn syntax_error() { let closing_paren = ")"; let not_linted = Regex::new(closing_paren); - let set = RegexSet::new(&[ - r"[a-z]+@[a-z]+\.(com|org|net)", - r"[a-z]+\.(com|org|net)", - ]); + let set = RegexSet::new(&[r"[a-z]+@[a-z]+\.(com|org|net)", r"[a-z]+\.(com|org|net)"]); let bset = BRegexSet::new(&[ r"[a-z]+@[a-z]+\.(com|org|net)", r"[a-z]+\.(com|org|net)", r".", // regression test ]); - let set_error = RegexSet::new(&[ - OPENING_PAREN, - r"[a-z]+\.(com|org|net)", - ]); - let bset_error = BRegexSet::new(&[ - OPENING_PAREN, - r"[a-z]+\.(com|org|net)", - ]); + let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); + let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); let raw_string_error = Regex::new(r"[...\/...]"); let raw_string_error = Regex::new(r#"[...\/...]"#); diff --git a/tests/ui/replace_consts.rs b/tests/ui/replace_consts.rs index 7da1f212a75..ca3d3b13edc 100644 --- a/tests/ui/replace_consts.rs +++ b/tests/ui/replace_consts.rs @@ -7,13 +7,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![feature(integer_atomics)] #![allow(clippy::blacklisted_name)] #![deny(clippy::replace_consts)] use std::sync::atomic::*; -use std::sync::{ONCE_INIT, Once}; +use std::sync::{Once, ONCE_INIT}; #[rustfmt::skip] fn bad() { diff --git a/tests/ui/result_map_unit_fn.rs b/tests/ui/result_map_unit_fn.rs index f24e52b10fd..043b3efd45e 100644 --- a/tests/ui/result_map_unit_fn.rs +++ b/tests/ui/result_map_unit_fn.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![feature(never_type)] #![warn(clippy::result_map_unit_fn)] #![allow(unused)] @@ -40,7 +37,7 @@ fn result_map_unit_fn() { let x = HasResult { field: Ok(10) }; x.field.map(plus_one); - let _ : Result<(), usize> = x.field.map(do_nothing); + let _: Result<(), usize> = x.field.map(do_nothing); x.field.map(do_nothing); @@ -49,47 +46,68 @@ fn result_map_unit_fn() { x.field.map(diverge); let captured = 10; - if let Ok(value) = x.field { do_nothing(value + captured) }; - let _ : Result<(), usize> = x.field.map(|value| do_nothing(value + captured)); + if let Ok(value) = x.field { + do_nothing(value + captured) + }; + let _: Result<(), usize> = x.field.map(|value| do_nothing(value + captured)); x.field.map(|value| x.do_result_nothing(value + captured)); - x.field.map(|value| { x.do_result_plus_one(value + captured); }); - + x.field.map(|value| { + x.do_result_plus_one(value + captured); + }); x.field.map(|value| do_nothing(value + captured)); - x.field.map(|value| { do_nothing(value + captured) }); + x.field.map(|value| do_nothing(value + captured)); - x.field.map(|value| { do_nothing(value + captured); }); - - x.field.map(|value| { { do_nothing(value + captured); } }); + x.field.map(|value| { + do_nothing(value + captured); + }); + x.field.map(|value| { + do_nothing(value + captured); + }); x.field.map(|value| diverge(value + captured)); - x.field.map(|value| { diverge(value + captured) }); + x.field.map(|value| diverge(value + captured)); - x.field.map(|value| { diverge(value + captured); }); - - x.field.map(|value| { { diverge(value + captured); } }); + x.field.map(|value| { + diverge(value + captured); + }); + x.field.map(|value| { + diverge(value + captured); + }); x.field.map(|value| plus_one(value + captured)); - x.field.map(|value| { plus_one(value + captured) }); - x.field.map(|value| { let y = plus_one(value + captured); }); + x.field.map(|value| plus_one(value + captured)); + x.field.map(|value| { + let y = plus_one(value + captured); + }); - x.field.map(|value| { plus_one(value + captured); }); + x.field.map(|value| { + plus_one(value + captured); + }); - x.field.map(|value| { { plus_one(value + captured); } }); + x.field.map(|value| { + plus_one(value + captured); + }); + x.field.map(|ref value| do_nothing(value + captured)); - x.field.map(|ref value| { do_nothing(value + captured) }); + x.field.map(|value| { + do_nothing(value); + do_nothing(value) + }); - - x.field.map(|value| { do_nothing(value); do_nothing(value) }); - - x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); + x.field.map(|value| { + if value > 0 { + do_nothing(value); + do_nothing(value) + } + }); // Suggestion for the let block should be `{ ... }` as it's too difficult to build a // proper suggestion for these cases @@ -97,9 +115,13 @@ fn result_map_unit_fn() { do_nothing(value); do_nothing(value) }); - x.field.map(|value| { do_nothing(value); do_nothing(value); }); + x.field.map(|value| { + do_nothing(value); + do_nothing(value); + }); - // The following should suggest `if let Ok(_X) ...` as it's difficult to generate a proper let variable name for them + // The following should suggest `if let Ok(_X) ...` as it's difficult to generate a proper let + // variable name for them let res: Result = Ok(42).map(diverge); "12".parse::().map(diverge); @@ -110,6 +132,4 @@ fn result_map_unit_fn() { y.map(do_nothing); } -fn main() { -} - +fn main() {} diff --git a/tests/ui/serde.rs b/tests/ui/serde.rs index 47be8423d7b..c52fd065dbe 100644 --- a/tests/ui/serde.rs +++ b/tests/ui/serde.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::serde_api_misuse)] #![allow(dead_code)] @@ -25,13 +22,15 @@ fn expecting(&self, _: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { } fn visit_str(self, _v: &str) -> Result - where E: serde::de::Error, + where + E: serde::de::Error, { unimplemented!() } fn visit_string(self, _v: String) -> Result - where E: serde::de::Error, + where + E: serde::de::Error, { unimplemented!() } @@ -47,11 +46,11 @@ fn expecting(&self, _: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { } fn visit_string(self, _v: String) -> Result - where E: serde::de::Error, + where + E: serde::de::Error, { unimplemented!() } } -fn main() { -} +fn main() {} diff --git a/tests/ui/shadow.rs b/tests/ui/shadow.rs index aa29bd1d79c..e960a6252be 100644 --- a/tests/ui/shadow.rs +++ b/tests/ui/shadow.rs @@ -7,16 +7,22 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - -#![warn(clippy::all, clippy::pedantic, clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)] +#![warn( + clippy::all, + clippy::pedantic, + clippy::shadow_same, + clippy::shadow_reuse, + clippy::shadow_unrelated +)] #![allow(unused_parens, unused_variables, clippy::missing_docs_in_private_items)] -fn id(x: T) -> T { x } +fn id(x: T) -> T { + x +} -fn first(x: (isize, isize)) -> isize { x.0 } +fn first(x: (isize, isize)) -> isize { + x.0 +} fn main() { let mut x = 1; @@ -35,7 +41,9 @@ fn main() { let o = Some(1_u8); - if let Some(p) = o { assert_eq!(1, p); } + if let Some(p) = o { + assert_eq!(1, p); + } match o { Some(p) => p, // no error, because the p above is in its own scope None => 0, diff --git a/tests/ui/short_circuit_statement.rs b/tests/ui/short_circuit_statement.rs index 67999a74e5e..efe9920dd88 100644 --- a/tests/ui/short_circuit_statement.rs +++ b/tests/ui/short_circuit_statement.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::short_circuit_statement)] fn main() { diff --git a/tests/ui/single_char_pattern.rs b/tests/ui/single_char_pattern.rs index c3d846997ec..5277841fe32 100644 --- a/tests/ui/single_char_pattern.rs +++ b/tests/ui/single_char_pattern.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - use std::collections::HashSet; fn main() { diff --git a/tests/ui/single_match.rs b/tests/ui/single_match.rs index dca68e179e7..5a1bde3de32 100644 --- a/tests/ui/single_match.rs +++ b/tests/ui/single_match.rs @@ -7,20 +7,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::single_match)] -fn dummy() { -} +fn dummy() {} -fn single_match(){ +fn single_match() { let x = Some(1u8); match x { - Some(y) => { println!("{:?}", y); } - _ => () + Some(y) => { + println!("{:?}", y); + }, + _ => (), }; let x = Some(1u8); @@ -29,19 +27,19 @@ fn single_match(){ // We suggest `if let Some(y) = x { .. }` because the macro // is expanded before we can do anything. Some(y) => println!("{:?}", y), - _ => () + _ => (), } - let z = (1u8,1u8); + let z = (1u8, 1u8); match z { (2...3, 7...9) => dummy(), - _ => {} + _ => {}, }; // Not linted (pattern guards used) match x { Some(y) if y == 0 => println!("{:?}", y), - _ => () + _ => (), } // Not linted (no block with statements in the single arm) @@ -51,22 +49,25 @@ fn single_match(){ } } -enum Foo { Bar, Baz(u8) } -use Foo::*; +enum Foo { + Bar, + Baz(u8), +} use std::borrow::Cow; +use Foo::*; fn single_match_know_enum() { let x = Some(1u8); - let y : Result<_, i8> = Ok(1i8); + let y: Result<_, i8> = Ok(1i8); match x { Some(y) => dummy(), - None => () + None => (), }; match y { Ok(y) => dummy(), - Err(..) => () + Err(..) => (), }; let c = Cow::Borrowed(""); @@ -89,4 +90,4 @@ fn single_match_know_enum() { } } -fn main() { } +fn main() {} diff --git a/tests/ui/single_match_else.rs b/tests/ui/single_match_else.rs index a7c28c578a4..18c26f7fc26 100644 --- a/tests/ui/single_match_else.rs +++ b/tests/ui/single_match_else.rs @@ -20,7 +20,10 @@ enum ExprNode { fn unwrap_addr() -> Option<&'static ExprNode> { match ExprNode::Butterflies { ExprNode::ExprAddrOf => Some(&NODE), - _ => { let x = 5; None }, + _ => { + let x = 5; + None + }, } } diff --git a/tests/ui/slow_vector_initialization.rs b/tests/ui/slow_vector_initialization.rs index 5364bf70ff0..cf11384467c 100644 --- a/tests/ui/slow_vector_initialization.rs +++ b/tests/ui/slow_vector_initialization.rs @@ -62,13 +62,11 @@ fn resize_vector() { vec1.resize(10, 0); } -fn do_stuff(vec: &mut Vec) { - -} +fn do_stuff(vec: &mut Vec) {} fn extend_vector_with_manipulations_between() { let len = 300; - let mut vec1:Vec = Vec::with_capacity(len); + let mut vec1: Vec = Vec::with_capacity(len); do_stuff(&mut vec1); vec1.extend(repeat(0).take(len)); } diff --git a/tests/ui/starts_ends_with.rs b/tests/ui/starts_ends_with.rs index 5c09e8f1f28..529c2487f54 100644 --- a/tests/ui/starts_ends_with.rs +++ b/tests/ui/starts_ends_with.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(dead_code)] fn main() {} @@ -22,22 +19,28 @@ fn starts_with() { fn chars_cmp_with_unwrap() { let s = String::from("foo"); - if s.chars().next().unwrap() == 'f' { // s.starts_with('f') + if s.chars().next().unwrap() == 'f' { + // s.starts_with('f') // Nothing here } - if s.chars().next_back().unwrap() == 'o' { // s.ends_with('o') + if s.chars().next_back().unwrap() == 'o' { + // s.ends_with('o') // Nothing here } - if s.chars().last().unwrap() == 'o' { // s.ends_with('o') + if s.chars().last().unwrap() == 'o' { + // s.ends_with('o') // Nothing here } - if s.chars().next().unwrap() != 'f' { // !s.starts_with('f') + if s.chars().next().unwrap() != 'f' { + // !s.starts_with('f') // Nothing here } - if s.chars().next_back().unwrap() != 'o' { // !s.ends_with('o') + if s.chars().next_back().unwrap() != 'o' { + // !s.ends_with('o') // Nothing here } - if s.chars().last().unwrap() != 'o' { // !s.ends_with('o') + if s.chars().last().unwrap() != 'o' { + // !s.ends_with('o') // Nothing here } } diff --git a/tests/ui/string_extend.rs b/tests/ui/string_extend.rs index a0cf9c46906..56b466ede20 100644 --- a/tests/ui/string_extend.rs +++ b/tests/ui/string_extend.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #[derive(Copy, Clone)] struct HasChars; diff --git a/tests/ui/strings.rs b/tests/ui/strings.rs index d2062b356dc..e15e80c1928 100644 --- a/tests/ui/strings.rs +++ b/tests/ui/strings.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #[warn(clippy::string_add)] #[allow(clippy::string_add_assign)] fn add_only() { diff --git a/tests/ui/stutter.rs b/tests/ui/stutter.rs index 17d528d1050..922487d671d 100644 --- a/tests/ui/stutter.rs +++ b/tests/ui/stutter.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::stutter)] #![allow(dead_code)] diff --git a/tests/ui/suspicious_arithmetic_impl.rs b/tests/ui/suspicious_arithmetic_impl.rs index 5e7608565ed..ed845b7647a 100644 --- a/tests/ui/suspicious_arithmetic_impl.rs +++ b/tests/ui/suspicious_arithmetic_impl.rs @@ -7,12 +7,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::suspicious_arithmetic_impl)] -use std::ops::{Add, AddAssign, Mul, Sub, Div}; +use std::ops::{Add, AddAssign, Div, Mul, Sub}; #[derive(Copy, Clone)] struct Foo(u32); diff --git a/tests/ui/swap.rs b/tests/ui/swap.rs index 90c2aec9875..e9f227d47a0 100644 --- a/tests/ui/swap.rs +++ b/tests/ui/swap.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::all)] #![allow(clippy::blacklisted_name, unused_assignments)] @@ -54,7 +50,7 @@ fn main() { a = b; b = a; - ; let t = a; +; let t = a; a = b; b = t; @@ -63,7 +59,7 @@ fn main() { c.0 = a; a = c.0; - ; let t = c.0; +; let t = c.0; c.0 = a; a = t; } diff --git a/tests/ui/temporary_assignment.rs b/tests/ui/temporary_assignment.rs index 9c4365bef40..79c090f0572 100644 --- a/tests/ui/temporary_assignment.rs +++ b/tests/ui/temporary_assignment.rs @@ -7,29 +7,29 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::temporary_assignment)] use std::ops::{Deref, DerefMut}; struct Struct { - field: i32 + field: i32, } struct Wrapper<'a> { - inner: &'a mut Struct + inner: &'a mut Struct, } impl<'a> Deref for Wrapper<'a> { type Target = Struct; - fn deref(&self) -> &Struct { self.inner } + fn deref(&self) -> &Struct { + self.inner + } } impl<'a> DerefMut for Wrapper<'a> { - fn deref_mut(&mut self) -> &mut Struct { self.inner } + fn deref_mut(&mut self) -> &mut Struct { + self.inner + } } fn main() { diff --git a/tests/ui/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs index 09ee79f6d8b..b051746bbd4 100644 --- a/tests/ui/toplevel_ref_arg.rs +++ b/tests/ui/toplevel_ref_arg.rs @@ -7,32 +7,28 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::all)] #![allow(unused)] fn the_answer(ref mut x: u8) { - *x = 42; + *x = 42; } fn main() { - let mut x = 0; - the_answer(x); - // Closures should not warn - let y = |ref x| { println!("{:?}", x) }; - y(1u8); + let mut x = 0; + the_answer(x); + // Closures should not warn + let y = |ref x| println!("{:?}", x); + y(1u8); - let ref x = 1; + let ref x = 1; - let ref y: (&_, u8) = (&1, 2); + let ref y: (&_, u8) = (&1, 2); - let ref z = 1 + 2; + let ref z = 1 + 2; - let ref mut z = 1 + 2; + let ref mut z = 1 + 2; - let (ref x, _) = (1,2); // okay, not top level - println!("The answer is {}.", x); + let (ref x, _) = (1, 2); // okay, not top level + println!("The answer is {}.", x); } diff --git a/tests/ui/trailing_zeros.rs b/tests/ui/trailing_zeros.rs index 7ed076225e2..9afb3399c59 100644 --- a/tests/ui/trailing_zeros.rs +++ b/tests/ui/trailing_zeros.rs @@ -7,14 +7,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![feature(stmt_expr_attributes)] - #![allow(unused_parens)] fn main() { let x: i32 = 42; - let _ = #[clippy::author] (x & 0b1111 == 0); // suggest trailing_zeros + let _ = #[clippy::author] + (x & 0b1111 == 0); // suggest trailing_zeros let _ = x & 0b1_1111 == 0; // suggest trailing_zeros let _ = x & 0b1_1010 == 0; // do not lint let _ = x & 1 == 0; // do not lint diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index 285c07a9724..b27014201cd 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(dead_code)] extern crate core; @@ -101,11 +97,11 @@ fn useless() { let _: *const usize = std::mem::transmute(5_isize); - let _ = 5_isize as *const usize; + let _ = 5_isize as *const usize; - let _: *const usize = std::mem::transmute(1+1usize); + let _: *const usize = std::mem::transmute(1 + 1usize); - let _ = (1+1_usize) as *const usize; + let _ = (1 + 1_usize) as *const usize; } } @@ -201,9 +197,7 @@ fn transmute_ptr_to_ptr() { let s = "hello world".to_owned(); let lp = LifetimeParam { s: &s }; let _: &LifetimeParam<'static> = unsafe { std::mem::transmute(&lp) }; - let _: &GenericParam<&LifetimeParam<'static>> = unsafe { - std::mem::transmute(&GenericParam { t: &lp}) - }; + let _: &GenericParam<&LifetimeParam<'static>> = unsafe { std::mem::transmute(&GenericParam { t: &lp }) }; } -fn main() { } +fn main() {} diff --git a/tests/ui/transmute_32bit.rs b/tests/ui/transmute_32bit.rs index 59d3d82ccae..dd96e2dabe1 100644 --- a/tests/ui/transmute_32bit.rs +++ b/tests/ui/transmute_32bit.rs @@ -7,11 +7,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - //ignore-x86_64 - - #[warn(wrong_transmute)] fn main() { unsafe { diff --git a/tests/ui/transmute_64bit.rs b/tests/ui/transmute_64bit.rs index 8620628fdce..fbc298e3a06 100644 --- a/tests/ui/transmute_64bit.rs +++ b/tests/ui/transmute_64bit.rs @@ -7,14 +7,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - //ignore-x86 //no-ignore-x86_64 - - #[warn(clippy::wrong_transmute)] fn main() { unsafe { diff --git a/tests/ui/trivially_copy_pass_by_ref.rs b/tests/ui/trivially_copy_pass_by_ref.rs index 2a0dc22bfef..94e0113e56c 100644 --- a/tests/ui/trivially_copy_pass_by_ref.rs +++ b/tests/ui/trivially_copy_pass_by_ref.rs @@ -7,10 +7,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - -#![allow(clippy::many_single_char_names, clippy::blacklisted_name, clippy::redundant_field_names)] +#![allow( + clippy::many_single_char_names, + clippy::blacklisted_name, + clippy::redundant_field_names +)] #[derive(Copy, Clone)] struct Foo(u32); @@ -20,7 +21,10 @@ #[derive(Copy, Clone)] pub struct Color { - pub r: u8, pub g: u8, pub b: u8, pub a: u8, + pub r: u8, + pub g: u8, + pub b: u8, + pub a: u8, } struct FooRef<'a> { @@ -29,8 +33,7 @@ struct FooRef<'a> { type Baz = u32; -fn good(a: &mut u32, b: u32, c: &Bar) { -} +fn good(a: &mut u32, b: u32, c: &Bar) {} fn good_return_implicit_lt_ref(foo: &Foo) -> &u32 { &foo.0 @@ -42,33 +45,24 @@ fn good_return_explicit_lt_ref<'a>(foo: &'a Foo) -> &'a u32 { } fn good_return_implicit_lt_struct(foo: &Foo) -> FooRef { - FooRef { - foo, - } + FooRef { foo } } #[allow(clippy::needless_lifetimes)] fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> { - FooRef { - foo, - } + FooRef { foo } } -fn bad(x: &u32, y: &Foo, z: &Baz) { -} +fn bad(x: &u32, y: &Foo, z: &Baz) {} impl Foo { - fn good(self, a: &mut u32, b: u32, c: &Bar) { - } + fn good(self, a: &mut u32, b: u32, c: &Bar) {} - fn good2(&mut self) { - } + fn good2(&mut self) {} - fn bad(&self, x: &u32, y: &Foo, z: &Baz) { - } + fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} - fn bad2(x: &u32, y: &Foo, z: &Baz) { - } + fn bad2(x: &u32, y: &Foo, z: &Baz) {} } impl AsRef for Foo { @@ -78,11 +72,9 @@ fn as_ref(&self) -> &u32 { } impl Bar { - fn good(&self, a: &mut u32, b: u32, c: &Bar) { - } + fn good(&self, a: &mut u32, b: u32, c: &Bar) {} - fn bad2(x: &u32, y: &Foo, z: &Baz) { - } + fn bad2(x: &u32, y: &Foo, z: &Baz) {} } trait MyTrait { diff --git a/tests/ui/ty_fn_sig.rs b/tests/ui/ty_fn_sig.rs index 82b5deda3ba..17027306367 100644 --- a/tests/ui/ty_fn_sig.rs +++ b/tests/ui/ty_fn_sig.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - // Regression test pub fn retry(f: F) { diff --git a/tests/ui/types.rs b/tests/ui/types.rs index 03676f69ab4..f0ede2fd48c 100644 --- a/tests/ui/types.rs +++ b/tests/ui/types.rs @@ -7,14 +7,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - // should not warn on lossy casting in constant types // because not supported yet -const C : i32 = 42; -const C_I64 : i64 = C as i64; +const C: i32 = 42; +const C_I64: i64 = C as i64; fn main() { // should suggest i64::from(c) - let c : i32 = 42; - let c_i64 : i64 = c as i64; + let c: i32 = 42; + let c_i64: i64 = c as i64; } diff --git a/tests/ui/unicode.rs b/tests/ui/unicode.rs index 8de17fea220..0e1200db227 100644 --- a/tests/ui/unicode.rs +++ b/tests/ui/unicode.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[warn(clippy::zero_width_space)] fn zero() { print!("Here >​< is a ZWS, and ​another"); diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs index 058c6563c5a..571882ced0f 100644 --- a/tests/ui/unit_arg.rs +++ b/tests/ui/unit_arg.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::unit_arg)] #![allow(clippy::no_effect)] @@ -33,7 +30,9 @@ fn bar(&self, t: T) { fn bad() { foo({}); - foo({ 1; }); + foo({ + 1; + }); foo(foo(1)); foo({ foo(1); @@ -41,7 +40,9 @@ fn bad() { }); foo3({}, 2, 2); let b = Bar; - b.bar({ 1; }); + b.bar({ + 1; + }); } fn ok() { diff --git a/tests/ui/unit_cmp.rs b/tests/ui/unit_cmp.rs index 10eb0c70c54..0bc87f43c15 100644 --- a/tests/ui/unit_cmp.rs +++ b/tests/ui/unit_cmp.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::unit_cmp)] #![allow(clippy::no_effect, clippy::unnecessary_operation)] @@ -19,13 +15,18 @@ fn main() { // this is fine - if true == false { - } + if true == false {} // this warns - if { true; } == { false; } { - } + if { + true; + } == { + false; + } {} - if { true; } > { false; } { - } + if { + true; + } > { + false; + } {} } diff --git a/tests/ui/unknown_clippy_lints.rs b/tests/ui/unknown_clippy_lints.rs index d0b4ae9f532..e583614a93c 100644 --- a/tests/ui/unknown_clippy_lints.rs +++ b/tests/ui/unknown_clippy_lints.rs @@ -11,6 +11,4 @@ #![warn(clippy::pedantic)] #[warn(clippy::if_not_els)] -fn main() { - -} +fn main() {} diff --git a/tests/ui/unnecessary_clone.rs b/tests/ui/unnecessary_clone.rs index 28cad1d881f..40c4b4961e9 100644 --- a/tests/ui/unnecessary_clone.rs +++ b/tests/ui/unnecessary_clone.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::clone_on_ref_ptr)] #![allow(unused)] @@ -70,14 +67,14 @@ fn clone_on_double_ref() { let y = &&x; let z: &Vec<_> = y.clone(); - println!("{:p} {:p}",*y, z); + println!("{:p} {:p}", *y, z); } fn iter_clone_collect() { - let v = [1,2,3,4,5]; - let v2 : Vec = v.iter().cloned().collect(); - let v3 : HashSet = v.iter().cloned().collect(); - let v4 : VecDeque = v.iter().cloned().collect(); + let v = [1, 2, 3, 4, 5]; + let v2: Vec = v.iter().cloned().collect(); + let v3: HashSet = v.iter().cloned().collect(); + let v4: VecDeque = v.iter().cloned().collect(); } mod many_derefs { @@ -92,9 +89,11 @@ macro_rules! impl_deref { ($src:ident, $dst:ident) => { impl std::ops::Deref for $src { type Target = $dst; - fn deref(&self) -> &Self::Target { &$dst } + fn deref(&self) -> &Self::Target { + &$dst + } } - } + }; } impl_deref!(A, B); @@ -102,7 +101,9 @@ fn deref(&self) -> &Self::Target { &$dst } impl_deref!(C, D); impl std::ops::Deref for D { type Target = &'static E; - fn deref(&self) -> &Self::Target { &&E } + fn deref(&self) -> &Self::Target { + &&E + } } fn go1() { diff --git a/tests/ui/unnecessary_filter_map.rs b/tests/ui/unnecessary_filter_map.rs index 8b74ca3a425..a0c183a58cc 100644 --- a/tests/ui/unnecessary_filter_map.rs +++ b/tests/ui/unnecessary_filter_map.rs @@ -7,10 +7,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - fn main() { let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); - let _ = (0..4).filter_map(|x| { if x > 1 { return Some(x); }; None }); + let _ = (0..4).filter_map(|x| { + if x > 1 { + return Some(x); + }; + None + }); let _ = (0..4).filter_map(|x| match x { 0 | 1 => None, _ => Some(x), diff --git a/tests/ui/unnecessary_fold.rs b/tests/ui/unnecessary_fold.rs index e8d84ecea8c..4b4a6ee044c 100644 --- a/tests/ui/unnecessary_fold.rs +++ b/tests/ui/unnecessary_fold.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - /// Calls which should trigger the `UNNECESSARY_FOLD` lint fn unnecessary_fold() { // Can be replaced by .any diff --git a/tests/ui/unnecessary_operation.rs b/tests/ui/unnecessary_operation.rs index de44047c867..34e1112f006 100644 --- a/tests/ui/unnecessary_operation.rs +++ b/tests/ui/unnecessary_operation.rs @@ -13,14 +13,14 @@ struct Tuple(i32); struct Struct { - field: i32 + field: i32, } enum Enum { Tuple(i32), Struct { field: i32 }, } struct DropStruct { - field: i32 + field: i32, } impl Drop for DropStruct { fn drop(&mut self) {} @@ -40,9 +40,15 @@ struct FooString { s: String, } -fn get_number() -> i32 { 0 } -fn get_struct() -> Struct { Struct { field: 0 } } -fn get_drop_struct() -> DropStruct { DropStruct { field: 0 } } +fn get_number() -> i32 { + 0 +} +fn get_struct() -> Struct { + Struct { field: 0 } +} +fn get_drop_struct() -> DropStruct { + DropStruct { field: 0 } +} fn main() { Tuple(get_number()); @@ -63,8 +69,12 @@ fn main() { (42, get_number()).1; [get_number(); 55]; [42; 55][get_number() as usize]; - {get_number()}; - FooString { s: String::from("blah"), }; + { + get_number() + }; + FooString { + s: String::from("blah"), + }; // Do not warn DropTuple(get_number()); diff --git a/tests/ui/unnecessary_ref.rs b/tests/ui/unnecessary_ref.rs index adc628fe8b6..31aa367e506 100644 --- a/tests/ui/unnecessary_ref.rs +++ b/tests/ui/unnecessary_ref.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![feature(tool_attributes)] #![feature(stmt_expr_attributes)] diff --git a/tests/ui/unneeded_field_pattern.rs b/tests/ui/unneeded_field_pattern.rs index 128a3fee429..14676c1e76f 100644 --- a/tests/ui/unneeded_field_pattern.rs +++ b/tests/ui/unneeded_field_pattern.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::unneeded_field_pattern)] #[allow(dead_code, unused)] @@ -24,13 +20,12 @@ fn main() { let f = Foo { a: 0, b: 0, c: 0 }; match f { - Foo { a: _, b: 0, .. } => {} - - Foo { a: _, b: _, c: _ } => {} + Foo { a: _, b: 0, .. } => {}, + Foo { a: _, b: _, c: _ } => {}, } match f { - Foo { b: 0, .. } => {} // should be OK - Foo { .. } => {} // and the Force might be with this one + Foo { b: 0, .. } => {}, // should be OK + Foo { .. } => {}, // and the Force might be with this one } } diff --git a/tests/ui/unreadable_literal.rs b/tests/ui/unreadable_literal.rs index 9142b3d2911..ad29fcf8fe4 100644 --- a/tests/ui/unreadable_literal.rs +++ b/tests/ui/unreadable_literal.rs @@ -7,13 +7,20 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #[warn(clippy::unreadable_literal)] #[allow(unused_variables)] fn main() { - let good = (0b1011_i64, 0o1_234_u32, 0x1_234_567, 65536, 1_2345_6789, 1234_f32, 1_234.12_f32, 1_234.123_f32, 1.123_4_f32); + let good = ( + 0b1011_i64, + 0o1_234_u32, + 0x1_234_567, + 65536, + 1_2345_6789, + 1234_f32, + 1_234.12_f32, + 1_234.123_f32, + 1.123_4_f32, + ); let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32); let good_sci = 1.1234e1; let bad_sci = 1.123456e1; diff --git a/tests/ui/unsafe_removed_from_name.rs b/tests/ui/unsafe_removed_from_name.rs index 9c1800467d3..bfab077375d 100644 --- a/tests/ui/unsafe_removed_from_name.rs +++ b/tests/ui/unsafe_removed_from_name.rs @@ -7,23 +7,20 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(unused_imports)] #![allow(dead_code)] #![warn(clippy::unsafe_removed_from_name)] -use std::cell::{UnsafeCell as TotallySafeCell}; +use std::cell::UnsafeCell as TotallySafeCell; use std::cell::UnsafeCell as TotallySafeCellAgain; // Shouldn't error -use std::cell::{UnsafeCell as SuperDangerousUnsafeCell}; -use std::cell::{UnsafeCell as Dangerunsafe}; -use std::cell::UnsafeCell as Bombsawayunsafe; -use std::cell::{RefCell as ProbablyNotUnsafe}; +use std::cell::RefCell as ProbablyNotUnsafe; use std::cell::RefCell as RefCellThatCantBeUnsafe; +use std::cell::UnsafeCell as SuperDangerousUnsafeCell; +use std::cell::UnsafeCell as Dangerunsafe; +use std::cell::UnsafeCell as Bombsawayunsafe; mod mod_with_some_unsafe_things { pub struct Safe {} diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs index a47a6ccfdf6..a125d0397af 100644 --- a/tests/ui/unused_io_amount.rs +++ b/tests/ui/unused_io_amount.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(dead_code)] #![warn(clippy::unused_io_amount)] @@ -37,5 +33,4 @@ fn unwrap(s: &mut T) { s.read(&mut buf).unwrap(); } -fn main() { -} +fn main() {} diff --git a/tests/ui/unused_labels.rs b/tests/ui/unused_labels.rs index d7d843dfc25..8db29dcf3fc 100644 --- a/tests/ui/unused_labels.rs +++ b/tests/ui/unused_labels.rs @@ -7,16 +7,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![allow(dead_code, clippy::items_after_statements, clippy::never_loop)] #![warn(clippy::unused_label)] fn unused_label() { 'label: for i in 1..2 { - if i > 4 { continue } + if i > 4 { + continue; + } } } @@ -26,9 +24,10 @@ fn foo() { } } - fn bla() { - 'a: loop { break } + 'a: loop { + break; + } fn blub() {} } diff --git a/tests/ui/unused_lt.rs b/tests/ui/unused_lt.rs index de13864421e..99e80103f1f 100644 --- a/tests/ui/unused_lt.rs +++ b/tests/ui/unused_lt.rs @@ -7,25 +7,20 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - -#![allow(unused, dead_code, clippy::needless_lifetimes, clippy::needless_pass_by_value, clippy::trivially_copy_pass_by_ref)] +#![allow( + unused, + dead_code, + clippy::needless_lifetimes, + clippy::needless_pass_by_value, + clippy::trivially_copy_pass_by_ref +)] #![warn(clippy::extra_unused_lifetimes)] -fn empty() { +fn empty() {} -} +fn used_lt<'a>(x: &'a u8) {} - -fn used_lt<'a>(x: &'a u8) { - -} - - -fn unused_lt<'a>(x: u8) { - -} +fn unused_lt<'a>(x: u8) {} fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) { // 'a is useless here since it's not directly bound @@ -39,19 +34,14 @@ fn lt_return_only<'a>() -> &'a u8 { panic!() } -fn unused_lt_blergh<'a>(x: Option>) { - -} - +fn unused_lt_blergh<'a>(x: Option>) {} trait Foo<'a> { fn x(&self, a: &'a u8); } impl<'a> Foo<'a> for u8 { - fn x(&self, a: &'a u8) { - - } + fn x(&self, a: &'a u8) {} } struct Bar; @@ -61,20 +51,23 @@ fn x<'a>(&self) {} } // test for #489 (used lifetimes in bounds) -pub fn parse<'a, I: Iterator>(_it: &mut I) { +pub fn parse<'a, I: Iterator>(_it: &mut I) { unimplemented!() } -pub fn parse2<'a, I>(_it: &mut I) where I: Iterator{ +pub fn parse2<'a, I>(_it: &mut I) +where + I: Iterator, +{ unimplemented!() } -struct X { x: u32 } +struct X { + x: u32, +} impl X { fn self_ref_with_lifetime<'a>(&'a self) {} fn explicit_self_with_lifetime<'a>(self: &'a Self) {} } -fn main() { - -} +fn main() {} diff --git a/tests/ui/unwrap_or.rs b/tests/ui/unwrap_or.rs index 80965635a08..8573f78d43b 100644 --- a/tests/ui/unwrap_or.rs +++ b/tests/ui/unwrap_or.rs @@ -7,8 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - #![warn(clippy::all)] fn main() { @@ -16,7 +14,5 @@ fn main() { } fn new_lines() { - let s = Some(String::from("test string")) - .unwrap_or("Fail".to_string()) - .len(); + let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); } diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index 60dc2d54d05..c21df403035 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::use_self)] #![allow(dead_code)] #![allow(clippy::should_implement_trait)] @@ -57,21 +54,24 @@ fn default() -> Self { //todo the lint does not handle lifetimed struct //the following module should trigger the lint on the third method only mod lifetimes { - struct Foo<'a>{foo_str: &'a str} + struct Foo<'a> { + foo_str: &'a str, + } impl<'a> Foo<'a> { - // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) -> Foo<'b>` + // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) -> + // Foo<'b>` fn foo(s: &str) -> Foo { Foo { foo_str: s } } // cannot replace with `Self`, because that's `Foo<'a>` fn bar() -> Foo<'static> { - Foo { foo_str: "foo"} + Foo { foo_str: "foo" } } // `Self` is applicable here fn clone(&self) -> Foo<'a> { - Foo {foo_str: self.foo_str} + Foo { foo_str: self.foo_str } } } } @@ -105,8 +105,7 @@ fn mut_refs(p1: &mut Bad) -> &mut Bad { p1 } - fn nested(_p1: Box, _p2: (&u8, &Bad)) { - } + fn nested(_p1: Box, _p2: (&u8, &Bad)) {} fn vals(_: Bad) -> Bad { Bad::default() @@ -137,8 +136,7 @@ fn mut_refs(p1: &mut Self) -> &mut Self { p1 } - fn nested(_p1: Box, _p2: (&u8, &Self)) { - } + fn nested(_p1: Box, _p2: (&u8, &Self)) {} fn vals(_: Self) -> Self { Self::default() @@ -175,8 +173,7 @@ fn mut_refs(p1: &mut Self) -> &mut Self { p1 } - fn nested(_p1: Box, _p2: (&Self, &Self)) { - } + fn nested(_p1: Box, _p2: (&Self, &Self)) {} fn vals(_: Self) -> Self { Self::default() @@ -210,11 +207,11 @@ mod existential { struct Foo; impl Foo { - fn bad(foos: &[Self]) -> impl Iterator { + fn bad(foos: &[Self]) -> impl Iterator { foos.iter() } - fn good(foos: &[Self]) -> impl Iterator { + fn good(foos: &[Self]) -> impl Iterator { foos.iter() } } @@ -239,7 +236,7 @@ enum Enum { A, } impl Enum { - fn a () { + fn a() { use self::Enum::*; } } diff --git a/tests/ui/used_underscore_binding.rs b/tests/ui/used_underscore_binding.rs index b6b055e58bc..bd20cc5f48a 100644 --- a/tests/ui/used_underscore_binding.rs +++ b/tests/ui/used_underscore_binding.rs @@ -7,11 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::all)] - #![allow(clippy::blacklisted_name)] #![warn(clippy::used_underscore_binding)] @@ -19,7 +15,7 @@ macro_rules! test_macro { () => {{ let _foo = 42; _foo + 1 - }} + }}; } /// Test that we lint if we use a binding with a single leading underscore @@ -74,7 +70,7 @@ fn _fn_test() {} struct _StructTest; enum _EnumTest { _Empty, - _Value(_StructTest) + _Value(_StructTest), } /// Test that we do not lint for non-variable bindings diff --git a/tests/ui/useless_asref.rs b/tests/ui/useless_asref.rs index a5e9caf3a67..34c0f5095db 100644 --- a/tests/ui/useless_asref.rs +++ b/tests/ui/useless_asref.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![deny(clippy::useless_asref)] #![allow(clippy::trivially_copy_pass_by_ref)] use std::fmt::Debug; @@ -18,7 +15,9 @@ #[allow(clippy::should_implement_trait)] impl FakeAsRef { - fn as_ref(&self) -> &Self { self } + fn as_ref(&self) -> &Self { + self + } } struct MoreRef; @@ -29,14 +28,22 @@ fn as_ref(&self) -> &&'a &'b &'c MoreRef { } } -fn foo_rstr(x: &str) { println!("{:?}", x); } -fn foo_rslice(x: &[i32]) { println!("{:?}", x); } -fn foo_mrslice(x: &mut [i32]) { println!("{:?}", x); } -fn foo_rrrrmr(_: &&&&MoreRef) { println!("so many refs"); } +fn foo_rstr(x: &str) { + println!("{:?}", x); +} +fn foo_rslice(x: &[i32]) { + println!("{:?}", x); +} +fn foo_mrslice(x: &mut [i32]) { + println!("{:?}", x); +} +fn foo_rrrrmr(_: &&&&MoreRef) { + println!("so many refs"); +} fn not_ok() { let rstr: &str = "hello"; - let mut mrslice: &mut [i32] = &mut [1,2,3]; + let mut mrslice: &mut [i32] = &mut [1, 2, 3]; { let rslice: &[i32] = &*mrslice; @@ -75,8 +82,8 @@ fn not_ok() { fn ok() { let string = "hello".to_owned(); - let mut arr = [1,2,3]; - let mut vec = vec![1,2,3]; + let mut arr = [1, 2, 3]; + let mut vec = vec![1, 2, 3]; { foo_rstr(string.as_ref()); @@ -109,8 +116,12 @@ fn ok() { generic_ok(&mut arr); } -fn foo_mrt(t: &mut T) { println!("{:?}", t); } -fn foo_rt(t: &T) { println!("{:?}", t); } +fn foo_mrt(t: &mut T) { + println!("{:?}", t); +} +fn foo_rt(t: &T) { + println!("{:?}", t); +} fn generic_not_ok + AsRef + Debug + ?Sized>(mrt: &mut T) { foo_mrt(mrt.as_mut()); diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index 9fb84866ef6..4ee6520443d 100644 --- a/tests/ui/useless_attribute.rs +++ b/tests/ui/useless_attribute.rs @@ -7,15 +7,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![warn(clippy::useless_attribute)] #[allow(dead_code)] #[cfg_attr(feature = "cargo-clippy", allow(dead_code))] -#[cfg_attr(feature = "cargo-clippy", - allow(dead_code))] +#[cfg_attr(feature = "cargo-clippy", allow(dead_code))] #[allow(unused_imports)] #[allow(unused_extern_crates)] #[macro_use] @@ -26,7 +22,10 @@ use std::collections; // don't lint on deprecated for `use` items -mod foo { #[deprecated] pub struct Bar; } +mod foo { + #[deprecated] + pub struct Bar; +} #[allow(deprecated)] pub use foo::Bar; diff --git a/tests/ui/vec.rs b/tests/ui/vec.rs index e74aded5728..a7ccda375bf 100644 --- a/tests/ui/vec.rs +++ b/tests/ui/vec.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::useless_vec)] #[derive(Debug)] @@ -37,10 +33,10 @@ fn main() { on_slice(&vec![1, 2]); on_slice(&[1, 2]); - on_slice(&vec ![1, 2]); + on_slice(&vec![1, 2]); on_slice(&[1, 2]); - on_slice(&vec!(1, 2)); + on_slice(&vec![1, 2]); on_slice(&[1, 2]); on_slice(&vec![1; 2]); diff --git a/tests/ui/while_loop.rs b/tests/ui/while_loop.rs index 3cc7c52df5d..e4c7047df91 100644 --- a/tests/ui/while_loop.rs +++ b/tests/ui/while_loop.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::while_let_loop, clippy::empty_loop, clippy::while_let_on_iterator)] #![allow(dead_code, clippy::never_loop, unused, clippy::cyclomatic_complexity)] @@ -20,10 +16,11 @@ fn main() { if let Some(_x) = y { let _v = 1; } else { - break + break; } } - loop { // no error, break is not in else clause + loop { + // no error, break is not in else clause if let Some(_x) = y { let _v = 1; } @@ -32,13 +29,13 @@ fn main() { loop { match y { Some(_x) => true, - None => break + None => break, }; } loop { let x = match y { Some(x) => x, - None => break + None => break, }; let _x = x; let _str = "foo"; @@ -48,19 +45,25 @@ fn main() { Some(x) => x, None => break, }; - { let _a = "bar"; }; - { let _b = "foobar"; } + { + let _a = "bar"; + }; + { + let _b = "foobar"; + } } - loop { // no error, else branch does something other than break + loop { + // no error, else branch does something other than break match y { Some(_x) => true, _ => { let _z = 1; break; - } + }, }; } - while let Some(x) = y { // no error, obviously + while let Some(x) = y { + // no error, obviously println!("{}", x); } @@ -68,7 +71,7 @@ fn main() { loop { let (e, l) = match "".split_whitespace().next() { Some(word) => (word.is_empty(), word.len()), - None => break + None => break, }; let _ = (e, l); @@ -91,7 +94,8 @@ fn main() { while let None = iter.next() {} // this is fine (if nonsensical) let mut iter = 1..20; - if let Some(x) = iter.next() { // also fine + if let Some(x) = iter.next() { + // also fine println!("{}", x) } @@ -109,7 +113,9 @@ fn main() { // or this let mut iter = 1u32..20; - while let Some(x) = iter.next() {break;} + while let Some(x) = iter.next() { + break; + } println!("Remaining iter {:?}", iter); // or this @@ -128,7 +134,7 @@ fn no_panic(slice: &[T]) { loop { let _ = match iter.next() { Some(ele) => ele, - None => break + None => break, }; loop {} } @@ -143,8 +149,8 @@ fn issue1017() { Err(_) => len = 0, Ok(length) => { len = length; - break - } + break; + }, } } } @@ -155,20 +161,17 @@ fn refutable() { let mut b = a.iter(); // consume all the 42s - while let Some(&42) = b.next() { - } + while let Some(&42) = b.next() {} let a = [(1, 2, 3)]; let mut b = a.iter(); - while let Some(&(1, 2, 3)) = b.next() { - } + while let Some(&(1, 2, 3)) = b.next() {} let a = [Some(42)]; let mut b = a.iter(); - while let Some(&None) = b.next() { - } + while let Some(&None) = b.next() {} /* This gives “refutable pattern in `for` loop binding: `&_` not covered” for &42 in b {} @@ -177,20 +180,22 @@ fn refutable() { // */ let mut y = a.iter(); - loop { // x is reused, so don't lint here - while let Some(v) = y.next() { - } + loop { + // x is reused, so don't lint here + while let Some(v) = y.next() {} } let mut y = a.iter(); for _ in 0..2 { - while let Some(v) = y.next() { // y is reused, don't lint + while let Some(v) = y.next() { + // y is reused, don't lint } } loop { let mut y = a.iter(); - while let Some(v) = y.next() { // use a for loop here + while let Some(v) = y.next() { + // use a for loop here } } diff --git a/tests/ui/write_literal.rs b/tests/ui/write_literal.rs index 7917479ed67..0ba1943e6d8 100644 --- a/tests/ui/write_literal.rs +++ b/tests/ui/write_literal.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(unused_must_use)] #![warn(clippy::write_literal)] @@ -23,17 +20,17 @@ fn main() { writeln!(&mut v, "Hello"); let world = "world"; writeln!(&mut v, "Hello {}", world); - writeln!(&mut v, "Hello {world}", world=world); + writeln!(&mut v, "Hello {world}", world = world); writeln!(&mut v, "3 in hex is {:X}", 3); writeln!(&mut v, "2 + 1 = {:.4}", 3); writeln!(&mut v, "2 + 1 = {:5.4}", 3); writeln!(&mut v, "Debug test {:?}", "hello, world"); writeln!(&mut v, "{0:8} {1:>8}", "hello", "world"); writeln!(&mut v, "{1:8} {0:>8}", "hello", "world"); - writeln!(&mut v, "{foo:8} {bar:>8}", foo="hello", bar="world"); - writeln!(&mut v, "{bar:8} {foo:>8}", foo="hello", bar="world"); - writeln!(&mut v, "{number:>width$}", number=1, width=6); - writeln!(&mut v, "{number:>0width$}", number=1, width=6); + writeln!(&mut v, "{foo:8} {bar:>8}", foo = "hello", bar = "world"); + writeln!(&mut v, "{bar:8} {foo:>8}", foo = "hello", bar = "world"); + writeln!(&mut v, "{number:>width$}", number = 1, width = 6); + writeln!(&mut v, "{number:>0width$}", number = 1, width = 6); // these should throw warnings writeln!(&mut v, "{} of {:b} people know binary, the other half doesn't", 1, 2); @@ -50,6 +47,6 @@ fn main() { writeln!(&mut v, "{1} {0}", "hello", "world"); // named args shouldn't change anything either - writeln!(&mut v, "{foo} {bar}", foo="hello", bar="world"); - writeln!(&mut v, "{bar} {foo}", foo="hello", bar="world"); + writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world"); + writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world"); } diff --git a/tests/ui/write_with_newline.rs b/tests/ui/write_with_newline.rs index e9fcff0b3dd..dbfa02d20a1 100644 --- a/tests/ui/write_with_newline.rs +++ b/tests/ui/write_with_newline.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(clippy::write_literal)] #![warn(clippy::write_with_newline)] diff --git a/tests/ui/writeln_empty_string.rs b/tests/ui/writeln_empty_string.rs index e272a5af88b..71b5df48bfa 100644 --- a/tests/ui/writeln_empty_string.rs +++ b/tests/ui/writeln_empty_string.rs @@ -7,9 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - #![allow(unused_must_use)] #![warn(clippy::writeln_empty_string)] use std::io::Write; @@ -27,5 +24,4 @@ fn main() { writeln!(&mut v); writeln!(&mut v, " "); write!(&mut v, ""); - } diff --git a/tests/ui/wrong_self_convention.rs b/tests/ui/wrong_self_convention.rs index d1c7424c8d7..3c69c9ad03f 100644 --- a/tests/ui/wrong_self_convention.rs +++ b/tests/ui/wrong_self_convention.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #![warn(clippy::wrong_self_convention)] #![warn(clippy::wrong_pub_self_convention)] #![allow(dead_code, clippy::trivially_copy_pass_by_ref)] @@ -21,7 +17,6 @@ fn main() {} struct Foo; impl Foo { - fn as_i32(self) {} fn as_u32(&self) {} fn into_i32(self) {} @@ -39,14 +34,13 @@ pub fn from_i64(self) {} #[allow(clippy::wrong_self_convention)] pub fn from_cake(self) {} - fn as_x>(_: F) { } - fn as_y>(_: F) { } + fn as_x>(_: F) {} + fn as_y>(_: F) {} } struct Bar; impl Bar { - fn as_i32(self) {} fn as_u32(&self) {} fn into_i32(&self) {} diff --git a/tests/ui/zero_div_zero.rs b/tests/ui/zero_div_zero.rs index 4e2272c8e09..68e9437273f 100644 --- a/tests/ui/zero_div_zero.rs +++ b/tests/ui/zero_div_zero.rs @@ -7,20 +7,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[allow(unused_variables)] #[warn(clippy::zero_divided_by_zero)] fn main() { let nan = 0.0 / 0.0; let f64_nan = 0.0 / 0.0f64; let other_f64_nan = 0.0f64 / 0.0; - let one_more_f64_nan = 0.0f64/0.0f64; + let one_more_f64_nan = 0.0f64 / 0.0f64; let zero = 0.0; let other_zero = 0.0; let other_nan = zero / other_zero; // fine - this lint doesn't propegate constants. - let not_nan = 2.0/0.0; // not an error: 2/0 = inf - let also_not_nan = 0.0/2.0; // not an error: 0/2 = 0 + let not_nan = 2.0 / 0.0; // not an error: 2/0 = inf + let also_not_nan = 0.0 / 2.0; // not an error: 0/2 = 0 } diff --git a/tests/ui/zero_ptr.rs b/tests/ui/zero_ptr.rs index fbe4f950da5..9930b8a4c6b 100644 --- a/tests/ui/zero_ptr.rs +++ b/tests/ui/zero_ptr.rs @@ -7,10 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - - - #[allow(unused_variables)] fn main() { let x = 0 as *const usize;