rustfmt tests

This commit is contained in:
Matthias Krüger 2018-12-09 23:26:16 +01:00
parent 1218145bc9
commit 435299be30
252 changed files with 1881 additions and 1983 deletions

View File

@ -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 {

View File

@ -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;
}

View File

@ -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!(),
}

View File

@ -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() {}

View File

@ -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];
}
_ => {}
},
_ => {},
}
}

View File

@ -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]),
)
},
}
}

View File

@ -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>;

View File

@ -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
}

View File

@ -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];
}
},
"" => (),
_ => (),
}

View File

@ -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();
}

View File

@ -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:
//

View File

@ -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() {}

View File

@ -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<String> for Ice {

View File

@ -7,7 +7,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[derive(Clone)]
pub struct HashMap<V, S> {
hash_builder: S,
@ -17,7 +16,7 @@ pub struct HashMap<V, S> {
#[derive(Clone)]
pub struct RawTable<V> {
size: usize,
val: V
val: V,
}
fn main() {}
fn main() {}

View File

@ -7,9 +7,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![deny(clippy::all)]
fn core() {}

View File

@ -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)]

View File

@ -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() {}

View File

@ -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, F: Fn() -> B>(&self, f: F) -> B;
}

View File

@ -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!();
}

View File

@ -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

View File

@ -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!(),
}
}

View File

@ -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)]

View File

@ -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() {}

View File

@ -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)]

View File

@ -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;
struct Foo;

View File

@ -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) {

View File

@ -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)]

View File

@ -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() {

View File

@ -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]

View File

@ -7,5 +7,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {}

View File

@ -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() {}

View File

@ -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() {}

View File

@ -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)]

View File

@ -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));

View File

@ -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() {}

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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<str> Add is not commutative
buf = cows + buf;
println!("{}", buf);
}

View File

@ -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()
}
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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() {

View File

@ -7,7 +7,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tool_attributes)]
fn main() {

View File

@ -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;

View File

@ -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: ()) {}

View File

@ -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<F: FnOnce(T) -> bool, T>(pfn: F, val:T) -> bool {
fn predicate<F: FnOnce(T) -> 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);

View File

@ -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"
};
}

View File

@ -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<E> { Ok, Err(E) }
enum CustomResultErr<E> { Ok, Err(E) }
enum CustomSomeSome<T> { Some(T), None }
enum CustomSomeNone<T> { Some(T), None }
enum CustomResultOk<E> {
Ok,
Err(E),
}
enum CustomResultErr<E> {
Ok,
Err(E),
}
enum CustomSomeSome<T> {
Some(T),
None,
}
enum CustomSomeNone<T> {
Some(T),
None,
}
impl<E> CustomResultOk<E> {
pub fn is_ok(&self) -> bool { true }
pub fn is_ok(&self) -> bool {
true
}
}
impl<E> CustomResultErr<E> {
pub fn is_err(&self) -> bool { true }
pub fn is_err(&self) -> bool {
true
}
}
impl<T> CustomSomeSome<T> {
pub fn is_some(&self) -> bool { true }
pub fn is_some(&self) -> bool {
true
}
}
impl<T> CustomSomeNone<T> {
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<usize, usize> = 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)]

View File

@ -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<bool>
foo: &'a Box<bool>,
}
trait Test4 {
@ -49,7 +45,7 @@ pub fn test6() {
}
struct Test7<'a> {
foo: &'a Box<Any>
foo: &'a Box<Any>,
}
trait Test8 {
@ -71,7 +67,7 @@ pub fn test10() {
}
struct Test11<'a> {
foo: &'a Box<Any + Send>
foo: &'a Box<Any + Send>,
}
trait Test12 {
@ -84,7 +80,7 @@ fn test4(a: &Box<Any + 'static>) {
}
}
fn main(){
fn main() {
test1(&mut Box::new(false));
test2();
test5(&mut (Box::new(false) as Box<Any>));

View File

@ -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<Vec<bool>>) {
println!("{:?}", foo.get(0))
}
pub fn test2(foo: Box<Fn(Vec<u32>)>) { // pass if #31 is fixed
pub fn test2(foo: Box<Fn(Vec<u32>)>) {
// pass if #31 is fixed
foo(vec![1, 2, 3])
}
@ -36,7 +33,7 @@ pub fn test_local_not_linted() {
let _: Box<Vec<bool>>;
}
fn main(){
fn main() {
test(Box::new(Vec::new()));
test2(Box::new(|v| println!("{:?}", v)));
test_macro();

View File

@ -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<u32>(a: u32) -> u32 {
@ -17,5 +14,4 @@ fn foo<u32>(a: u32) -> u32 {
// ^ rustc's type error
}
fn main() {
}
fn main() {}

View File

@ -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];

View File

@ -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;

View File

@ -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)]

View File

@ -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() {

View File

@ -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() {

View File

@ -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

View File

@ -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() {

View File

@ -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).
}
}

View File

@ -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<T> {
#[doc(hidden)]

View File

@ -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;

View File

@ -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() {

View File

@ -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!");
}

View File

@ -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;

View File

@ -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() {

View File

@ -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<Vec<Box<(u32, u32, u32, u32)>>>) { }
fn impl_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
}
trait T {
const A: Vec<Vec<Box<(u32, u32, u32, u32)>>>;
type B = Vec<Vec<Box<(u32, u32, u32, u32)>>>;
fn method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>);
fn def_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { }
fn def_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
}
fn test1() -> Vec<Vec<Box<(u32, u32, u32, u32)>>> { vec![] }
fn test1() -> Vec<Vec<Box<(u32, u32, u32, u32)>>> {
vec![]
}
fn test2(_x: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { }
fn test2(_x: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
fn test3() {
let _y: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![];
@ -67,5 +66,4 @@ struct D {
),
}
fn main() {
}
fn main() {}

View File

@ -7,7 +7,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[derive(Debug)]
struct Foo {}

View File

@ -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>(_: 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::<u8>(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::<u8> {}
}
else {
} else {
if let Some(42) = None {}
}
if true {
if let Some(42) = None::<u8> {}
}
else {
} else {
if let Some(42) = None::<u32> {}
}
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 {
}
}

View File

@ -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)]

View File

@ -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)]

View File

@ -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 {}
}
}

View File

@ -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)]

View File

@ -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

View File

@ -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();

View File

@ -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() {}

View File

@ -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<u64> 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<Baz> for Baz {
fn eq(&self, _: &Baz) -> bool { true }
fn eq(&self, _: &Baz) -> bool {
true
}
}
#[derive(PartialEq)]
@ -49,7 +51,9 @@ fn hash<H: Hasher>(&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<T> {
}
impl<T> Clone for Generic<T> {
fn clone(&self) -> Self { unimplemented!() }
fn clone(&self) -> Self {
unimplemented!()
}
}
fn main() {}

View File

@ -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)]

View File

@ -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<u8>;
fn foo(LinkedList<u8>);
const BAR : Option<LinkedList<u8>>;
const BAR: Option<LinkedList<u8>>;
}
// ok, we dont want to warn for implementations, see #605
impl Foo for LinkedList<u8> {
fn foo(_: LinkedList<u8>) {}
const BAR : Option<LinkedList<u8>> = None;
const BAR: Option<LinkedList<u8>> = None;
}
struct Bar;
@ -49,7 +44,7 @@ pub fn test_local_not_linted() {
let _: LinkedList<u8>;
}
fn main(){
fn main() {
test(LinkedList::new());
test_local_not_linted();
}

View File

@ -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;

View File

@ -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;

View File

@ -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<u8>
z: Vec<u8>,
}
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;

View File

@ -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)]

View File

@ -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)]

View File

@ -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;

View File

@ -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");
}
}

View File

@ -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() {}

View File

@ -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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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<K: Ord, V>(m: &mut BTreeMap<K, V>, 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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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() {}

View File

@ -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::*;

View File

@ -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,
}

View File

@ -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() {}

View File

@ -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() {

View File

@ -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<Z>) {
let boxed_local = boxed_trait;
@ -85,11 +83,9 @@ fn nowarn_pass() {
take_box(&bx); // fn needs &Box
}
fn take_box(x: &Box<A>) {}
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<I: Foo> {
_peeked: I::Item,
}
pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {
}
pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
/// Regression for #916, #1123
///

View File

@ -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<Target = [i32]>> { Box::new(v) });
}
fn meta<F>(f: F) where F: Fn(u8) {
fn meta<F>(f: F)
where
F: Fn(u8),
{
f(1u8)
}
fn foo(_: u8) {
}
fn foo(_: u8) {}
fn foo2(_: u8) -> u8 {
1u8
}
fn all<X, F>(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!()

View File

@ -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
},
);
}

View File

@ -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)]

View File

@ -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)

View File

@ -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

View File

@ -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()
}

Some files were not shown because too many files have changed in this diff Show More