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

@ -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 @@ impl<'a> Test12 for Test11<'a> {
}
}
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 @@ use std::ptr;
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 @@ use std::hash::{Hash, Hasher};
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 @@ impl Hash for Bah {
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 @@ use alloc::collections::linked_list::LinkedList;
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::mem::{drop, forget};
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 @@ use std::hash::Hash;
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 @@ impl Z for A {
}
}
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()
}

View file

@ -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 @@ impl From<String> for Foo {
}
}
struct Valid(Vec<u8>);
impl<'a> From<&'a str> for Valid {
@ -34,7 +30,6 @@ impl From<usize> for Valid {
}
}
struct Invalid;
impl From<usize> for Invalid {

View file

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

View file

@ -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<T>(x : T) -> T where T : Add<T, Output = T>, T : Copy {
fn twice<T>(x: T) -> T
where
T: Add<T, Output = T>,
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();

View file

@ -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 ONE: f32 = 1.0;
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() {

View file

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

View file

@ -25,10 +25,22 @@ impl Unrelated {
}
}
#[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;

View file

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

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

View file

@ -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<String, String> = HashMap::default();

View file

@ -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<u8, char> = 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();
}

View file

@ -29,4 +29,3 @@ fn main() {
let a = Foo::A;
test_hash!(&a, A => 0, B => 1, C => 2);
}

View file

@ -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<T: Copy>(val: T) -> T {

View file

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

View file

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

View file

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

View file

@ -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<T>: Sized {
fn make() -> (Self, Self);
@ -49,7 +48,6 @@ impl<S: BuildHasher + Default> Foo<i64> for HashMap<String, String, S> {
}
}
impl<T: Hash + Eq> Foo<i8> for HashSet<T> {
fn make() -> (Self, Self) {
(HashSet::new(), HashSet::with_capacity(10))
@ -72,8 +70,7 @@ impl<S: BuildHasher + Default> Foo<i64> for HashSet<String, S> {
}
}
pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
}
pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
macro_rules! gen {
(impl) => {
@ -85,19 +82,19 @@ macro_rules! gen {
};
(fn $name:ident) => {
pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
}
}
pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
};
}
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<K, V> for HashMap<K, V> where V: test_macro::A);
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::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;
}

View file

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

View file

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

View file

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

View file

@ -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::<Vec<_>>(); // 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::<u32>(); // infinite iter
(0_usize..).flat_map(|x| 0..x).product::<usize>(); // infinite iter
(0_usize..).flat_map(|x| 0..x).product::<usize>(); // 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

View file

@ -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<bool>) { unimplemented!() }
fn maybe_i_mutate(i: &Cell<bool>) {
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");
}

View file

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

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, clippy::unnecessary_operation)]
#[warn(clippy::int_plus_one)]
fn main() {

View file

@ -5,21 +5,21 @@ struct X;
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()

View file

@ -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 @@ extern crate core;
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: ?Sized>(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: ?Sized>(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: ?Sized>(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: ?Sized>(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: ?Sized>(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: ?Sized>(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
}

View file

@ -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>() -> T { unimplemented!() }
fn mk_value<T>() -> 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);

View file

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

View file

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

View file

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

View file

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

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(unused_variables)]
#![warn(clippy::large_enum_variant)]

View file

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

View file

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

View file

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

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