struct T;
impl T {
- fn add(self, other: T) -> T { self } //~ERROR defining a method called `add`
- fn drop(&mut self) { } //~ERROR defining a method called `drop`
+ fn add(self, other: T) -> T { self }
+ fn drop(&mut self) { }
fn sub(&self, other: T) -> &T { self } // no error, self is a ref
fn div(self) -> T { self } // no error, different #arguments
fn rem(self, other: T) { } // no error, wrong return type
fn into_u32(self) -> u32 { 0 } // fine
- fn into_u16(&self) -> u16 { 0 } //~ERROR methods called `into_*` usually take self by value
+ fn into_u16(&self) -> u16 { 0 }
- fn to_something(self) -> u32 { 0 } //~ERROR methods called `to_*` usually take self by reference
+ fn to_something(self) -> u32 { 0 }
fn new(self) {}
- //~^ ERROR methods called `new` usually take no self
- //~| ERROR methods called `new` usually return `Self`
}
struct Lt<'a> {
// Check OPTION_MAP_UNWRAP_OR
// single line case
- let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)`
- //~| NOTE replace `map(|x| x + 1).unwrap_or(0)`
+ let _ = opt.map(|x| x + 1)
+
.unwrap_or(0); // should lint even though this call is on a separate line
// multi line cases
- let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or(a)`
+ let _ = opt.map(|x| {
x + 1
}
).unwrap_or(0);
- let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)`
+ let _ = opt.map(|x| x + 1)
.unwrap_or({
0
});
// Check OPTION_MAP_UNWRAP_OR_ELSE
// single line case
- let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)`
- //~| NOTE replace `map(|x| x + 1).unwrap_or_else(|| 0)`
+ let _ = opt.map(|x| x + 1)
+
.unwrap_or_else(|| 0); // should lint even though this call is on a separate line
// multi line cases
- let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or_else(g)`
+ let _ = opt.map(|x| {
x + 1
}
).unwrap_or_else(|| 0);
- let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)`
+ let _ = opt.map(|x| x + 1)
.unwrap_or_else(||
0
);
// check single-line case
let _ = v.iter().filter(|&x| *x < 0).next();
- //~^ ERROR called `filter(p).next()` on an `Iterator`.
- //~| NOTE replace `filter(|&x| *x < 0).next()`
+
+
// check multi-line case
- let _ = v.iter().filter(|&x| { //~ERROR called `filter(p).next()` on an `Iterator`.
+ let _ = v.iter().filter(|&x| {
*x < 0
}
).next();
// check `find().is_some()`, single-line
let _ = v.iter().find(|&x| *x < 0).is_some();
- //~^ ERROR called `is_some()` after searching
- //~| NOTE replace `find(|&x| *x < 0).is_some()`
+
+
// check `find().is_some()`, multi-line
- let _ = v.iter().find(|&x| { //~ERROR called `is_some()` after searching
+ let _ = v.iter().find(|&x| {
*x < 0
}
).is_some();
// check `position().is_some()`, single-line
let _ = v.iter().position(|&x| x < 0).is_some();
- //~^ ERROR called `is_some()` after searching
- //~| NOTE replace `position(|&x| x < 0).is_some()`
+
+
// check `position().is_some()`, multi-line
- let _ = v.iter().position(|&x| { //~ERROR called `is_some()` after searching
+ let _ = v.iter().position(|&x| {
x < 0
}
).is_some();
// check `rposition().is_some()`, single-line
let _ = v.iter().rposition(|&x| x < 0).is_some();
- //~^ ERROR called `is_some()` after searching
- //~| NOTE replace `rposition(|&x| x < 0).is_some()`
+
+
// check `rposition().is_some()`, multi-line
- let _ = v.iter().rposition(|&x| { //~ERROR called `is_some()` after searching
+ let _ = v.iter().rposition(|&x| {
x < 0
}
).is_some();
let with_constructor = Some(vec![1]);
with_constructor.unwrap_or(make());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_constructor.unwrap_or_else(make)
+
+
+
let with_new = Some(vec![1]);
with_new.unwrap_or(Vec::new());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_new.unwrap_or_default();
+
+
+
let with_const_args = Some(vec![1]);
with_const_args.unwrap_or(Vec::with_capacity(12));
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_const_args.unwrap_or_else(|| Vec::with_capacity(12));
+
+
+
let with_err : Result<_, ()> = Ok(vec![1]);
with_err.unwrap_or(make());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_err.unwrap_or_else(|_| make());
+
+
+
let with_err_args : Result<_, ()> = Ok(vec![1]);
with_err_args.unwrap_or(Vec::with_capacity(12));
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_err_args.unwrap_or_else(|_| Vec::with_capacity(12));
+
+
+
let with_default_trait = Some(1);
with_default_trait.unwrap_or(Default::default());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_default_trait.unwrap_or_default();
+
+
+
let with_default_type = Some(1);
with_default_type.unwrap_or(u64::default());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_default_type.unwrap_or_default();
+
+
+
let with_vec = Some(vec![1]);
with_vec.unwrap_or(vec![]);
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
+
+
// FIXME #944: ~|SUGGESTION with_vec.unwrap_or_else(|| vec![]);
let without_default = Some(Foo);
without_default.unwrap_or(Foo::new());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION without_default.unwrap_or_else(Foo::new);
+
+
+
let mut map = HashMap::<u64, String>::new();
map.entry(42).or_insert(String::new());
- //~^ERROR use of `or_insert` followed by a function call
- //~|HELP try this
- //~|SUGGESTION map.entry(42).or_insert_with(String::new);
+
+
+
let mut btree = BTreeMap::<u64, String>::new();
btree.entry(42).or_insert(String::new());
- //~^ERROR use of `or_insert` followed by a function call
- //~|HELP try this
- //~|SUGGESTION btree.entry(42).or_insert_with(String::new);
+
+
+
let stringy = Some(String::from(""));
let _ = stringy.unwrap_or("".to_owned());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION stringy.unwrap_or_else(|| "".to_owned());
+
+
+
}
/// Checks implementation of `ITER_NTH` lint
{
// Make sure we lint `.iter()` for relevant types
let bad_vec = some_vec.iter().nth(3);
- //~^ERROR called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable
+
let bad_slice = &some_vec[..].iter().nth(3);
- //~^ERROR called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
+
let bad_boxed_slice = boxed_slice.iter().nth(3);
- //~^ERROR called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
+
let bad_vec_deque = some_vec_deque.iter().nth(3);
- //~^ERROR called `.iter().nth()` on a VecDeque. Calling `.get()` is both faster and more readable
+
}
{
// Make sure we lint `.iter_mut()` for relevant types
let bad_vec = some_vec.iter_mut().nth(3);
- //~^ERROR called `.iter_mut().nth()` on a Vec. Calling `.get_mut()` is both faster and more readable
+
}
{
let bad_slice = &some_vec[..].iter_mut().nth(3);
- //~^ERROR called `.iter_mut().nth()` on a slice. Calling `.get_mut()` is both faster and more readable
+
}
{
let bad_vec_deque = some_vec_deque.iter_mut().nth(3);
- //~^ERROR called `.iter_mut().nth()` on a VecDeque. Calling `.get_mut()` is both faster and more readable
+
}
// Make sure we don't lint for non-relevant types
let mut some_vec = vec![0, 1, 2, 3];
let _ = some_vec.iter().skip(42).next();
- //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
+
let _ = some_vec.iter().cycle().skip(42).next();
- //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
+
let _ = (1..10).skip(10).next();
- //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
+
let _ = &some_vec[..].iter().skip(3).next();
- //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
+
let foo = IteratorFalsePositives { foo : 0 };
let _ = foo.skip(42).next();
{ // Test `get().unwrap()`
let _ = boxed_slice.get(1).unwrap();
- //~^ERROR called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION boxed_slice[1]
+
+
+
let _ = some_slice.get(0).unwrap();
- //~^ERROR called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION some_slice[0]
+
+
+
let _ = some_vec.get(0).unwrap();
- //~^ERROR called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION some_vec[0]
+
+
+
let _ = some_vecdeque.get(0).unwrap();
- //~^ERROR called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION some_vecdeque[0]
+
+
+
let _ = some_hashmap.get(&1).unwrap();
- //~^ERROR called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION some_hashmap[&1]
+
+
+
let _ = some_btreemap.get(&1).unwrap();
- //~^ERROR called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION some_btreemap[&1]
+
+
+
let _ = false_positive.get(0).unwrap();
}
{ // Test `get_mut().unwrap()`
*boxed_slice.get_mut(0).unwrap() = 1;
- //~^ERROR called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION &mut boxed_slice[0]
+
+
+
*some_slice.get_mut(0).unwrap() = 1;
- //~^ERROR called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION &mut some_slice[0]
+
+
+
*some_vec.get_mut(0).unwrap() = 1;
- //~^ERROR called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION &mut some_vec[0]
+
+
+
*some_vecdeque.get_mut(0).unwrap() = 1;
- //~^ERROR called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION &mut some_vecdeque[0]
+
+
+
// Check false positives
*some_hashmap.get_mut(&1).unwrap() = 'b';
use std::io;
let opt = Some(0);
- let _ = opt.unwrap(); //~ERROR used unwrap() on an Option
+ let _ = opt.unwrap();
let res: Result<i32, ()> = Ok(0);
- let _ = res.unwrap(); //~ERROR used unwrap() on a Result
+ let _ = res.unwrap();
- res.ok().expect("disaster!"); //~ERROR called `ok().expect()`
+ res.ok().expect("disaster!");
// the following should not warn, since `expect` isn't implemented unless
// the error type implements `Debug`
let res2: Result<i32, MyError> = Ok(0);
res2.ok().expect("oh noes!");
let res3: Result<u32, MyErrorWithParam<u8>>= Ok(0);
- res3.ok().expect("whoof"); //~ERROR called `ok().expect()`
+ res3.ok().expect("whoof");
let res4: Result<u32, io::Error> = Ok(0);
- res4.ok().expect("argh"); //~ERROR called `ok().expect()`
+ res4.ok().expect("argh");
let res5: io::Result<u32> = Ok(0);
- res5.ok().expect("oops"); //~ERROR called `ok().expect()`
+ res5.ok().expect("oops");
let res6: Result<u32, &str> = Ok(0);
- res6.ok().expect("meh"); //~ERROR called `ok().expect()`
+ res6.ok().expect("meh");
}
struct MyError(()); // doesn't implement Debug
#[allow(unnecessary_operation)]
fn starts_with() {
"".chars().next() == Some(' ');
- //~^ ERROR starts_with
- //~| HELP like this
- //~| SUGGESTION "".starts_with(' ')
+
+
+
Some(' ') != "".chars().next();
- //~^ ERROR starts_with
- //~| HELP like this
- //~| SUGGESTION !"".starts_with(' ')
+
+
+
}
fn str_extend_chars() {
s.push_str(abc);
s.extend(abc.chars());
- //~^ERROR calling `.extend(_.chars())`
- //~|HELP try this
- //~|SUGGESTION s.push_str(abc)
+
+
+
s.push_str("abc");
s.extend("abc".chars());
- //~^ERROR calling `.extend(_.chars())`
- //~|HELP try this
- //~|SUGGESTION s.push_str("abc")
+
+
+
s.push_str(&def);
s.extend(def.chars());
- //~^ERROR calling `.extend(_.chars())`
- //~|HELP try this
- //~|SUGGESTION s.push_str(&def)
+
+
+
s.extend(abc.chars().skip(1));
s.extend("abc".chars().skip(1));
}
fn clone_on_copy() {
- 42.clone(); //~ERROR using `clone` on a `Copy` type
- //~| HELP try removing the `clone` call
- //~| SUGGESTION 42
+ 42.clone();
+
+
vec![1].clone(); // ok, not a Copy type
Some(vec![1]).clone(); // ok, not a Copy type
- (&42).clone(); //~ERROR using `clone` on a `Copy` type
- //~| HELP try dereferencing it
- //~| SUGGESTION *(&42)
+ (&42).clone();
+
+
}
fn clone_on_copy_generic<T: Copy>(t: T) {
- t.clone(); //~ERROR using `clone` on a `Copy` type
- //~| HELP try removing the `clone` call
- //~| SUGGESTION t
- Some(t).clone(); //~ERROR using `clone` on a `Copy` type
- //~| HELP try removing the `clone` call
- //~| SUGGESTION Some(t)
+ t.clone();
+
+
+ Some(t).clone();
+
+
}
fn clone_on_double_ref() {
let x = vec![1];
let y = &&x;
- let z: &Vec<_> = y.clone(); //~ERROR using `clone` on a double
- //~| HELP try dereferencing it
- //~| SUGGESTION let z: &Vec<_> = (*y).clone();
+ let z: &Vec<_> = y.clone();
+
+
println!("{:p} {:p}",*y, z);
}
fn single_char_pattern() {
let x = "foo";
x.split("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.split('x');
+
+
+
x.split("xx");
x.split("❤️");
x.contains("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.contains('x');
+
+
+
x.starts_with("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.starts_with('x');
+
+
+
x.ends_with("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.ends_with('x');
+
+
+
x.find("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.find('x');
+
+
+
x.rfind("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rfind('x');
+
+
+
x.rsplit("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rsplit('x');
+
+
+
x.split_terminator("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.split_terminator('x');
+
+
+
x.rsplit_terminator("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rsplit_terminator('x');
+
+
+
x.splitn(0, "x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.splitn(0, 'x');
+
+
+
x.rsplitn(0, "x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rsplitn(0, 'x');
+
+
+
x.matches("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.matches('x');
+
+
+
x.rmatches("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rmatches('x');
+
+
+
x.match_indices("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.match_indices('x');
+
+
+
x.rmatch_indices("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rmatch_indices('x');
+
+
+
x.trim_left_matches("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.trim_left_matches('x');
+
+
+
x.trim_right_matches("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.trim_right_matches('x');
+
+
+
let h = HashSet::<String>::new();
h.contains("X"); // should not warn
use std::ffi::CString;
CString::new("foo").unwrap().as_ptr();
- //~^ ERROR you are getting the inner pointer of a temporary `CString`
- //~| NOTE that pointer will be invalid outside this expression
- //~| HELP assign the `CString` to a variable to extend its lifetime
+
+
+
}
#![feature(plugin)]
#![plugin(clippy)]
#![deny(clippy,similar_names)]
-//~^ NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
+
+
+
+
+
+
+
+
+
+
+
#![allow(unused)]
let specter: i32;
let spectre: i32;
- let apple: i32; //~ NOTE: existing binding defined here
- //~^ NOTE: existing binding defined here
- let bpple: i32; //~ ERROR: name is too similar
- //~| HELP: separate the discriminating character by an underscore like: `b_pple`
- let cpple: i32; //~ ERROR: name is too similar
- //~| HELP: separate the discriminating character by an underscore like: `c_pple`
+ let apple: i32;
+
+ let bpple: i32;
+
+ let cpple: i32;
+
let a_bar: i32;
let b_bar: i32;
let blubrhs: i32;
let blublhs: i32;
- let blubx: i32; //~ NOTE: existing binding defined here
- let bluby: i32; //~ ERROR: name is too similar
- //~| HELP: separate the discriminating character by an underscore like: `blub_y`
+ let blubx: i32;
+ let bluby: i32;
+
- let cake: i32; //~ NOTE: existing binding defined here
+ let cake: i32;
let cakes: i32;
- let coke: i32; //~ ERROR: name is too similar
+ let coke: i32;
match 5 {
cheese @ 1 => {},
let ipv6: i32;
let abcd1: i32;
let abdc2: i32;
- let xyz1abc: i32; //~ NOTE: existing binding defined here
+ let xyz1abc: i32;
let xyz2abc: i32;
- let xyzeabc: i32; //~ ERROR: name is too similar
+ let xyzeabc: i32;
- let parser: i32; //~ NOTE: existing binding defined here
+ let parser: i32;
let parsed: i32;
- let parsee: i32; //~ ERROR: name is too similar
- //~| HELP: separate the discriminating character by an underscore like: `parse_e`
+ let parsee: i32;
+
let setter: i32;
let getter: i32;
fn foo() {
let Foo { apple, bpple } = unimplemented!();
- let Foo { apple: spring, //~NOTE existing binding defined here
- bpple: sprang } = unimplemented!(); //~ ERROR: name is too similar
+ let Foo { apple: spring,
+ bpple: sprang } = unimplemented!();
}
#[derive(Clone, Debug)]
let blar: i32;
}
{
- let e: i32; //~ ERROR: 5th binding whose name is just one char
- //~^ NOTE implied by
+ let e: i32;
+
}
{
- let e: i32; //~ ERROR: 5th binding whose name is just one char
- //~^ NOTE implied by
- let f: i32; //~ ERROR: 6th binding whose name is just one char
- //~^ NOTE implied by
+ let e: i32;
+
+ let f: i32;
+
}
match 5 {
1 => println!(""),
- e => panic!(), //~ ERROR: 5th binding whose name is just one char
- //~^ NOTE implied by
+ e => panic!(),
+
}
match 5 {
1 => println!(""),
let mut x = "".to_owned();
for _ in 1..3 {
- x = x + "."; //~ERROR you added something to a string.
+ x = x + ".";
}
let y = "".to_owned();
- let z = y + "..."; //~ERROR you added something to a string.
+ let z = y + "...";
assert_eq!(&x, &z);
}
let mut x = "".to_owned();
for _ in 1..3 {
- x = x + "."; //~ERROR you assigned the result of adding something to this string.
+ x = x + ".";
}
let y = "".to_owned();
let mut x = "".to_owned();
for _ in 1..3 {
- x = x + "."; //~ERROR you assigned the result of adding something to this string.
+ x = x + ".";
}
let y = "".to_owned();
- let z = y + "..."; //~ERROR you added something to a string.
+ let z = y + "...";
assert_eq!(&x, &z);
}
#[deny(string_lit_as_bytes)]
fn str_lit_as_bytes() {
let bs = "hello there".as_bytes();
- //~^ERROR calling `as_bytes()`
- //~|HELP byte string literal
- //~|SUGGESTION b"hello there"
+
+
+
// no warning, because this cannot be written as a byte string literal:
let ubs = "☃".as_bytes();
// the add is only caught for `String`
let mut x = 1;
; x = x + 1;
- //~^ WARN manual implementation of an assign operation
- //~| HELP replace
- //~| SUGGESTION ; x += 1;
+
+
+
assert_eq!(2, x);
}
fn array() {
let mut foo = [1, 2];
- let temp = foo[0]; //~ NOTE implied by
+ let temp = foo[0];
foo[0] = foo[1];
foo[1] = temp;
- //~^^^ ERROR this looks like you are swapping elements of `foo` manually
- //~| HELP try
- //~| SUGGESTION foo.swap(0, 1);
+
+
+
foo.swap(0, 1);
}
fn slice() {
let foo = &mut [1, 2];
- let temp = foo[0]; //~ NOTE implied by
+ let temp = foo[0];
foo[0] = foo[1];
foo[1] = temp;
- //~^^^ ERROR this looks like you are swapping elements of `foo` manually
- //~| HELP try
- //~| SUGGESTION foo.swap(0, 1);
+
+
+
foo.swap(0, 1);
}
fn vec() {
let mut foo = vec![1, 2];
- let temp = foo[0]; //~ NOTE implied by
+ let temp = foo[0];
foo[0] = foo[1];
foo[1] = temp;
- //~^^^ ERROR this looks like you are swapping elements of `foo` manually
- //~| HELP try
- //~| SUGGESTION foo.swap(0, 1);
+
+
+
foo.swap(0, 1);
}
let mut a = 42;
let mut b = 1337;
- a = b; //~ NOTE implied by
+ a = b;
b = a;
- //~^^ ERROR this looks like you are trying to swap `a` and `b`
- //~| HELP try
- //~| SUGGESTION std::mem::swap(&mut a, &mut b);
- //~| NOTE or maybe you should use `std::mem::replace`?
- ; let t = a; //~ NOTE implied by
+
+
+
+
+ ; let t = a;
a = b;
b = t;
- //~^^^ ERROR this looks like you are swapping `a` and `b` manually
- //~| HELP try
- //~| SUGGESTION ; std::mem::swap(&mut a, &mut b);
- //~| NOTE or maybe you should use `std::mem::replace`?
+
+
+
+
let mut c = Foo(42);
- c.0 = a; //~ NOTE implied by
+ c.0 = a;
a = c.0;
- //~^^ ERROR this looks like you are trying to swap `c.0` and `a`
- //~| HELP try
- //~| SUGGESTION std::mem::swap(&mut c.0, &mut a);
- //~| NOTE or maybe you should use `std::mem::replace`?
- ; let t = c.0; //~ NOTE implied by
+
+
+
+
+ ; let t = c.0;
c.0 = a;
a = t;
- //~^^^ ERROR this looks like you are swapping `c.0` and `a` manually
- //~| HELP try
- //~| SUGGESTION ; std::mem::swap(&mut c.0, &mut a);
- //~| NOTE or maybe you should use `std::mem::replace`?
+
+
+
+
}
#![plugin(clippy)]
#[warn(str_to_string)]
-//~^WARNING: lint str_to_string has been removed: using `str::to_string`
+
#[warn(string_to_string)]
-//~^WARNING: lint string_to_string has been removed: using `string::to_string`
+
#[warn(unstable_as_slice)]
-//~^WARNING: lint unstable_as_slice has been removed: `Vec::as_slice` has been stabilized
+
#[warn(unstable_as_mut_slice)]
-//~^WARNING: lint unstable_as_mut_slice has been removed: `Vec::as_mut_slice` has been stabilized
+
fn main() {}
let u: u32 = 42;
u <= 0;
- //~^ ERROR this comparison involving the minimum or maximum element for this type contains a
- //~| HELP using u == 0 instead
+
+
u <= Z;
- //~^ ERROR this comparison involving
- //~| HELP using u == Z instead
+
+
u < Z;
- //~^ ERROR this comparison involving
- //~| HELP comparison is always false
+
+
Z >= u;
- //~^ ERROR this comparison involving
- //~| HELP using Z == u instead
+
+
Z > u;
- //~^ ERROR this comparison involving
- //~| HELP comparison is always false
+
+
u > std::u32::MAX;
- //~^ ERROR this comparison involving
- //~| HELP comparison is always false
+
+
u >= std::u32::MAX;
- //~^ ERROR this comparison involving
- //~| HELP using u == std::u32::MAX instead
+
+
std::u32::MAX < u;
- //~^ ERROR this comparison involving
- //~| HELP comparison is always false
+
+
std::u32::MAX <= u;
- //~^ ERROR this comparison involving
- //~| HELP using std::u32::MAX == u instead
+
+
1-1 > u;
- //~^ ERROR this comparison involving
- //~| HELP because 1-1 is the minimum value for this type, this comparison is always false
+
+
u >= !0;
- //~^ ERROR this comparison involving
- //~| HELP consider using u == !0 instead
+
+
u <= 12 - 2*6;
- //~^ ERROR this comparison involving
- //~| HELP consider using u == 12 - 2*6 instead
+
+
let i: i8 = 0;
i < -127 - 1;
- //~^ ERROR this comparison involving
- //~| HELP comparison is always false
+
+
std::i8::MAX >= i;
- //~^ ERROR this comparison involving
- //~| HELP comparison is always true
+
+
3-7 < std::i32::MIN;
- //~^ ERROR this comparison involving
- //~| HELP comparison is always false
+
+
let b = false;
b >= true;
- //~^ ERROR this comparison involving
- //~| HELP using b == true instead
+
+
false > b;
- //~^ ERROR this comparison involving
- //~| HELP comparison is always false
+
+
u > 0; // ok
// this is handled by unit_cmp
- () < {}; //~WARNING <-comparison of unit values detected.
+ () < {};
}
use std::cmp::{Ordering, PartialEq, PartialOrd};
warning: <-comparison of unit values detected. This will always be false
--> $DIR/absurd-extreme-comparisons.rs:72:5
|
-72 | () < {}; //~WARNING <-comparison of unit values detected.
+72 | () < {};
| ^^^^^^^
|
= note: #[warn(unit_cmp)] on by default
#[deny(approx_constant)]
#[allow(unused, shadow_unrelated, similar_names)]
fn main() {
- let my_e = 2.7182; //~ERROR approximate value of `f{32, 64}::consts::E` found
- let almost_e = 2.718; //~ERROR approximate value of `f{32, 64}::consts::E` found
+ let my_e = 2.7182;
+ let almost_e = 2.718;
let no_e = 2.71;
- let my_1_frac_pi = 0.3183; //~ERROR approximate value of `f{32, 64}::consts::FRAC_1_PI` found
+ let my_1_frac_pi = 0.3183;
let no_1_frac_pi = 0.31;
- let my_frac_1_sqrt_2 = 0.70710678; //~ERROR approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found
- let almost_frac_1_sqrt_2 = 0.70711; //~ERROR approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found
+ let my_frac_1_sqrt_2 = 0.70710678;
+ let almost_frac_1_sqrt_2 = 0.70711;
let my_frac_1_sqrt_2 = 0.707;
- let my_frac_2_pi = 0.63661977; //~ERROR approximate value of `f{32, 64}::consts::FRAC_2_PI` found
+ let my_frac_2_pi = 0.63661977;
let no_frac_2_pi = 0.636;
- let my_frac_2_sq_pi = 1.128379; //~ERROR approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found
+ let my_frac_2_sq_pi = 1.128379;
let no_frac_2_sq_pi = 1.128;
- let my_frac_pi_2 = 1.57079632679; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_2` found
+ let my_frac_pi_2 = 1.57079632679;
let no_frac_pi_2 = 1.5705;
- let my_frac_pi_3 = 1.04719755119; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_3` found
+ let my_frac_pi_3 = 1.04719755119;
let no_frac_pi_3 = 1.047;
- let my_frac_pi_4 = 0.785398163397; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_4` found
+ let my_frac_pi_4 = 0.785398163397;
let no_frac_pi_4 = 0.785;
- let my_frac_pi_6 = 0.523598775598; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_6` found
+ let my_frac_pi_6 = 0.523598775598;
let no_frac_pi_6 = 0.523;
- let my_frac_pi_8 = 0.3926990816987; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_8` found
+ let my_frac_pi_8 = 0.3926990816987;
let no_frac_pi_8 = 0.392;
- let my_ln_10 = 2.302585092994046; //~ERROR approximate value of `f{32, 64}::consts::LN_10` found
+ let my_ln_10 = 2.302585092994046;
let no_ln_10 = 2.303;
- let my_ln_2 = 0.6931471805599453; //~ERROR approximate value of `f{32, 64}::consts::LN_2` found
+ let my_ln_2 = 0.6931471805599453;
let no_ln_2 = 0.693;
- let my_log10_e = 0.43429448190325182; //~ERROR approximate value of `f{32, 64}::consts::LOG10_E` found
+ let my_log10_e = 0.43429448190325182;
let no_log10_e = 0.434;
- let my_log2_e = 1.4426950408889634; //~ERROR approximate value of `f{32, 64}::consts::LOG2_E` found
+ let my_log2_e = 1.4426950408889634;
let no_log2_e = 1.442;
- let my_pi = 3.1415; //~ERROR approximate value of `f{32, 64}::consts::PI` found
- let almost_pi = 3.14; //~ERROR approximate value of `f{32, 64}::consts::PI` found
+ let my_pi = 3.1415;
+ let almost_pi = 3.14;
let no_pi = 3.15;
- let my_sq2 = 1.4142; //~ERROR approximate value of `f{32, 64}::consts::SQRT_2` found
+ let my_sq2 = 1.4142;
let no_sq2 = 1.414;
}
error: approximate value of `f{32, 64}::consts::E` found. Consider using it directly
--> $DIR/approx_const.rs:7:16
|
-7 | let my_e = 2.7182; //~ERROR approximate value of `f{32, 64}::consts::E` found
+7 | let my_e = 2.7182;
| ^^^^^^
|
note: lint level defined here
error: approximate value of `f{32, 64}::consts::E` found. Consider using it directly
--> $DIR/approx_const.rs:8:20
|
-8 | let almost_e = 2.718; //~ERROR approximate value of `f{32, 64}::consts::E` found
+8 | let almost_e = 2.718;
| ^^^^^
error: approximate value of `f{32, 64}::consts::FRAC_1_PI` found. Consider using it directly
--> $DIR/approx_const.rs:11:24
|
-11 | let my_1_frac_pi = 0.3183; //~ERROR approximate value of `f{32, 64}::consts::FRAC_1_PI` found
+11 | let my_1_frac_pi = 0.3183;
| ^^^^^^
error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found. Consider using it directly
--> $DIR/approx_const.rs:14:28
|
-14 | let my_frac_1_sqrt_2 = 0.70710678; //~ERROR approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found
+14 | let my_frac_1_sqrt_2 = 0.70710678;
| ^^^^^^^^^^
error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found. Consider using it directly
--> $DIR/approx_const.rs:15:32
|
-15 | let almost_frac_1_sqrt_2 = 0.70711; //~ERROR approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found
+15 | let almost_frac_1_sqrt_2 = 0.70711;
| ^^^^^^^
error: approximate value of `f{32, 64}::consts::FRAC_2_PI` found. Consider using it directly
--> $DIR/approx_const.rs:18:24
|
-18 | let my_frac_2_pi = 0.63661977; //~ERROR approximate value of `f{32, 64}::consts::FRAC_2_PI` found
+18 | let my_frac_2_pi = 0.63661977;
| ^^^^^^^^^^
error: approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found. Consider using it directly
--> $DIR/approx_const.rs:21:27
|
-21 | let my_frac_2_sq_pi = 1.128379; //~ERROR approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found
+21 | let my_frac_2_sq_pi = 1.128379;
| ^^^^^^^^
error: approximate value of `f{32, 64}::consts::FRAC_PI_2` found. Consider using it directly
--> $DIR/approx_const.rs:24:24
|
-24 | let my_frac_pi_2 = 1.57079632679; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_2` found
+24 | let my_frac_pi_2 = 1.57079632679;
| ^^^^^^^^^^^^^
error: approximate value of `f{32, 64}::consts::FRAC_PI_3` found. Consider using it directly
--> $DIR/approx_const.rs:27:24
|
-27 | let my_frac_pi_3 = 1.04719755119; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_3` found
+27 | let my_frac_pi_3 = 1.04719755119;
| ^^^^^^^^^^^^^
error: approximate value of `f{32, 64}::consts::FRAC_PI_4` found. Consider using it directly
--> $DIR/approx_const.rs:30:24
|
-30 | let my_frac_pi_4 = 0.785398163397; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_4` found
+30 | let my_frac_pi_4 = 0.785398163397;
| ^^^^^^^^^^^^^^
error: approximate value of `f{32, 64}::consts::FRAC_PI_6` found. Consider using it directly
--> $DIR/approx_const.rs:33:24
|
-33 | let my_frac_pi_6 = 0.523598775598; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_6` found
+33 | let my_frac_pi_6 = 0.523598775598;
| ^^^^^^^^^^^^^^
error: approximate value of `f{32, 64}::consts::FRAC_PI_8` found. Consider using it directly
--> $DIR/approx_const.rs:36:24
|
-36 | let my_frac_pi_8 = 0.3926990816987; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_8` found
+36 | let my_frac_pi_8 = 0.3926990816987;
| ^^^^^^^^^^^^^^^
error: approximate value of `f{32, 64}::consts::LN_10` found. Consider using it directly
--> $DIR/approx_const.rs:39:20
|
-39 | let my_ln_10 = 2.302585092994046; //~ERROR approximate value of `f{32, 64}::consts::LN_10` found
+39 | let my_ln_10 = 2.302585092994046;
| ^^^^^^^^^^^^^^^^^
error: approximate value of `f{32, 64}::consts::LN_2` found. Consider using it directly
--> $DIR/approx_const.rs:42:19
|
-42 | let my_ln_2 = 0.6931471805599453; //~ERROR approximate value of `f{32, 64}::consts::LN_2` found
+42 | let my_ln_2 = 0.6931471805599453;
| ^^^^^^^^^^^^^^^^^^
error: approximate value of `f{32, 64}::consts::LOG10_E` found. Consider using it directly
--> $DIR/approx_const.rs:45:22
|
-45 | let my_log10_e = 0.43429448190325182; //~ERROR approximate value of `f{32, 64}::consts::LOG10_E` found
+45 | let my_log10_e = 0.43429448190325182;
| ^^^^^^^^^^^^^^^^^^^
error: approximate value of `f{32, 64}::consts::LOG2_E` found. Consider using it directly
--> $DIR/approx_const.rs:48:21
|
-48 | let my_log2_e = 1.4426950408889634; //~ERROR approximate value of `f{32, 64}::consts::LOG2_E` found
+48 | let my_log2_e = 1.4426950408889634;
| ^^^^^^^^^^^^^^^^^^
error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly
--> $DIR/approx_const.rs:51:17
|
-51 | let my_pi = 3.1415; //~ERROR approximate value of `f{32, 64}::consts::PI` found
+51 | let my_pi = 3.1415;
| ^^^^^^
error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly
--> $DIR/approx_const.rs:52:21
|
-52 | let almost_pi = 3.14; //~ERROR approximate value of `f{32, 64}::consts::PI` found
+52 | let almost_pi = 3.14;
| ^^^^
error: approximate value of `f{32, 64}::consts::SQRT_2` found. Consider using it directly
--> $DIR/approx_const.rs:55:18
|
-55 | let my_sq2 = 1.4142; //~ERROR approximate value of `f{32, 64}::consts::SQRT_2` found
+55 | let my_sq2 = 1.4142;
| ^^^^^^
error: aborting due to 19 previous errors
#![allow(unused, shadow_reuse, shadow_unrelated, no_effect, unnecessary_operation)]
fn main() {
let i = 1i32;
- 1 + i; //~ERROR integer arithmetic detected
- i * 2; //~ERROR integer arithmetic detected
- 1 % //~ERROR integer arithmetic detected
+ 1 + i;
+ i * 2;
+ 1 %
i / 2; // no error, this is part of the expression in the preceding line
- i - 2 + 2 - i; //~ERROR integer arithmetic detected
- -i; //~ERROR integer arithmetic detected
+ i - 2 + 2 - i;
+ -i;
i & 1; // no wrapping
i | 1;
let f = 1.0f32;
- f * 2.0; //~ERROR floating-point arithmetic detected
+ f * 2.0;
- 1.0 + f; //~ERROR floating-point arithmetic detected
- f * 2.0; //~ERROR floating-point arithmetic detected
- f / 2.0; //~ERROR floating-point arithmetic detected
- f - 2.0 * 4.2; //~ERROR floating-point arithmetic detected
- -f; //~ERROR floating-point arithmetic detected
+ 1.0 + f;
+ f * 2.0;
+ f / 2.0;
+ f - 2.0 * 4.2;
+ -f;
}
error: integer arithmetic detected
--> $DIR/arithmetic.rs:8:5
|
-8 | 1 + i; //~ERROR integer arithmetic detected
+8 | 1 + i;
| ^^^^^
|
note: lint level defined here
error: integer arithmetic detected
--> $DIR/arithmetic.rs:9:5
|
-9 | i * 2; //~ERROR integer arithmetic detected
+9 | i * 2;
| ^^^^^
error: integer arithmetic detected
--> $DIR/arithmetic.rs:10:5
|
-10 | 1 % //~ERROR integer arithmetic detected
+10 | 1 %
| _____^ starting here...
11 | | i / 2; // no error, this is part of the expression in the preceding line
| |_________^ ...ending here
error: integer arithmetic detected
--> $DIR/arithmetic.rs:12:5
|
-12 | i - 2 + 2 - i; //~ERROR integer arithmetic detected
+12 | i - 2 + 2 - i;
| ^^^^^^^^^^^^^
error: integer arithmetic detected
--> $DIR/arithmetic.rs:13:5
|
-13 | -i; //~ERROR integer arithmetic detected
+13 | -i;
| ^^
error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:23:5
|
-23 | f * 2.0; //~ERROR floating-point arithmetic detected
+23 | f * 2.0;
| ^^^^^^^
|
note: lint level defined here
error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:25:5
|
-25 | 1.0 + f; //~ERROR floating-point arithmetic detected
+25 | 1.0 + f;
| ^^^^^^^
error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:26:5
|
-26 | f * 2.0; //~ERROR floating-point arithmetic detected
+26 | f * 2.0;
| ^^^^^^^
error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:27:5
|
-27 | f / 2.0; //~ERROR floating-point arithmetic detected
+27 | f / 2.0;
| ^^^^^^^
error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:28:5
|
-28 | f - 2.0 * 4.2; //~ERROR floating-point arithmetic detected
+28 | f - 2.0 * 4.2;
| ^^^^^^^^^^^^^
error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:29:5
|
-29 | -f; //~ERROR floating-point arithmetic detected
+29 | -f;
| ^^
error: aborting due to 11 previous errors
let x = [1,2,3,4];
x[0];
x[3];
- x[4]; //~ERROR: const index is out of bounds
- x[1 << 3]; //~ERROR: const index is out of bounds
- &x[1..5]; //~ERROR: range is out of bounds
+ x[4];
+ x[1 << 3];
+ &x[1..5];
&x[0..3];
- &x[0...4]; //~ERROR: range is out of bounds
- &x[...4]; //~ERROR: range is out of bounds
+ &x[0...4];
+ &x[...4];
&x[..];
&x[1..];
&x[4..];
- &x[5..]; //~ERROR: range is out of bounds
+ &x[5..];
&x[..4];
- &x[..5]; //~ERROR: range is out of bounds
+ &x[..5];
let y = &x;
- y[0]; //~ERROR: indexing may panic
- &y[1..2]; //~ERROR: slicing may panic
+ y[0];
+ &y[1..2];
&y[..];
- &y[0...4]; //~ERROR: slicing may panic
- &y[...4]; //~ERROR: slicing may panic
+ &y[0...4];
+ &y[...4];
let empty: [i8; 0] = [];
- empty[0]; //~ERROR: const index is out of bounds
- &empty[1..5]; //~ERROR: range is out of bounds
- &empty[0...4]; //~ERROR: range is out of bounds
- &empty[...4]; //~ERROR: range is out of bounds
+ empty[0];
+ &empty[1..5];
+ &empty[0...4];
+ &empty[...4];
&empty[..];
&empty[0..];
&empty[0..0];
- &empty[0...0]; //~ERROR: range is out of bounds
- &empty[...0]; //~ERROR: range is out of bounds
+ &empty[0...0];
+ &empty[...0];
&empty[..0];
- &empty[1..]; //~ERROR: range is out of bounds
- &empty[..4]; //~ERROR: range is out of bounds
+ &empty[1..];
+ &empty[..4];
}
error: const index is out of bounds
--> $DIR/array_indexing.rs:12:5
|
-12 | x[4]; //~ERROR: const index is out of bounds
+12 | x[4];
| ^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: const index is out of bounds
--> $DIR/array_indexing.rs:13:5
|
-13 | x[1 << 3]; //~ERROR: const index is out of bounds
+13 | x[1 << 3];
| ^^^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:14:6
|
-14 | &x[1..5]; //~ERROR: range is out of bounds
+14 | &x[1..5];
| ^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:16:6
|
-16 | &x[0...4]; //~ERROR: range is out of bounds
+16 | &x[0...4];
| ^^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:17:6
|
-17 | &x[...4]; //~ERROR: range is out of bounds
+17 | &x[...4];
| ^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:21:6
|
-21 | &x[5..]; //~ERROR: range is out of bounds
+21 | &x[5..];
| ^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:23:6
|
-23 | &x[..5]; //~ERROR: range is out of bounds
+23 | &x[..5];
| ^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: indexing may panic
--> $DIR/array_indexing.rs:26:5
|
-26 | y[0]; //~ERROR: indexing may panic
+26 | y[0];
| ^^^^
|
note: lint level defined here
error: slicing may panic
--> $DIR/array_indexing.rs:27:6
|
-27 | &y[1..2]; //~ERROR: slicing may panic
+27 | &y[1..2];
| ^^^^^^^
error: slicing may panic
--> $DIR/array_indexing.rs:29:6
|
-29 | &y[0...4]; //~ERROR: slicing may panic
+29 | &y[0...4];
| ^^^^^^^^
error: slicing may panic
--> $DIR/array_indexing.rs:30:6
|
-30 | &y[...4]; //~ERROR: slicing may panic
+30 | &y[...4];
| ^^^^^^^
error: const index is out of bounds
--> $DIR/array_indexing.rs:33:5
|
-33 | empty[0]; //~ERROR: const index is out of bounds
+33 | empty[0];
| ^^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:34:6
|
-34 | &empty[1..5]; //~ERROR: range is out of bounds
+34 | &empty[1..5];
| ^^^^^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:35:6
|
-35 | &empty[0...4]; //~ERROR: range is out of bounds
+35 | &empty[0...4];
| ^^^^^^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:36:6
|
-36 | &empty[...4]; //~ERROR: range is out of bounds
+36 | &empty[...4];
| ^^^^^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:40:6
|
-40 | &empty[0...0]; //~ERROR: range is out of bounds
+40 | &empty[0...0];
| ^^^^^^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:41:6
|
-41 | &empty[...0]; //~ERROR: range is out of bounds
+41 | &empty[...0];
| ^^^^^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:43:6
|
-43 | &empty[1..]; //~ERROR: range is out of bounds
+43 | &empty[1..];
| ^^^^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
error: range is out of bounds
--> $DIR/array_indexing.rs:44:6
|
-44 | &empty[..4]; //~ERROR: range is out of bounds
+44 | &empty[..4];
| ^^^^^^^^^^
|
= note: #[deny(out_of_bounds_indexing)] on by default
#[allow(unused_assignments)]
fn main() {
let mut i = 1i32;
- i += 2; //~ ERROR assign operation detected
- //~^ HELP replace it with
- //~| SUGGESTION i = i + 2
- i += 2 + 17; //~ ERROR assign operation detected
- //~^ HELP replace it with
- //~| SUGGESTION i = i + 2 + 17
- i -= 6; //~ ERROR assign operation detected
- //~^ HELP replace it with
- //~| SUGGESTION i = i - 6
+ i += 2;
+
+
+ i += 2 + 17;
+
+
+ i -= 6;
+
+
i -= 2 - 1;
- //~^ ERROR assign operation detected
- //~| HELP replace it with
- //~| SUGGESTION i = i - (2 - 1)
- i *= 5; //~ ERROR assign operation detected
- //~^ HELP replace it with
- //~| SUGGESTION i = i * 5
- i *= 1+5; //~ ERROR assign operation detected
- //~^ HELP replace it with
- //~| SUGGESTION i = i * (1+5)
- i /= 32; //~ ERROR assign operation detected
- //~^ HELP replace it with
- //~| SUGGESTION i = i / 32
- i /= 32 | 5; //~ ERROR assign operation detected
- //~^ HELP replace it with
- //~| SUGGESTION i = i / (32 | 5)
- i /= 32 / 5; //~ ERROR assign operation detected
- //~^ HELP replace it with
- //~| SUGGESTION i = i / (32 / 5)
- i %= 42; //~ ERROR assign operation detected
- //~^ HELP replace it with
- //~| SUGGESTION i = i % 42
- i >>= i; //~ ERROR assign operation detected
- //~^ HELP replace it with
- //~| SUGGESTION i = i >> i
- i <<= 9 + 6 - 7; //~ ERROR assign operation detected
- //~^ HELP replace it with
- //~| SUGGESTION i = i << (9 + 6 - 7)
+
+
+
+ i *= 5;
+
+
+ i *= 1+5;
+
+
+ i /= 32;
+
+
+ i /= 32 | 5;
+
+
+ i /= 32 / 5;
+
+
+ i %= 42;
+
+
+ i >>= i;
+
+
+ i <<= 9 + 6 - 7;
+
+
i += 1 << 5;
- //~^ ERROR assign operation detected
- //~| HELP replace it with
- //~| SUGGESTION i = i + (1 << 5)
+
+
+
}
#[allow(dead_code, unused_assignments)]
#[deny(assign_op_pattern)]
fn bla() {
let mut a = 5;
- a = a + 1; //~ ERROR manual implementation of an assign operation
- //~^ HELP replace it with
- //~| SUGGESTION a += 1
- a = 1 + a; //~ ERROR manual implementation of an assign operation
- //~^ HELP replace it with
- //~| SUGGESTION a += 1
- a = a - 1; //~ ERROR manual implementation of an assign operation
- //~^ HELP replace it with
- //~| SUGGESTION a -= 1
- a = a * 99; //~ ERROR manual implementation of an assign operation
- //~^ HELP replace it with
- //~| SUGGESTION a *= 99
- a = 42 * a; //~ ERROR manual implementation of an assign operation
- //~^ HELP replace it with
- //~| SUGGESTION a *= 42
- a = a / 2; //~ ERROR manual implementation of an assign operation
- //~^ HELP replace it with
- //~| SUGGESTION a /= 2
- a = a % 5; //~ ERROR manual implementation of an assign operation
- //~^ HELP replace it with
- //~| SUGGESTION a %= 5
- a = a & 1; //~ ERROR manual implementation of an assign operation
- //~^ HELP replace it with
- //~| SUGGESTION a &= 1
+ a = a + 1;
+
+
+ a = 1 + a;
+
+
+ a = a - 1;
+
+
+ a = a * 99;
+
+
+ a = 42 * a;
+
+
+ a = a / 2;
+
+
+ a = a % 5;
+
+
+ a = a & 1;
+
+
a = 1 - a;
a = 5 / a;
a = 42 % a;
error: assign operation detected
--> $DIR/assign_ops.rs:8:5
|
-8 | i += 2; //~ ERROR assign operation detected
+8 | i += 2;
| ^^^^^^
|
note: lint level defined here
4 | #[deny(assign_ops)]
| ^^^^^^^^^^
help: replace it with
- | i = i + 2; //~ ERROR assign operation detected
+ | i = i + 2;
error: assign operation detected
--> $DIR/assign_ops.rs:11:5
|
-11 | i += 2 + 17; //~ ERROR assign operation detected
+11 | i += 2 + 17;
| ^^^^^^^^^^^
|
help: replace it with
- | i = i + 2 + 17; //~ ERROR assign operation detected
+ | i = i + 2 + 17;
error: assign operation detected
--> $DIR/assign_ops.rs:14:5
|
-14 | i -= 6; //~ ERROR assign operation detected
+14 | i -= 6;
| ^^^^^^
|
help: replace it with
- | i = i - 6; //~ ERROR assign operation detected
+ | i = i - 6;
error: assign operation detected
--> $DIR/assign_ops.rs:17:5
error: assign operation detected
--> $DIR/assign_ops.rs:21:5
|
-21 | i *= 5; //~ ERROR assign operation detected
+21 | i *= 5;
| ^^^^^^
|
help: replace it with
- | i = i * 5; //~ ERROR assign operation detected
+ | i = i * 5;
error: assign operation detected
--> $DIR/assign_ops.rs:24:5
|
-24 | i *= 1+5; //~ ERROR assign operation detected
+24 | i *= 1+5;
| ^^^^^^^^
|
help: replace it with
- | i = i * (1+5); //~ ERROR assign operation detected
+ | i = i * (1+5);
error: assign operation detected
--> $DIR/assign_ops.rs:27:5
|
-27 | i /= 32; //~ ERROR assign operation detected
+27 | i /= 32;
| ^^^^^^^
|
help: replace it with
- | i = i / 32; //~ ERROR assign operation detected
+ | i = i / 32;
error: assign operation detected
--> $DIR/assign_ops.rs:30:5
|
-30 | i /= 32 | 5; //~ ERROR assign operation detected
+30 | i /= 32 | 5;
| ^^^^^^^^^^^
|
help: replace it with
- | i = i / (32 | 5); //~ ERROR assign operation detected
+ | i = i / (32 | 5);
error: assign operation detected
--> $DIR/assign_ops.rs:33:5
|
-33 | i /= 32 / 5; //~ ERROR assign operation detected
+33 | i /= 32 / 5;
| ^^^^^^^^^^^
|
help: replace it with
- | i = i / (32 / 5); //~ ERROR assign operation detected
+ | i = i / (32 / 5);
error: assign operation detected
--> $DIR/assign_ops.rs:36:5
|
-36 | i %= 42; //~ ERROR assign operation detected
+36 | i %= 42;
| ^^^^^^^
|
help: replace it with
- | i = i % 42; //~ ERROR assign operation detected
+ | i = i % 42;
error: assign operation detected
--> $DIR/assign_ops.rs:39:5
|
-39 | i >>= i; //~ ERROR assign operation detected
+39 | i >>= i;
| ^^^^^^^
|
help: replace it with
- | i = i >> i; //~ ERROR assign operation detected
+ | i = i >> i;
error: assign operation detected
--> $DIR/assign_ops.rs:42:5
|
-42 | i <<= 9 + 6 - 7; //~ ERROR assign operation detected
+42 | i <<= 9 + 6 - 7;
| ^^^^^^^^^^^^^^^
|
help: replace it with
- | i = i << (9 + 6 - 7); //~ ERROR assign operation detected
+ | i = i << (9 + 6 - 7);
error: assign operation detected
--> $DIR/assign_ops.rs:45:5
error: manual implementation of an assign operation
--> $DIR/assign_ops.rs:55:5
|
-55 | a = a + 1; //~ ERROR manual implementation of an assign operation
+55 | a = a + 1;
| ^^^^^^^^^
|
note: lint level defined here
52 | #[deny(assign_op_pattern)]
| ^^^^^^^^^^^^^^^^^
help: replace it with
- | a += 1; //~ ERROR manual implementation of an assign operation
+ | a += 1;
error: manual implementation of an assign operation
--> $DIR/assign_ops.rs:58:5
|
-58 | a = 1 + a; //~ ERROR manual implementation of an assign operation
+58 | a = 1 + a;
| ^^^^^^^^^
|
help: replace it with
- | a += 1; //~ ERROR manual implementation of an assign operation
+ | a += 1;
error: manual implementation of an assign operation
--> $DIR/assign_ops.rs:61:5
|
-61 | a = a - 1; //~ ERROR manual implementation of an assign operation
+61 | a = a - 1;
| ^^^^^^^^^
|
help: replace it with
- | a -= 1; //~ ERROR manual implementation of an assign operation
+ | a -= 1;
error: manual implementation of an assign operation
--> $DIR/assign_ops.rs:64:5
|
-64 | a = a * 99; //~ ERROR manual implementation of an assign operation
+64 | a = a * 99;
| ^^^^^^^^^^
|
help: replace it with
- | a *= 99; //~ ERROR manual implementation of an assign operation
+ | a *= 99;
error: manual implementation of an assign operation
--> $DIR/assign_ops.rs:67:5
|
-67 | a = 42 * a; //~ ERROR manual implementation of an assign operation
+67 | a = 42 * a;
| ^^^^^^^^^^
|
help: replace it with
- | a *= 42; //~ ERROR manual implementation of an assign operation
+ | a *= 42;
error: manual implementation of an assign operation
--> $DIR/assign_ops.rs:70:5
|
-70 | a = a / 2; //~ ERROR manual implementation of an assign operation
+70 | a = a / 2;
| ^^^^^^^^^
|
help: replace it with
- | a /= 2; //~ ERROR manual implementation of an assign operation
+ | a /= 2;
error: manual implementation of an assign operation
--> $DIR/assign_ops.rs:73:5
|
-73 | a = a % 5; //~ ERROR manual implementation of an assign operation
+73 | a = a % 5;
| ^^^^^^^^^
|
help: replace it with
- | a %= 5; //~ ERROR manual implementation of an assign operation
+ | a %= 5;
error: manual implementation of an assign operation
--> $DIR/assign_ops.rs:76:5
|
-76 | a = a & 1; //~ ERROR manual implementation of an assign operation
+76 | a = a & 1;
| ^^^^^^^^^
|
help: replace it with
- | a &= 1; //~ ERROR manual implementation of an assign operation
+ | a &= 1;
error: aborting due to 21 previous errors
#[deny(misrefactored_assign_op)]
fn main() {
let mut a = 5;
- a += a + 1; //~ ERROR variable appears on both sides of an assignment operation
- //~^ HELP replace it with
- //~| SUGGESTION a += 1
- a += 1 + a; //~ ERROR variable appears on both sides of an assignment operation
- //~^ HELP replace it with
- //~| SUGGESTION a += 1
- a -= a - 1; //~ ERROR variable appears on both sides of an assignment operation
- //~^ HELP replace it with
- //~| SUGGESTION a -= 1
- a *= a * 99; //~ ERROR variable appears on both sides of an assignment operation
- //~^ HELP replace it with
- //~| SUGGESTION a *= 99
- a *= 42 * a; //~ ERROR variable appears on both sides of an assignment operation
- //~^ HELP replace it with
- //~| SUGGESTION a *= 42
- a /= a / 2; //~ ERROR variable appears on both sides of an assignment operation
- //~^ HELP replace it with
- //~| SUGGESTION a /= 2
- a %= a % 5; //~ ERROR variable appears on both sides of an assignment operation
- //~^ HELP replace it with
- //~| SUGGESTION a %= 5
- a &= a & 1; //~ ERROR variable appears on both sides of an assignment operation
- //~^ HELP replace it with
- //~| SUGGESTION a &= 1
+ a += a + 1;
+
+
+ a += 1 + a;
+
+
+ a -= a - 1;
+
+
+ a *= a * 99;
+
+
+ a *= 42 * a;
+
+
+ a /= a / 2;
+
+
+ a %= a % 5;
+
+
+ a &= a & 1;
+
+
a -= 1 - a;
a /= 5 / a;
a %= 42 % a;
error: variable appears on both sides of an assignment operation
--> $DIR/assign_ops2.rs:8:5
|
-8 | a += a + 1; //~ ERROR variable appears on both sides of an assignment operation
+8 | a += a + 1;
| ^^^^^^^^^^
|
note: lint level defined here
5 | #[deny(misrefactored_assign_op)]
| ^^^^^^^^^^^^^^^^^^^^^^^
help: replace it with
- | a += 1; //~ ERROR variable appears on both sides of an assignment operation
+ | a += 1;
error: variable appears on both sides of an assignment operation
--> $DIR/assign_ops2.rs:11:5
|
-11 | a += 1 + a; //~ ERROR variable appears on both sides of an assignment operation
+11 | a += 1 + a;
| ^^^^^^^^^^
|
help: replace it with
- | a += 1; //~ ERROR variable appears on both sides of an assignment operation
+ | a += 1;
error: variable appears on both sides of an assignment operation
--> $DIR/assign_ops2.rs:14:5
|
-14 | a -= a - 1; //~ ERROR variable appears on both sides of an assignment operation
+14 | a -= a - 1;
| ^^^^^^^^^^
|
help: replace it with
- | a -= 1; //~ ERROR variable appears on both sides of an assignment operation
+ | a -= 1;
error: variable appears on both sides of an assignment operation
--> $DIR/assign_ops2.rs:17:5
|
-17 | a *= a * 99; //~ ERROR variable appears on both sides of an assignment operation
+17 | a *= a * 99;
| ^^^^^^^^^^^
|
help: replace it with
- | a *= 99; //~ ERROR variable appears on both sides of an assignment operation
+ | a *= 99;
error: variable appears on both sides of an assignment operation
--> $DIR/assign_ops2.rs:20:5
|
-20 | a *= 42 * a; //~ ERROR variable appears on both sides of an assignment operation
+20 | a *= 42 * a;
| ^^^^^^^^^^^
|
help: replace it with
- | a *= 42; //~ ERROR variable appears on both sides of an assignment operation
+ | a *= 42;
error: variable appears on both sides of an assignment operation
--> $DIR/assign_ops2.rs:23:5
|
-23 | a /= a / 2; //~ ERROR variable appears on both sides of an assignment operation
+23 | a /= a / 2;
| ^^^^^^^^^^
|
help: replace it with
- | a /= 2; //~ ERROR variable appears on both sides of an assignment operation
+ | a /= 2;
error: variable appears on both sides of an assignment operation
--> $DIR/assign_ops2.rs:26:5
|
-26 | a %= a % 5; //~ ERROR variable appears on both sides of an assignment operation
+26 | a %= a % 5;
| ^^^^^^^^^^
|
help: replace it with
- | a %= 5; //~ ERROR variable appears on both sides of an assignment operation
+ | a %= 5;
error: variable appears on both sides of an assignment operation
--> $DIR/assign_ops2.rs:29:5
|
-29 | a &= a & 1; //~ ERROR variable appears on both sides of an assignment operation
+29 | a &= a & 1;
| ^^^^^^^^^^
|
help: replace it with
- | a &= 1; //~ ERROR variable appears on both sides of an assignment operation
+ | a &= 1;
error: aborting due to 8 previous errors
#![deny(inline_always, deprecated_semver)]
-#[inline(always)] //~ERROR you have declared `#[inline(always)]` on `test_attr_lint`.
+#[inline(always)]
fn test_attr_lint() {
assert!(true)
}
unreachable!();
}
-#[deprecated(since = "forever")] //~ERROR the since field must contain a semver-compliant version
+#[deprecated(since = "forever")]
pub const SOME_CONST : u8 = 42;
-#[deprecated(since = "1")] //~ERROR the since field must contain a semver-compliant version
+#[deprecated(since = "1")]
pub const ANOTHER_CONST : u8 = 23;
#[deprecated(since = "0.1.1")]
error: you have declared `#[inline(always)]` on `test_attr_lint`. This is usually a bad idea
--> $DIR/attrs.rs:6:1
|
-6 | #[inline(always)] //~ERROR you have declared `#[inline(always)]` on `test_attr_lint`.
+6 | #[inline(always)]
| ^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: the since field must contain a semver-compliant version
--> $DIR/attrs.rs:27:14
|
-27 | #[deprecated(since = "forever")] //~ERROR the since field must contain a semver-compliant version
+27 | #[deprecated(since = "forever")]
| ^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: the since field must contain a semver-compliant version
--> $DIR/attrs.rs:30:14
|
-30 | #[deprecated(since = "1")] //~ERROR the since field must contain a semver-compliant version
+30 | #[deprecated(since = "1")]
| ^^^^^^^^^^^
error: aborting due to 3 previous errors
fn main() {
let x = 5;
- x & 0 == 0; //~ERROR &-masking with zero
+ x & 0 == 0;
x & 1 == 1; //ok, distinguishes bit 0
x & 1 == 0; //ok, compared with zero
- x & 2 == 1; //~ERROR incompatible bit mask
+ x & 2 == 1;
x | 0 == 0; //ok, equals x == 0 (maybe warn?)
x | 1 == 3; //ok, equals x == 2 || x == 3
x | 3 == 3; //ok, equals x <= 3
- x | 3 == 2; //~ERROR incompatible bit mask
+ x | 3 == 2;
- x & 1 > 1; //~ERROR incompatible bit mask
+ x & 1 > 1;
x & 2 > 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0
x & 2 < 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0
x | 1 > 1; // ok (if a bit silly), equals x > 1
- x | 2 > 1; //~ERROR incompatible bit mask
+ x | 2 > 1;
x | 2 <= 2; // ok (if a bit silly), equals x <= 2
x & 192 == 128; // ok, tests for bit 7 and not bit 6
x & 0xffc0 == 0xfe80; // ok
// this also now works with constants
- x & THREE_BITS == 8; //~ERROR incompatible bit mask
- x | EVEN_MORE_REDIRECTION < 7; //~ERROR incompatible bit mask
+ x & THREE_BITS == 8;
+ x | EVEN_MORE_REDIRECTION < 7;
- 0 & x == 0; //~ERROR &-masking with zero
+ 0 & x == 0;
1 | x > 1;
// and should now also match uncommon usage
- 1 < 2 | x; //~ERROR incompatible bit mask
- 2 == 3 | x; //~ERROR incompatible bit mask
- 1 == x & 2; //~ERROR incompatible bit mask
+ 1 < 2 | x;
+ 2 == 3 | x;
+ 1 == x & 2;
x | 1 > 2; // no error, because we allowed ineffective bit masks
ineffective();
fn ineffective() {
let x = 5;
- x | 1 > 3; //~ERROR ineffective bit mask
- x | 1 < 4; //~ERROR ineffective bit mask
- x | 1 <= 3; //~ERROR ineffective bit mask
- x | 1 >= 8; //~ERROR ineffective bit mask
+ x | 1 > 3;
+ x | 1 < 4;
+ x | 1 <= 3;
+ x | 1 >= 8;
x | 1 > 2; // not an error (yet), better written as x >= 2
x | 1 >= 7; // not an error (yet), better written as x >= 6
error: &-masking with zero
--> $DIR/bit_masks.rs:12:5
|
-12 | x & 0 == 0; //~ERROR &-masking with zero
+12 | x & 0 == 0;
| ^^^^^^^^^^
|
note: lint level defined here
error: incompatible bit mask: `_ & 2` can never be equal to `1`
--> $DIR/bit_masks.rs:15:5
|
-15 | x & 2 == 1; //~ERROR incompatible bit mask
+15 | x & 2 == 1;
| ^^^^^^^^^^
error: incompatible bit mask: `_ | 3` can never be equal to `2`
--> $DIR/bit_masks.rs:19:5
|
-19 | x | 3 == 2; //~ERROR incompatible bit mask
+19 | x | 3 == 2;
| ^^^^^^^^^^
error: incompatible bit mask: `_ & 1` will never be higher than `1`
--> $DIR/bit_masks.rs:21:5
|
-21 | x & 1 > 1; //~ERROR incompatible bit mask
+21 | x & 1 > 1;
| ^^^^^^^^^
error: incompatible bit mask: `_ | 2` will always be higher than `1`
--> $DIR/bit_masks.rs:25:5
|
-25 | x | 2 > 1; //~ERROR incompatible bit mask
+25 | x | 2 > 1;
| ^^^^^^^^^
error: incompatible bit mask: `_ & 7` can never be equal to `8`
--> $DIR/bit_masks.rs:32:5
|
-32 | x & THREE_BITS == 8; //~ERROR incompatible bit mask
+32 | x & THREE_BITS == 8;
| ^^^^^^^^^^^^^^^^^^^
error: incompatible bit mask: `_ | 7` will never be lower than `7`
--> $DIR/bit_masks.rs:33:5
|
-33 | x | EVEN_MORE_REDIRECTION < 7; //~ERROR incompatible bit mask
+33 | x | EVEN_MORE_REDIRECTION < 7;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: &-masking with zero
--> $DIR/bit_masks.rs:35:5
|
-35 | 0 & x == 0; //~ERROR &-masking with zero
+35 | 0 & x == 0;
| ^^^^^^^^^^
error: incompatible bit mask: `_ | 2` will always be higher than `1`
--> $DIR/bit_masks.rs:39:5
|
-39 | 1 < 2 | x; //~ERROR incompatible bit mask
+39 | 1 < 2 | x;
| ^^^^^^^^^
error: incompatible bit mask: `_ | 3` can never be equal to `2`
--> $DIR/bit_masks.rs:40:5
|
-40 | 2 == 3 | x; //~ERROR incompatible bit mask
+40 | 2 == 3 | x;
| ^^^^^^^^^^
error: incompatible bit mask: `_ & 2` can never be equal to `1`
--> $DIR/bit_masks.rs:41:5
|
-41 | 1 == x & 2; //~ERROR incompatible bit mask
+41 | 1 == x & 2;
| ^^^^^^^^^^
error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly
--> $DIR/bit_masks.rs:52:5
|
-52 | x | 1 > 3; //~ERROR ineffective bit mask
+52 | x | 1 > 3;
| ^^^^^^^^^
|
note: lint level defined here
error: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared directly
--> $DIR/bit_masks.rs:53:5
|
-53 | x | 1 < 4; //~ERROR ineffective bit mask
+53 | x | 1 < 4;
| ^^^^^^^^^
error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly
--> $DIR/bit_masks.rs:54:5
|
-54 | x | 1 <= 3; //~ERROR ineffective bit mask
+54 | x | 1 <= 3;
| ^^^^^^^^^^
error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared directly
--> $DIR/bit_masks.rs:55:5
|
-55 | x | 1 >= 8; //~ERROR ineffective bit mask
+55 | x | 1 >= 8;
| ^^^^^^^^^^
error: aborting due to 15 previous errors
#![allow(unused_variables, similar_names)]
#![deny(blacklisted_name)]
-fn test(foo: ()) {} //~ERROR use of a blacklisted/placeholder name `foo`
+fn test(foo: ()) {}
fn main() {
- let foo = 42; //~ERROR use of a blacklisted/placeholder name `foo`
- let bar = 42; //~ERROR use of a blacklisted/placeholder name `bar`
- let baz = 42; //~ERROR use of a blacklisted/placeholder name `baz`
+ let foo = 42;
+ let bar = 42;
+ let baz = 42;
let barb = 42;
let barbaric = 42;
match (42, Some(1337), Some(0)) {
(foo, Some(bar), baz @ Some(_)) => (),
- //~^ ERROR use of a blacklisted/placeholder name `foo`
- //~| ERROR use of a blacklisted/placeholder name `bar`
- //~| ERROR use of a blacklisted/placeholder name `baz`
+
+
+
_ => (),
}
}
error: use of a blacklisted/placeholder name `foo`
--> $DIR/blacklisted_name.rs:9:9
|
-9 | fn test(foo: ()) {} //~ERROR use of a blacklisted/placeholder name `foo`
+9 | fn test(foo: ()) {}
| ^^^
|
note: lint level defined here
error: use of a blacklisted/placeholder name `foo`
--> $DIR/blacklisted_name.rs:12:9
|
-12 | let foo = 42; //~ERROR use of a blacklisted/placeholder name `foo`
+12 | let foo = 42;
| ^^^
error: use of a blacklisted/placeholder name `bar`
--> $DIR/blacklisted_name.rs:13:9
|
-13 | let bar = 42; //~ERROR use of a blacklisted/placeholder name `bar`
+13 | let bar = 42;
| ^^^
error: use of a blacklisted/placeholder name `baz`
--> $DIR/blacklisted_name.rs:14:9
|
-14 | let baz = 42; //~ERROR use of a blacklisted/placeholder name `baz`
+14 | let baz = 42;
| ^^^
error: use of a blacklisted/placeholder name `foo`
}
fn condition_has_block() -> i32 {
- if { //~ERROR in an 'if' condition, avoid complex blocks or closures with blocks;
+ if {
let x = 3;
x == 3
} {
}
fn condition_has_block_with_single_expression() -> i32 {
- if { true } { //~ERROR omit braces around single expression condition
+ if { true } {
6
} else {
10
// 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) {
- //~^ERROR in an 'if' condition, avoid complex blocks or closures with blocks;
+
}
if predicate(|x| { let target = 3; x == target }, v) {
- //~^ERROR in an 'if' condition, avoid complex blocks or closures with blocks;
+
}
}
fn condition_is_normal() -> i32 {
let x = 3;
- if true && x == 3 { //~ WARN this boolean expression can be simplified
+ if true && x == 3 {
6
} else {
10
error: in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let'
--> $DIR/block_in_if_condition.rs:30:8
|
-30 | if { //~ERROR in an 'if' condition, avoid complex blocks or closures with blocks;
+30 | if {
| ________^ starting here...
31 | | let x = 3;
32 | | x == 3
5 | #![deny(block_in_if_condition_stmt)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: try
- let res = { //~ERROR in an 'if' condition, avoid complex blocks or closures with blocks;
+ let res = {
let x = 3;
x == 3
};
error: omit braces around single expression condition
--> $DIR/block_in_if_condition.rs:41:8
|
-41 | if { true } { //~ERROR omit braces around single expression condition
+41 | if { true } {
| ^^^^^^^^
|
note: lint level defined here
4 | #![deny(block_in_if_condition_expr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: try
- if true { //~ERROR omit braces around single expression condition
+ if true {
6
} ...
warning: this boolean expression can be simplified
--> $DIR/block_in_if_condition.rs:70:8
|
-70 | if true && x == 3 { //~ WARN this boolean expression can be simplified
+70 | if true && x == 3 {
| ^^^^^^^^^^^^^^
|
note: lint level defined here
7 | #![warn(nonminimal_bool)]
| ^^^^^^^^^^^^^^^
help: try
- | if x == 3 { //~ WARN this boolean expression can be simplified
+ | if x == 3 {
error: aborting due to 4 previous errors
fn main() {
let x = true;
if x == true { "yes" } else { "no" };
- //~^ ERROR equality checks against true are unnecessary
- //~| HELP try simplifying it as shown:
- //~| SUGGESTION if x { "yes" } else { "no" };
+
+
+
if x == false { "yes" } else { "no" };
- //~^ ERROR equality checks against false can be replaced by a negation
- //~| HELP try simplifying it as shown:
- //~| SUGGESTION if !x { "yes" } else { "no" };
+
+
+
if true == x { "yes" } else { "no" };
- //~^ ERROR equality checks against true are unnecessary
- //~| HELP try simplifying it as shown:
- //~| SUGGESTION if x { "yes" } else { "no" };
+
+
+
if false == x { "yes" } else { "no" };
- //~^ ERROR equality checks against false can be replaced by a negation
- //~| HELP try simplifying it as shown:
- //~| SUGGESTION if !x { "yes" } else { "no" };
+
+
+
}
let c: bool = unimplemented!();
let d: bool = unimplemented!();
let e: bool = unimplemented!();
- let _ = a && b || a; //~ ERROR this boolean expression contains a logic bug
- //~| HELP this expression can be optimized out
- //~| HELP it would look like the following
- //~| SUGGESTION let _ = a;
+ let _ = a && b || a;
+
+
+
let _ = !(a && b);
- let _ = !true; //~ ERROR this boolean expression can be simplified
- //~| HELP try
- //~| SUGGESTION let _ = false;
- let _ = !false; //~ ERROR this boolean expression can be simplified
- //~| HELP try
- //~| SUGGESTION let _ = true;
- let _ = !!a; //~ ERROR this boolean expression can be simplified
- //~| HELP try
- //~| SUGGESTION let _ = a;
-
- let _ = false && a; //~ ERROR this boolean expression contains a logic bug
- //~| HELP this expression can be optimized out
- //~| HELP it would look like the following
- //~| SUGGESTION let _ = false;
-
- let _ = false || a; //~ ERROR this boolean expression can be simplified
- //~| HELP try
- //~| SUGGESTION let _ = a;
+ let _ = !true;
+
+
+ let _ = !false;
+
+
+ let _ = !!a;
+
+
+
+ let _ = false && a;
+
+
+
+
+ let _ = false || a;
+
+
// don't lint on cfgs
let _ = cfg!(you_shall_not_not_pass) && a;
let _ = !(a && b || c);
- let _ = !(!a && b); //~ ERROR this boolean expression can be simplified
- //~| HELP try
- //~| SUGGESTION let _ = !b || a;
+ let _ = !(!a && b);
+
+
}
#[allow(unused, many_single_char_names)]
let d: i32 = unimplemented!();
let e: i32 = unimplemented!();
let _ = a == b && a != b;
- //~^ ERROR this boolean expression contains a logic bug
- //~| HELP this expression can be optimized out
- //~| HELP it would look like the following
- //~| SUGGESTION let _ = false;
+
+
+
+
let _ = a == b && c == 5 && a == b;
- //~^ ERROR this boolean expression can be simplified
- //~| HELP try
- //~| SUGGESTION let _ = a == b && c == 5;
- //~| HELP try
- //~| SUGGESTION let _ = !(c != 5 || a != b);
+
+
+
+
+
let _ = a == b && c == 5 && b == a;
- //~^ ERROR this boolean expression can be simplified
- //~| HELP try
- //~| SUGGESTION let _ = a == b && c == 5;
- //~| HELP try
- //~| SUGGESTION let _ = !(c != 5 || a != b);
+
+
+
+
+
let _ = a < b && a >= b;
- //~^ ERROR this boolean expression contains a logic bug
- //~| HELP this expression can be optimized out
- //~| HELP it would look like the following
- //~| SUGGESTION let _ = false;
+
+
+
+
let _ = a > b && a <= b;
- //~^ ERROR this boolean expression contains a logic bug
- //~| HELP this expression can be optimized out
- //~| HELP it would look like the following
- //~| SUGGESTION let _ = false;
+
+
+
+
let _ = a > b && a == b;
let _ = a != b || !(a != b || c == d);
- //~^ ERROR this boolean expression can be simplified
- //~| HELP try
- //~| SUGGESTION let _ = c != d || a != b;
- //~| HELP try
- //~| SUGGESTION let _ = !(a == b && c == d);
+
+
+
+
+
}
error: this boolean expression contains a logic bug
--> $DIR/booleans.rs:12:13
|
-12 | let _ = a && b || a; //~ ERROR this boolean expression contains a logic bug
+12 | let _ = a && b || a;
| ^^^^^^^^^^^
|
note: lint level defined here
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/booleans.rs:12:18
|
-12 | let _ = a && b || a; //~ ERROR this boolean expression contains a logic bug
+12 | let _ = a && b || a;
| ^
help: it would look like the following
- | let _ = a; //~ ERROR this boolean expression contains a logic bug
+ | let _ = a;
error: this boolean expression can be simplified
--> $DIR/booleans.rs:17:13
|
-17 | let _ = !true; //~ ERROR this boolean expression can be simplified
+17 | let _ = !true;
| ^^^^^
|
note: lint level defined here
3 | #![deny(nonminimal_bool, logic_bug)]
| ^^^^^^^^^^^^^^^
help: try
- | let _ = false; //~ ERROR this boolean expression can be simplified
+ | let _ = false;
error: this boolean expression can be simplified
--> $DIR/booleans.rs:20:13
|
-20 | let _ = !false; //~ ERROR this boolean expression can be simplified
+20 | let _ = !false;
| ^^^^^^
|
help: try
- | let _ = true; //~ ERROR this boolean expression can be simplified
+ | let _ = true;
error: this boolean expression can be simplified
--> $DIR/booleans.rs:23:13
|
-23 | let _ = !!a; //~ ERROR this boolean expression can be simplified
+23 | let _ = !!a;
| ^^^
|
help: try
- | let _ = a; //~ ERROR this boolean expression can be simplified
+ | let _ = a;
error: this boolean expression contains a logic bug
--> $DIR/booleans.rs:27:13
|
-27 | let _ = false && a; //~ ERROR this boolean expression contains a logic bug
+27 | let _ = false && a;
| ^^^^^^^^^^
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/booleans.rs:27:22
|
-27 | let _ = false && a; //~ ERROR this boolean expression contains a logic bug
+27 | let _ = false && a;
| ^
help: it would look like the following
- | let _ = false; //~ ERROR this boolean expression contains a logic bug
+ | let _ = false;
error: this boolean expression can be simplified
--> $DIR/booleans.rs:32:13
|
-32 | let _ = false || a; //~ ERROR this boolean expression can be simplified
+32 | let _ = false || a;
| ^^^^^^^^^^
|
help: try
- | let _ = a; //~ ERROR this boolean expression can be simplified
+ | let _ = a;
error: this boolean expression can be simplified
--> $DIR/booleans.rs:43:13
|
-43 | let _ = !(!a && b); //~ ERROR this boolean expression can be simplified
+43 | let _ = !(!a && b);
| ^^^^^^^^^^
|
help: try
- | let _ = !b || a; //~ ERROR this boolean expression can be simplified
+ | let _ = !b || a;
error: this boolean expression contains a logic bug
--> $DIR/booleans.rs:55:13
fn test_macro() {
boxit!(Vec::new(), Vec<u8>);
}
-pub fn test(foo: Box<Vec<bool>>) { //~ ERROR you seem to be trying to use `Box<Vec<T>>`
+pub fn test(foo: Box<Vec<bool>>) {
println!("{:?}", foo.get(0))
}
error: you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`
--> $DIR/box_vec.rs:17:18
|
-17 | pub fn test(foo: Box<Vec<bool>>) { //~ ERROR you seem to be trying to use `Box<Vec<T>>`
+17 | pub fn test(foo: Box<Vec<bool>>) {
| ^^^^^^^^^^^^^^
|
= note: #[deny(box_vec)] implied by #[deny(clippy)]
#![plugin(clippy)]
#![deny(builtin_type_shadow)]
-fn foo<u32>(a: u32) -> u32 { //~ERROR shadows the built-in type `u32`
- 42 //~ERROR E0308
+fn foo<u32>(a: u32) -> u32 {
+ 42
// ^ rustc's type error
}
error: This generic shadows the built-in type `u32`
--> $DIR/builtin-type-shadow.rs:5:8
|
-5 | fn foo<u32>(a: u32) -> u32 { //~ERROR shadows the built-in type `u32`
+5 | fn foo<u32>(a: u32) -> u32 {
| ^^^
|
note: lint level defined here
error[E0308]: mismatched types
--> $DIR/builtin-type-shadow.rs:6:5
|
-6 | 42 //~ERROR E0308
+6 | 42
| ^^ expected type parameter, found integral variable
|
= note: expected type `u32`
#[allow(no_effect, unnecessary_operation)]
fn main() {
// Test cast_precision_loss
- 1i32 as f32; //~ERROR casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
- 1i64 as f32; //~ERROR casting i64 to f32 causes a loss of precision (i64 is 64 bits wide, but f32's mantissa is only 23 bits wide)
- 1i64 as f64; //~ERROR casting i64 to f64 causes a loss of precision (i64 is 64 bits wide, but f64's mantissa is only 52 bits wide)
- 1u32 as f32; //~ERROR casting u32 to f32 causes a loss of precision (u32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
- 1u64 as f32; //~ERROR casting u64 to f32 causes a loss of precision (u64 is 64 bits wide, but f32's mantissa is only 23 bits wide)
- 1u64 as f64; //~ERROR casting u64 to f64 causes a loss of precision (u64 is 64 bits wide, but f64's mantissa is only 52 bits wide)
+ 1i32 as f32;
+ 1i64 as f32;
+ 1i64 as f64;
+ 1u32 as f32;
+ 1u64 as f32;
+ 1u64 as f64;
1i32 as f64; // Should not trigger the lint
1u32 as f64; // Should not trigger the lint
// Test cast_possible_truncation
- 1f32 as i32; //~ERROR casting f32 to i32 may truncate the value
- 1f32 as u32; //~ERROR casting f32 to u32 may truncate the value
- //~^ERROR casting f32 to u32 may lose the sign of the value
- 1f64 as f32; //~ERROR casting f64 to f32 may truncate the value
- 1i32 as i8; //~ERROR casting i32 to i8 may truncate the value
- 1i32 as u8; //~ERROR casting i32 to u8 may truncate the value
- //~^ERROR casting i32 to u8 may lose the sign of the value
- 1f64 as isize; //~ERROR casting f64 to isize may truncate the value
- 1f64 as usize; //~ERROR casting f64 to usize may truncate the value
- //~^ERROR casting f64 to usize may lose the sign of the value
+ 1f32 as i32;
+ 1f32 as u32;
+
+ 1f64 as f32;
+ 1i32 as i8;
+ 1i32 as u8;
+
+ 1f64 as isize;
+ 1f64 as usize;
+
// Test cast_possible_wrap
- 1u8 as i8; //~ERROR casting u8 to i8 may wrap around the value
- 1u16 as i16; //~ERROR casting u16 to i16 may wrap around the value
- 1u32 as i32; //~ERROR casting u32 to i32 may wrap around the value
- 1u64 as i64; //~ERROR casting u64 to i64 may wrap around the value
- 1usize as isize; //~ERROR casting usize to isize may wrap around the value
+ 1u8 as i8;
+ 1u16 as i16;
+ 1u32 as i32;
+ 1u64 as i64;
+ 1usize as isize;
// Test cast_sign_loss
- 1i32 as u32; //~ERROR casting i32 to u32 may lose the sign of the value
- 1isize as usize; //~ERROR casting isize to usize may lose the sign of the value
+ 1i32 as u32;
+ 1isize as usize;
// Extra checks for *size
// Casting from *size
- 1isize as i8; //~ERROR casting isize to i8 may truncate the value
- 1isize as f64; //~ERROR casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide)
- 1usize as f64; //~ERROR casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide)
- 1isize as f32; //~ERROR casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
- 1usize as f32; //~ERROR casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
- 1isize as i32; //~ERROR casting isize to i32 may truncate the value on targets with 64-bit wide pointers
- 1isize as u32; //~ERROR casting isize to u32 may lose the sign of the value
- //~^ERROR casting isize to u32 may truncate the value on targets with 64-bit wide pointers
- 1usize as u32; //~ERROR casting usize to u32 may truncate the value on targets with 64-bit wide pointers
- 1usize as i32; //~ERROR casting usize to i32 may truncate the value on targets with 64-bit wide pointers
- //~^ERROR casting usize to i32 may wrap around the value on targets with 32-bit wide pointers
+ 1isize as i8;
+ 1isize as f64;
+ 1usize as f64;
+ 1isize as f32;
+ 1usize as f32;
+ 1isize as i32;
+ 1isize as u32;
+
+ 1usize as u32;
+ 1usize as i32;
+
// Casting to *size
- 1i64 as isize; //~ERROR casting i64 to isize may truncate the value on targets with 32-bit wide pointers
- 1i64 as usize; //~ERROR casting i64 to usize may truncate the value on targets with 32-bit wide pointers
- //~^ERROR casting i64 to usize may lose the sign of the value
- 1u64 as isize; //~ERROR casting u64 to isize may truncate the value on targets with 32-bit wide pointers
- //~^ERROR casting u64 to isize may wrap around the value on targets with 64-bit wide pointers
- 1u64 as usize; //~ERROR casting u64 to usize may truncate the value on targets with 32-bit wide pointers
- 1u32 as isize; //~ERROR casting u32 to isize may wrap around the value on targets with 32-bit wide pointers
+ 1i64 as isize;
+ 1i64 as usize;
+
+ 1u64 as isize;
+
+ 1u64 as usize;
+ 1u32 as isize;
1u32 as usize; // Should not trigger any lint
1i32 as isize; // Neither should this
- 1i32 as usize; //~ERROR casting i32 to usize may lose the sign of the value
+ 1i32 as usize;
}
error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
--> $DIR/cast.rs:8:5
|
-8 | 1i32 as f32; //~ERROR casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
+8 | 1i32 as f32;
| ^^^^^^^^^^^
|
note: lint level defined here
error: casting i64 to f32 causes a loss of precision (i64 is 64 bits wide, but f32's mantissa is only 23 bits wide)
--> $DIR/cast.rs:9:5
|
-9 | 1i64 as f32; //~ERROR casting i64 to f32 causes a loss of precision (i64 is 64 bits wide, but f32's mantissa is only 23 bits wide)
+9 | 1i64 as f32;
| ^^^^^^^^^^^
error: casting i64 to f64 causes a loss of precision (i64 is 64 bits wide, but f64's mantissa is only 52 bits wide)
--> $DIR/cast.rs:10:5
|
-10 | 1i64 as f64; //~ERROR casting i64 to f64 causes a loss of precision (i64 is 64 bits wide, but f64's mantissa is only 52 bits wide)
+10 | 1i64 as f64;
| ^^^^^^^^^^^
error: casting u32 to f32 causes a loss of precision (u32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
--> $DIR/cast.rs:11:5
|
-11 | 1u32 as f32; //~ERROR casting u32 to f32 causes a loss of precision (u32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
+11 | 1u32 as f32;
| ^^^^^^^^^^^
error: casting u64 to f32 causes a loss of precision (u64 is 64 bits wide, but f32's mantissa is only 23 bits wide)
--> $DIR/cast.rs:12:5
|
-12 | 1u64 as f32; //~ERROR casting u64 to f32 causes a loss of precision (u64 is 64 bits wide, but f32's mantissa is only 23 bits wide)
+12 | 1u64 as f32;
| ^^^^^^^^^^^
error: casting u64 to f64 causes a loss of precision (u64 is 64 bits wide, but f64's mantissa is only 52 bits wide)
--> $DIR/cast.rs:13:5
|
-13 | 1u64 as f64; //~ERROR casting u64 to f64 causes a loss of precision (u64 is 64 bits wide, but f64's mantissa is only 52 bits wide)
+13 | 1u64 as f64;
| ^^^^^^^^^^^
error: casting f32 to i32 may truncate the value
--> $DIR/cast.rs:18:5
|
-18 | 1f32 as i32; //~ERROR casting f32 to i32 may truncate the value
+18 | 1f32 as i32;
| ^^^^^^^^^^^
|
note: lint level defined here
error: casting f32 to u32 may truncate the value
--> $DIR/cast.rs:19:5
|
-19 | 1f32 as u32; //~ERROR casting f32 to u32 may truncate the value
+19 | 1f32 as u32;
| ^^^^^^^^^^^
error: casting f32 to u32 may lose the sign of the value
--> $DIR/cast.rs:19:5
|
-19 | 1f32 as u32; //~ERROR casting f32 to u32 may truncate the value
+19 | 1f32 as u32;
| ^^^^^^^^^^^
|
note: lint level defined here
error: casting f64 to f32 may truncate the value
--> $DIR/cast.rs:21:5
|
-21 | 1f64 as f32; //~ERROR casting f64 to f32 may truncate the value
+21 | 1f64 as f32;
| ^^^^^^^^^^^
error: casting i32 to i8 may truncate the value
--> $DIR/cast.rs:22:5
|
-22 | 1i32 as i8; //~ERROR casting i32 to i8 may truncate the value
+22 | 1i32 as i8;
| ^^^^^^^^^^
error: casting i32 to u8 may lose the sign of the value
--> $DIR/cast.rs:23:5
|
-23 | 1i32 as u8; //~ERROR casting i32 to u8 may truncate the value
+23 | 1i32 as u8;
| ^^^^^^^^^^
error: casting i32 to u8 may truncate the value
--> $DIR/cast.rs:23:5
|
-23 | 1i32 as u8; //~ERROR casting i32 to u8 may truncate the value
+23 | 1i32 as u8;
| ^^^^^^^^^^
error: casting f64 to isize may truncate the value
--> $DIR/cast.rs:25:5
|
-25 | 1f64 as isize; //~ERROR casting f64 to isize may truncate the value
+25 | 1f64 as isize;
| ^^^^^^^^^^^^^
error: casting f64 to usize may truncate the value
--> $DIR/cast.rs:26:5
|
-26 | 1f64 as usize; //~ERROR casting f64 to usize may truncate the value
+26 | 1f64 as usize;
| ^^^^^^^^^^^^^
error: casting f64 to usize may lose the sign of the value
--> $DIR/cast.rs:26:5
|
-26 | 1f64 as usize; //~ERROR casting f64 to usize may truncate the value
+26 | 1f64 as usize;
| ^^^^^^^^^^^^^
error: casting u8 to i8 may wrap around the value
--> $DIR/cast.rs:30:5
|
-30 | 1u8 as i8; //~ERROR casting u8 to i8 may wrap around the value
+30 | 1u8 as i8;
| ^^^^^^^^^
|
note: lint level defined here
error: casting u16 to i16 may wrap around the value
--> $DIR/cast.rs:31:5
|
-31 | 1u16 as i16; //~ERROR casting u16 to i16 may wrap around the value
+31 | 1u16 as i16;
| ^^^^^^^^^^^
error: casting u32 to i32 may wrap around the value
--> $DIR/cast.rs:32:5
|
-32 | 1u32 as i32; //~ERROR casting u32 to i32 may wrap around the value
+32 | 1u32 as i32;
| ^^^^^^^^^^^
error: casting u64 to i64 may wrap around the value
--> $DIR/cast.rs:33:5
|
-33 | 1u64 as i64; //~ERROR casting u64 to i64 may wrap around the value
+33 | 1u64 as i64;
| ^^^^^^^^^^^
error: casting usize to isize may wrap around the value
--> $DIR/cast.rs:34:5
|
-34 | 1usize as isize; //~ERROR casting usize to isize may wrap around the value
+34 | 1usize as isize;
| ^^^^^^^^^^^^^^^
error: casting i32 to u32 may lose the sign of the value
--> $DIR/cast.rs:37:5
|
-37 | 1i32 as u32; //~ERROR casting i32 to u32 may lose the sign of the value
+37 | 1i32 as u32;
| ^^^^^^^^^^^
error: casting isize to usize may lose the sign of the value
--> $DIR/cast.rs:38:5
|
-38 | 1isize as usize; //~ERROR casting isize to usize may lose the sign of the value
+38 | 1isize as usize;
| ^^^^^^^^^^^^^^^
error: casting isize to i8 may truncate the value
--> $DIR/cast.rs:42:5
|
-42 | 1isize as i8; //~ERROR casting isize to i8 may truncate the value
+42 | 1isize as i8;
| ^^^^^^^^^^^^
error: casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide)
--> $DIR/cast.rs:43:5
|
-43 | 1isize as f64; //~ERROR casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide)
+43 | 1isize as f64;
| ^^^^^^^^^^^^^
error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide)
--> $DIR/cast.rs:44:5
|
-44 | 1usize as f64; //~ERROR casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide)
+44 | 1usize as f64;
| ^^^^^^^^^^^^^
error: casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
--> $DIR/cast.rs:45:5
|
-45 | 1isize as f32; //~ERROR casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
+45 | 1isize as f32;
| ^^^^^^^^^^^^^
error: casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
--> $DIR/cast.rs:46:5
|
-46 | 1usize as f32; //~ERROR casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
+46 | 1usize as f32;
| ^^^^^^^^^^^^^
error: casting isize to i32 may truncate the value on targets with 64-bit wide pointers
--> $DIR/cast.rs:47:5
|
-47 | 1isize as i32; //~ERROR casting isize to i32 may truncate the value on targets with 64-bit wide pointers
+47 | 1isize as i32;
| ^^^^^^^^^^^^^
error: casting isize to u32 may lose the sign of the value
--> $DIR/cast.rs:48:5
|
-48 | 1isize as u32; //~ERROR casting isize to u32 may lose the sign of the value
+48 | 1isize as u32;
| ^^^^^^^^^^^^^
error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers
--> $DIR/cast.rs:48:5
|
-48 | 1isize as u32; //~ERROR casting isize to u32 may lose the sign of the value
+48 | 1isize as u32;
| ^^^^^^^^^^^^^
error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
--> $DIR/cast.rs:50:5
|
-50 | 1usize as u32; //~ERROR casting usize to u32 may truncate the value on targets with 64-bit wide pointers
+50 | 1usize as u32;
| ^^^^^^^^^^^^^
error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers
--> $DIR/cast.rs:51:5
|
-51 | 1usize as i32; //~ERROR casting usize to i32 may truncate the value on targets with 64-bit wide pointers
+51 | 1usize as i32;
| ^^^^^^^^^^^^^
error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers
--> $DIR/cast.rs:51:5
|
-51 | 1usize as i32; //~ERROR casting usize to i32 may truncate the value on targets with 64-bit wide pointers
+51 | 1usize as i32;
| ^^^^^^^^^^^^^
error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers
--> $DIR/cast.rs:54:5
|
-54 | 1i64 as isize; //~ERROR casting i64 to isize may truncate the value on targets with 32-bit wide pointers
+54 | 1i64 as isize;
| ^^^^^^^^^^^^^
error: casting i64 to usize may lose the sign of the value
--> $DIR/cast.rs:55:5
|
-55 | 1i64 as usize; //~ERROR casting i64 to usize may truncate the value on targets with 32-bit wide pointers
+55 | 1i64 as usize;
| ^^^^^^^^^^^^^
error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers
--> $DIR/cast.rs:55:5
|
-55 | 1i64 as usize; //~ERROR casting i64 to usize may truncate the value on targets with 32-bit wide pointers
+55 | 1i64 as usize;
| ^^^^^^^^^^^^^
error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers
--> $DIR/cast.rs:57:5
|
-57 | 1u64 as isize; //~ERROR casting u64 to isize may truncate the value on targets with 32-bit wide pointers
+57 | 1u64 as isize;
| ^^^^^^^^^^^^^
error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers
--> $DIR/cast.rs:57:5
|
-57 | 1u64 as isize; //~ERROR casting u64 to isize may truncate the value on targets with 32-bit wide pointers
+57 | 1u64 as isize;
| ^^^^^^^^^^^^^
error: casting u64 to usize may truncate the value on targets with 32-bit wide pointers
--> $DIR/cast.rs:59:5
|
-59 | 1u64 as usize; //~ERROR casting u64 to usize may truncate the value on targets with 32-bit wide pointers
+59 | 1u64 as usize;
| ^^^^^^^^^^^^^
error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers
--> $DIR/cast.rs:60:5
|
-60 | 1u32 as isize; //~ERROR casting u32 to isize may wrap around the value on targets with 32-bit wide pointers
+60 | 1u32 as isize;
| ^^^^^^^^^^^^^
error: casting i32 to usize may lose the sign of the value
--> $DIR/cast.rs:63:5
|
-63 | 1i32 as usize; //~ERROR casting i32 to usize may lose the sign of the value
+63 | 1i32 as usize;
| ^^^^^^^^^^^^^
error: aborting due to 42 previous errors
#![deny(char_lit_as_u8)]
#![allow(unused_variables)]
fn main() {
- let c = 'a' as u8; //~ERROR casting character literal
+ let c = 'a' as u8;
}
error: casting character literal to u8. `char`s are 4 bytes wide in rust, so casting to u8 truncates them
--> $DIR/char_lit_as_u8.rs:7:13
|
-7 | let c = 'a' as u8; //~ERROR casting character literal
+7 | let c = 'a' as u8;
| ^^^^^^^^^
|
note: lint level defined here
#[allow(float_cmp, no_effect, unnecessary_operation)]
fn main() {
let x = 5f32;
- x == std::f32::NAN; //~ERROR doomed comparison with NAN
- x != std::f32::NAN; //~ERROR doomed comparison with NAN
- x < std::f32::NAN; //~ERROR doomed comparison with NAN
- x > std::f32::NAN; //~ERROR doomed comparison with NAN
- x <= std::f32::NAN; //~ERROR doomed comparison with NAN
- x >= std::f32::NAN; //~ERROR doomed comparison with NAN
+ x == std::f32::NAN;
+ x != std::f32::NAN;
+ x < std::f32::NAN;
+ x > std::f32::NAN;
+ x <= std::f32::NAN;
+ x >= std::f32::NAN;
let y = 0f64;
- y == std::f64::NAN; //~ERROR doomed comparison with NAN
- y != std::f64::NAN; //~ERROR doomed comparison with NAN
- y < std::f64::NAN; //~ERROR doomed comparison with NAN
- y > std::f64::NAN; //~ERROR doomed comparison with NAN
- y <= std::f64::NAN; //~ERROR doomed comparison with NAN
- y >= std::f64::NAN; //~ERROR doomed comparison with NAN
+ y == std::f64::NAN;
+ y != std::f64::NAN;
+ y < std::f64::NAN;
+ y > std::f64::NAN;
+ y <= std::f64::NAN;
+ y >= std::f64::NAN;
}
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:8:5
|
-8 | x == std::f32::NAN; //~ERROR doomed comparison with NAN
+8 | x == std::f32::NAN;
| ^^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:9:5
|
-9 | x != std::f32::NAN; //~ERROR doomed comparison with NAN
+9 | x != std::f32::NAN;
| ^^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:10:5
|
-10 | x < std::f32::NAN; //~ERROR doomed comparison with NAN
+10 | x < std::f32::NAN;
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:11:5
|
-11 | x > std::f32::NAN; //~ERROR doomed comparison with NAN
+11 | x > std::f32::NAN;
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:12:5
|
-12 | x <= std::f32::NAN; //~ERROR doomed comparison with NAN
+12 | x <= std::f32::NAN;
| ^^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:13:5
|
-13 | x >= std::f32::NAN; //~ERROR doomed comparison with NAN
+13 | x >= std::f32::NAN;
| ^^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:16:5
|
-16 | y == std::f64::NAN; //~ERROR doomed comparison with NAN
+16 | y == std::f64::NAN;
| ^^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:17:5
|
-17 | y != std::f64::NAN; //~ERROR doomed comparison with NAN
+17 | y != std::f64::NAN;
| ^^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:18:5
|
-18 | y < std::f64::NAN; //~ERROR doomed comparison with NAN
+18 | y < std::f64::NAN;
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:19:5
|
-19 | y > std::f64::NAN; //~ERROR doomed comparison with NAN
+19 | y > std::f64::NAN;
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:20:5
|
-20 | y <= std::f64::NAN; //~ERROR doomed comparison with NAN
+20 | y <= std::f64::NAN;
| ^^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
--> $DIR/cmp_nan.rs:21:5
|
-21 | y >= std::f64::NAN; //~ERROR doomed comparison with NAN
+21 | y >= std::f64::NAN;
| ^^^^^^^^^^^^^^^^^^
|
= note: #[deny(cmp_nan)] on by default
fn main() {
let x = 0;
let p : *const usize = &x;
- if p == ptr::null() { //~ERROR: Comparing with null
+ if p == ptr::null() {
println!("This is surprising!");
}
let mut y = 0;
let mut m : *mut usize = &mut y;
- if m == ptr::null_mut() { //~ERROR: Comparing with null
+ if m == ptr::null_mut() {
println!("This is surprising, too!");
}
}
error: Comparing with null is better expressed by the .is_null() method
--> $DIR/cmp_null.rs:11:8
|
-11 | if p == ptr::null() { //~ERROR: Comparing with null
+11 | if p == ptr::null() {
| ^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: Comparing with null is better expressed by the .is_null() method
--> $DIR/cmp_null.rs:16:8
|
-16 | if m == ptr::null_mut() { //~ERROR: Comparing with null
+16 | if m == ptr::null_mut() {
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
fn main() {
fn with_to_string(x : &str) {
x != "foo".to_string();
- //~^ ERROR this creates an owned instance just for comparison. Consider using `x != "foo"` to compare without allocation
+
"foo".to_string() != x;
- //~^ ERROR this creates an owned instance just for comparison. Consider using `"foo" != x` to compare without allocation
+
}
let x = "oh";
with_to_string(x);
- x != "foo".to_owned(); //~ERROR this creates an owned instance
+ x != "foo".to_owned();
// removed String::from_str(..), as it has finally been removed in 1.4.0
// as of 2015-08-14
- x != String::from("foo"); //~ERROR this creates an owned instance
+ x != String::from("foo");
42.to_string() == "42";
}
error: this creates an owned instance just for comparison. Consider using `x != "foo"` to compare without allocation
--> $DIR/cmp_owned.rs:19:10
|
-19 | x != "foo".to_owned(); //~ERROR this creates an owned instance
+19 | x != "foo".to_owned();
| ^^^^^^^^^^^^^^^^
error: this creates an owned instance just for comparison. Consider using `x != "foo"` to compare without allocation
--> $DIR/cmp_owned.rs:24:10
|
-24 | x != String::from("foo"); //~ERROR this creates an owned instance
+24 | x != String::from("foo");
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors
let x = "hello";
let y = "world";
if x == "hello" {
- //~^ ERROR this if statement can be collapsed
- //~| HELP try
- //~| SUGGESTION if x == "hello" && y == "world" {
+
+
+
if y == "world" {
println!("Hello world!");
}
}
if x == "hello" || x == "world" {
- //~^ ERROR this if statement can be collapsed
- //~| HELP try
- //~| SUGGESTION if (x == "hello" || x == "world") && (y == "world" || y == "hello") {
+
+
+
if y == "world" || y == "hello" {
println!("Hello world!");
}
}
if x == "hello" && x == "world" {
- //~^ ERROR this if statement can be collapsed
- //~| HELP try
- //~| SUGGESTION if x == "hello" && x == "world" && (y == "world" || y == "hello") {
+
+
+
if y == "world" || y == "hello" {
println!("Hello world!");
}
}
if x == "hello" || x == "world" {
- //~^ ERROR this if statement can be collapsed
- //~| HELP try
- //~| SUGGESTION if (x == "hello" || x == "world") && y == "world" && y == "hello" {
+
+
+
if y == "world" && y == "hello" {
println!("Hello world!");
}
}
if x == "hello" && x == "world" {
- //~^ ERROR this if statement can be collapsed
- //~| HELP try
- //~| SUGGESTION if x == "hello" && x == "world" && y == "world" && y == "hello" {
+
+
+
if y == "world" && y == "hello" {
println!("Hello world!");
}
}
if 42 == 1337 {
- //~^ ERROR this if statement can be collapsed
- //~| HELP try
- //~| SUGGESTION if 42 == 1337 && 'a' != 'A' {
+
+
+
if 'a' != 'A' {
println!("world!")
}
if x == "hello" {
print!("Hello ");
} else {
- //~^ ERROR: this `else { if .. }`
- //~| HELP try
- //~| SUGGESTION } else if y == "world"
+
+
+
if y == "world" {
println!("world!")
}
if x == "hello" {
print!("Hello ");
} else {
- //~^ ERROR: this `else { if .. }`
- //~| HELP try
- //~| SUGGESTION } else if let Some(42)
+
+
+
if let Some(42) = Some(42) {
println!("world!")
}
if x == "hello" {
print!("Hello ");
} else {
- //~^ ERROR this `else { if .. }`
- //~| HELP try
- //~| SUGGESTION } else if y == "world"
+
+
+
if y == "world" {
println!("world")
}
if x == "hello" {
print!("Hello ");
} else {
- //~^ ERROR this `else { if .. }`
- //~| HELP try
- //~| SUGGESTION } else if let Some(42)
+
+
+
if let Some(42) = Some(42) {
println!("world")
}
if let Some(42) = Some(42) {
print!("Hello ");
} else {
- //~^ ERROR this `else { if .. }`
- //~| HELP try
- //~| SUGGESTION } else if let Some(42)
+
+
+
if let Some(42) = Some(42) {
println!("world")
}
if let Some(42) = Some(42) {
print!("Hello ");
} else {
- //~^ ERROR this `else { if .. }`
- //~| HELP try
- //~| SUGGESTION } else if x == "hello"
+
+
+
if x == "hello" {
println!("world")
}
if let Some(42) = Some(42) {
print!("Hello ");
} else {
- //~^ ERROR this `else { if .. }`
- //~| HELP try
- //~| SUGGESTION } else if let Some(42)
+
+
+
if let Some(42) = Some(42) {
println!("world")
}
|
8 | if x == "hello" {
| _____^ starting here...
-9 | | //~^ ERROR this if statement can be collapsed
-10 | | //~| HELP try
-11 | | //~| SUGGESTION if x == "hello" && y == "world" {
+9 | |
+10 | |
+11 | |
12 | | if y == "world" {
13 | | println!("Hello world!");
14 | | }
|
17 | if x == "hello" || x == "world" {
| _____^ starting here...
-18 | | //~^ ERROR this if statement can be collapsed
-19 | | //~| HELP try
-20 | | //~| SUGGESTION if (x == "hello" || x == "world") && (y == "world" || y == "hello") {
+18 | |
+19 | |
+20 | |
21 | | if y == "world" || y == "hello" {
22 | | println!("Hello world!");
23 | | }
|
26 | if x == "hello" && x == "world" {
| _____^ starting here...
-27 | | //~^ ERROR this if statement can be collapsed
-28 | | //~| HELP try
-29 | | //~| SUGGESTION if x == "hello" && x == "world" && (y == "world" || y == "hello") {
+27 | |
+28 | |
+29 | |
30 | | if y == "world" || y == "hello" {
31 | | println!("Hello world!");
32 | | }
|
35 | if x == "hello" || x == "world" {
| _____^ starting here...
-36 | | //~^ ERROR this if statement can be collapsed
-37 | | //~| HELP try
-38 | | //~| SUGGESTION if (x == "hello" || x == "world") && y == "world" && y == "hello" {
+36 | |
+37 | |
+38 | |
39 | | if y == "world" && y == "hello" {
40 | | println!("Hello world!");
41 | | }
|
44 | if x == "hello" && x == "world" {
| _____^ starting here...
-45 | | //~^ ERROR this if statement can be collapsed
-46 | | //~| HELP try
-47 | | //~| SUGGESTION if x == "hello" && x == "world" && y == "world" && y == "hello" {
+45 | |
+46 | |
+47 | |
48 | | if y == "world" && y == "hello" {
49 | | println!("Hello world!");
50 | | }
|
53 | if 42 == 1337 {
| _____^ starting here...
-54 | | //~^ ERROR this if statement can be collapsed
-55 | | //~| HELP try
-56 | | //~| SUGGESTION if 42 == 1337 && 'a' != 'A' {
+54 | |
+55 | |
+56 | |
57 | | if 'a' != 'A' {
58 | | println!("world!")
59 | | }
|
65 | } else {
| ____________^ starting here...
-66 | | //~^ ERROR: this `else { if .. }`
-67 | | //~| HELP try
-68 | | //~| SUGGESTION } else if y == "world"
+66 | |
+67 | |
+68 | |
69 | | if y == "world" {
70 | | println!("world!")
71 | | }
|
76 | } else {
| ____________^ starting here...
-77 | | //~^ ERROR: this `else { if .. }`
-78 | | //~| HELP try
-79 | | //~| SUGGESTION } else if let Some(42)
+77 | |
+78 | |
+79 | |
80 | | if let Some(42) = Some(42) {
81 | | println!("world!")
82 | | }
type Alias = Vec<Vec<Box<(u32, u32, u32, u32)>>>; // no warning here
-const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); //~ERROR very complex type
-static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); //~ERROR very complex type
+const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
+static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
struct S {
- f: Vec<Vec<Box<(u32, u32, u32, u32)>>>, //~ERROR very complex type
+ f: Vec<Vec<Box<(u32, u32, u32, u32)>>>,
}
-struct TS(Vec<Vec<Box<(u32, u32, u32, u32)>>>); //~ERROR very complex type
+struct TS(Vec<Vec<Box<(u32, u32, u32, u32)>>>);
enum E {
- Tuple(Vec<Vec<Box<(u32, u32, u32, u32)>>>), //~ERROR very complex type
- Struct { f: Vec<Vec<Box<(u32, u32, u32, u32)>>> }, //~ERROR very complex type
+ Tuple(Vec<Vec<Box<(u32, u32, u32, u32)>>>),
+ Struct { f: Vec<Vec<Box<(u32, u32, u32, u32)>>> },
}
impl S {
- const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); //~ERROR very complex type
- fn impl_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { } //~ERROR very complex type
+ const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
+ fn impl_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { }
}
trait T {
- const A: Vec<Vec<Box<(u32, u32, u32, u32)>>>; //~ERROR very complex type
- type B = Vec<Vec<Box<(u32, u32, u32, u32)>>>; //~ERROR very complex type
- fn method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>); //~ERROR very complex type
- fn def_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { } //~ERROR very complex type
+ 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 test1() -> Vec<Vec<Box<(u32, u32, u32, u32)>>> { vec![] } //~ERROR very complex type
+fn test1() -> Vec<Vec<Box<(u32, u32, u32, u32)>>> { vec![] }
-fn test2(_x: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { } //~ERROR very complex type
+fn test2(_x: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { }
fn test3() {
- let _y: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![]; //~ERROR very complex type
+ let _y: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![];
}
fn main() {
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:9:12
|
-9 | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); //~ERROR very complex type
+9 | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:10:12
|
-10 | static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); //~ERROR very complex type
+10 | static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:13:8
|
-13 | f: Vec<Vec<Box<(u32, u32, u32, u32)>>>, //~ERROR very complex type
+13 | f: Vec<Vec<Box<(u32, u32, u32, u32)>>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:16:11
|
-16 | struct TS(Vec<Vec<Box<(u32, u32, u32, u32)>>>); //~ERROR very complex type
+16 | struct TS(Vec<Vec<Box<(u32, u32, u32, u32)>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:19:11
|
-19 | Tuple(Vec<Vec<Box<(u32, u32, u32, u32)>>>), //~ERROR very complex type
+19 | Tuple(Vec<Vec<Box<(u32, u32, u32, u32)>>>),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:20:17
|
-20 | Struct { f: Vec<Vec<Box<(u32, u32, u32, u32)>>> }, //~ERROR very complex type
+20 | Struct { f: Vec<Vec<Box<(u32, u32, u32, u32)>>> },
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:24:14
|
-24 | const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); //~ERROR very complex type
+24 | const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:25:30
|
-25 | fn impl_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { } //~ERROR very complex type
+25 | fn impl_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:29:14
|
-29 | const A: Vec<Vec<Box<(u32, u32, u32, u32)>>>; //~ERROR very complex type
+29 | const A: Vec<Vec<Box<(u32, u32, u32, u32)>>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:30:14
|
-30 | type B = Vec<Vec<Box<(u32, u32, u32, u32)>>>; //~ERROR very complex type
+30 | type B = Vec<Vec<Box<(u32, u32, u32, u32)>>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:31:25
|
-31 | fn method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>); //~ERROR very complex type
+31 | fn method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:32:29
|
-32 | fn def_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { } //~ERROR very complex type
+32 | fn def_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:35:15
|
-35 | fn test1() -> Vec<Vec<Box<(u32, u32, u32, u32)>>> { vec![] } //~ERROR very complex type
+35 | fn test1() -> Vec<Vec<Box<(u32, u32, u32, u32)>>> { vec![] }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:37:14
|
-37 | fn test2(_x: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { } //~ERROR very complex type
+37 | fn test2(_x: Vec<Vec<Box<(u32, u32, u32, u32)>>>) { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:40:13
|
-40 | let _y: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![]; //~ERROR very complex type
+40 | let _y: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(type_complexity)] implied by #[deny(clippy)]
#![allow(unused_variables)]
#![deny(blacklisted_name)]
-fn test(toto: ()) {} //~ERROR use of a blacklisted/placeholder name `toto`
+fn test(toto: ()) {}
fn main() {
- let toto = 42; //~ERROR use of a blacklisted/placeholder name `toto`
- let tata = 42; //~ERROR use of a blacklisted/placeholder name `tata`
- let titi = 42; //~ERROR use of a blacklisted/placeholder name `titi`
+ let toto = 42;
+ let tata = 42;
+ let titi = 42;
let tatab = 42;
let tatatataic = 42;
match (42, Some(1337), Some(0)) {
(toto, Some(tata), titi @ Some(_)) => (),
- //~^ ERROR use of a blacklisted/placeholder name `toto`
- //~| ERROR use of a blacklisted/placeholder name `tata`
- //~| ERROR use of a blacklisted/placeholder name `titi`
+
+
+
_ => (),
}
}
error: use of a blacklisted/placeholder name `toto`
--> $DIR/conf_french_blacklisted_name.rs:9:9
|
-9 | fn test(toto: ()) {} //~ERROR use of a blacklisted/placeholder name `toto`
+9 | fn test(toto: ()) {}
| ^^^^
|
note: lint level defined here
error: use of a blacklisted/placeholder name `toto`
--> $DIR/conf_french_blacklisted_name.rs:12:9
|
-12 | let toto = 42; //~ERROR use of a blacklisted/placeholder name `toto`
+12 | let toto = 42;
| ^^^^
error: use of a blacklisted/placeholder name `tata`
--> $DIR/conf_french_blacklisted_name.rs:13:9
|
-13 | let tata = 42; //~ERROR use of a blacklisted/placeholder name `tata`
+13 | let tata = 42;
| ^^^^
error: use of a blacklisted/placeholder name `titi`
--> $DIR/conf_french_blacklisted_name.rs:14:9
|
-14 | let titi = 42; //~ERROR use of a blacklisted/placeholder name `titi`
+14 | let titi = 42;
| ^^^^
error: use of a blacklisted/placeholder name `toto`
#![feature(attr_literals)]
#![feature(plugin)]
#![plugin(clippy(conf_file=42))]
-//~^ ERROR `conf_file` value must be a string
+
fn main() {}
#[deny(match_same_arms)]
fn if_same_then_else() -> Result<&'static str, ()> {
if true {
- //~^NOTE same as this
+
Foo { bar: 42 };
0..10;
..;
0...10;
foo();
}
- else { //~ERROR this `if` has identical blocks
+ else {
Foo { bar: 42 };
0..10;
..;
let _ = match 42 {
42 => {
- //~^ NOTE same as this
- //~| NOTE removing
+
+
foo();
let mut a = 42 + [23].len() as i32;
if true {
a = -31-a;
a
}
- _ => { //~ERROR this `match` has identical arm bodies
+ _ => {
foo();
let mut a = 42 + [23].len() as i32;
if true {
let _ = match Abc::A {
Abc::A => 0,
- //~^ NOTE same as this
- //~| NOTE removing
+
+
Abc::B => 1,
- _ => 0, //~ERROR this `match` has identical arm bodies
+ _ => 0,
};
if true {
}
let _ = if true {
- //~^NOTE same as this
+
42
}
- else { //~ERROR this `if` has identical blocks
+ else {
42
};
if true {
- //~^NOTE same as this
+
for _ in &[42] {
let foo: &Option<_> = &Some::<u8>(42);
if true {
}
}
}
- else { //~ERROR this `if` has identical blocks
+ else {
for _ in &[42] {
let foo: &Option<_> = &Some::<u8>(42);
if true {
}
if true {
- //~^NOTE same as this
+
let bar = if true {
42
}
while foo() { break; }
bar + 1;
}
- else { //~ERROR this `if` has identical blocks
+ else {
let bar = if true {
42
}
}
if true {
- //~^NOTE same as this
+
let _ = match 42 {
42 => 1,
a if a > 0 => 2,
else if false {
foo();
}
- else if foo() { //~ERROR this `if` has identical blocks
+ else if foo() {
let _ = match 42 {
42 => 1,
a if a > 0 => 2,
}
if true {
- //~^NOTE same as this
+
if let Some(a) = Some(42) {}
}
- else { //~ERROR this `if` has identical blocks
+ else {
if let Some(a) = Some(42) {}
}
if true {
- //~^NOTE same as this
+
if let (1, .., 3) = (1, 2, 3) {}
}
- else { //~ERROR this `if` has identical blocks
+ else {
if let (1, .., 3) = (1, 2, 3) {}
}
let _ = match 42 {
42 => foo(),
- //~^NOTE same as this
- //~|NOTE `42 | 51`
- 51 => foo(), //~ERROR this `match` has identical arm bodies
+
+
+ 51 => foo(),
_ => true,
};
let _ = match Some(42) {
Some(_) => 24,
- //~^NOTE same as this
- //~|NOTE `Some(_) | None`
- None => 24, //~ERROR this `match` has identical arm bodies
+
+
+ None => 24,
};
let _ = match Some(42) {
match (Some(42), Some(42)) {
(Some(a), None) => bar(a),
- //~^NOTE same as this
- //~|NOTE `(Some(a), None) | (None, Some(a))`
- (None, Some(a)) => bar(a), //~ERROR this `match` has identical arm bodies
+
+
+ (None, Some(a)) => bar(a),
_ => (),
}
match (Some(42), Some(42)) {
(Some(a), ..) => bar(a),
- //~^NOTE same as this
- //~|NOTE `(Some(a), ..) | (.., Some(a))`
- (.., Some(a)) => bar(a), //~ERROR this `match` has identical arm bodies
+
+
+ (.., Some(a)) => bar(a),
_ => (),
}
match (1, 2, 3) {
(1, .., 3) => 42,
- //~^NOTE same as this
- //~|NOTE `(1, .., 3) | (.., 3)`
- (.., 3) => 42, //~ERROR this `match` has identical arm bodies
+
+
+ (.., 3) => 42,
_ => 0,
};
let _ = if true {
- //~^NOTE same as this
+
0.0
- } else { //~ERROR this `if` has identical blocks
+ } else {
0.0
};
let _ = if true {
- //~^NOTE same as this
+
-0.0
- } else { //~ERROR this `if` has identical blocks
+ } else {
-0.0
};
// Same NaNs
let _ = if true {
- //~^NOTE same as this
+
std::f32::NAN
- } else { //~ERROR this `if` has identical blocks
+ } else {
std::f32::NAN
};
}
if true {
- //~^NOTE same as this
+
try!(Ok("foo"));
}
- else { //~ERROR this `if` has identical blocks
+ else {
try!(Ok("foo"));
}
if true {
- //~^NOTE same as this
+
let foo = "";
return Ok(&foo[0..]);
}
let foo = "bar";
return Ok(&foo[0..]);
}
- else { //~ERROR this `if` has identical blocks
+ else {
let foo = "";
return Ok(&foo[0..]);
}
let b = false;
if b {
- //~^NOTE same as this
+
}
- else if b { //~ERROR this `if` has the same condition as a previous if
+ else if b {
}
if a == 1 {
- //~^NOTE same as this
+
}
- else if a == 1 { //~ERROR this `if` has the same condition as a previous if
+ else if a == 1 {
}
if 2*a == 1 {
- //~^NOTE same as this
+
}
else if 2*a == 2 {
}
- else if 2*a == 1 { //~ERROR this `if` has the same condition as a previous if
+ else if 2*a == 1 {
}
else if a == 1 {
}
error: this `if` has identical blocks
--> $DIR/copies.rs:40:10
|
-40 | else { //~ERROR this `if` has identical blocks
+40 | else {
| __________^ starting here...
41 | | Foo { bar: 42 };
42 | | 0..10;
error: this `match` has identical arm bodies
--> $DIR/copies.rs:91:14
|
-91 | _ => { //~ERROR this `match` has identical arm bodies
+91 | _ => {
| ______________^ starting here...
92 | | foo();
93 | | let mut a = 42 + [23].len() as i32;
error: this `match` has identical arm bodies
--> $DIR/copies.rs:107:14
|
-107 | _ => 0, //~ERROR this `match` has identical arm bodies
+107 | _ => 0,
| ^
|
note: same as this
error: this `if` has identical blocks
--> $DIR/copies.rs:118:10
|
-118 | else { //~ERROR this `if` has identical blocks
+118 | else {
| __________^ starting here...
119 | | 42
120 | | };
|
114 | let _ = if true {
| _____________________^ starting here...
-115 | | //~^NOTE same as this
+115 | |
116 | | 42
117 | | }
| |_____^ ...ending here
error: this `if` has identical blocks
--> $DIR/copies.rs:133:10
|
-133 | else { //~ERROR this `if` has identical blocks
+133 | else {
| ^
|
note: same as this
error: this `if` has identical blocks
--> $DIR/copies.rs:156:10
|
-156 | else { //~ERROR this `if` has identical blocks
+156 | else {
| ^
|
note: same as this
error: this `if` has identical blocks
--> $DIR/copies.rs:180:19
|
-180 | else if foo() { //~ERROR this `if` has identical blocks
+180 | else if foo() {
| ___________________^ starting here...
181 | | let _ = match 42 {
182 | | 42 => 1,
|
168 | if true {
| _____________^ starting here...
-169 | | //~^NOTE same as this
+169 | |
170 | | let _ = match 42 {
171 | | 42 => 1,
172 | | a if a > 0 => 2,
error: this `if` has identical blocks
--> $DIR/copies.rs:193:10
|
-193 | else { //~ERROR this `if` has identical blocks
+193 | else {
| __________^ starting here...
194 | | if let Some(a) = Some(42) {}
195 | | }
|
189 | if true {
| _____________^ starting here...
-190 | | //~^NOTE same as this
+190 | |
191 | | if let Some(a) = Some(42) {}
192 | | }
| |_____^ ...ending here
error: this `if` has identical blocks
--> $DIR/copies.rs:201:10
|
-201 | else { //~ERROR this `if` has identical blocks
+201 | else {
| __________^ starting here...
202 | | if let (1, .., 3) = (1, 2, 3) {}
203 | | }
|
197 | if true {
| _____________^ starting here...
-198 | | //~^NOTE same as this
+198 | |
199 | | if let (1, .., 3) = (1, 2, 3) {}
200 | | }
| |_____^ ...ending here
error: this `match` has identical arm bodies
--> $DIR/copies.rs:258:15
|
-258 | 51 => foo(), //~ERROR this `match` has identical arm bodies
+258 | 51 => foo(),
| ^^^^^
|
note: same as this
error: this `match` has identical arm bodies
--> $DIR/copies.rs:266:17
|
-266 | None => 24, //~ERROR this `match` has identical arm bodies
+266 | None => 24,
| ^^
|
note: same as this
error: this `match` has identical arm bodies
--> $DIR/copies.rs:290:28
|
-290 | (None, Some(a)) => bar(a), //~ERROR this `match` has identical arm bodies
+290 | (None, Some(a)) => bar(a),
| ^^^^^^
|
note: same as this
error: this `match` has identical arm bodies
--> $DIR/copies.rs:298:26
|
-298 | (.., Some(a)) => bar(a), //~ERROR this `match` has identical arm bodies
+298 | (.., Some(a)) => bar(a),
| ^^^^^^
|
note: same as this
error: this `match` has identical arm bodies
--> $DIR/copies.rs:306:20
|
-306 | (.., 3) => 42, //~ERROR this `match` has identical arm bodies
+306 | (.., 3) => 42,
| ^^
|
note: same as this
error: this `if` has identical blocks
--> $DIR/copies.rs:313:12
|
-313 | } else { //~ERROR this `if` has identical blocks
+313 | } else {
| ____________^ starting here...
314 | | 0.0
315 | | };
|
310 | let _ = if true {
| _____________________^ starting here...
-311 | | //~^NOTE same as this
+311 | |
312 | | 0.0
-313 | | } else { //~ERROR this `if` has identical blocks
+313 | | } else {
| |_____^ ...ending here
error: this `if` has identical blocks
--> $DIR/copies.rs:320:12
|
-320 | } else { //~ERROR this `if` has identical blocks
+320 | } else {
| ____________^ starting here...
321 | | -0.0
322 | | };
|
317 | let _ = if true {
| _____________________^ starting here...
-318 | | //~^NOTE same as this
+318 | |
319 | | -0.0
-320 | | } else { //~ERROR this `if` has identical blocks
+320 | | } else {
| |_____^ ...ending here
error: this `if` has identical blocks
--> $DIR/copies.rs:341:12
|
-341 | } else { //~ERROR this `if` has identical blocks
+341 | } else {
| ____________^ starting here...
342 | | std::f32::NAN
343 | | };
|
338 | let _ = if true {
| _____________________^ starting here...
-339 | | //~^NOTE same as this
+339 | |
340 | | std::f32::NAN
-341 | | } else { //~ERROR this `if` has identical blocks
+341 | | } else {
| |_____^ ...ending here
error: this `if` has identical blocks
--> $DIR/copies.rs:360:10
|
-360 | else { //~ERROR this `if` has identical blocks
+360 | else {
| __________^ starting here...
361 | | try!(Ok("foo"));
362 | | }
|
356 | if true {
| _____________^ starting here...
-357 | | //~^NOTE same as this
+357 | |
358 | | try!(Ok("foo"));
359 | | }
| |_____^ ...ending here
error: this `if` has identical blocks
--> $DIR/copies.rs:373:10
|
-373 | else { //~ERROR this `if` has identical blocks
+373 | else {
| __________^ starting here...
374 | | let foo = "";
375 | | return Ok(&foo[0..]);
|
364 | if true {
| _____________^ starting here...
-365 | | //~^NOTE same as this
+365 | |
366 | | let foo = "";
367 | | return Ok(&foo[0..]);
368 | | }
error: this `if` has the same condition as a previous if
--> $DIR/copies.rs:388:13
|
-388 | else if b { //~ERROR this `if` has the same condition as a previous if
+388 | else if b {
| ^
|
note: lint level defined here
error: this `if` has the same condition as a previous if
--> $DIR/copies.rs:394:13
|
-394 | else if a == 1 { //~ERROR this `if` has the same condition as a previous if
+394 | else if a == 1 {
| ^^^^^^
|
note: same as this
error: this `if` has the same condition as a previous if
--> $DIR/copies.rs:402:13
|
-402 | else if 2*a == 1 { //~ERROR this `if` has the same condition as a previous if
+402 | else if 2*a == 1 {
| ^^^^^^^^
|
note: same as this
#![deny(cyclomatic_complexity)]
#![allow(unused)]
-fn main() { //~ERROR the function has a cyclomatic complexity of 28
+fn main() {
if true {
println!("a");
}
}
#[cyclomatic_complexity = "0"]
-fn kaboom() { //~ ERROR: the function has a cyclomatic complexity of 7
+fn kaboom() {
let n = 0;
'a: for i in 0..20 {
'b: for j in i..20 {
}
#[cyclomatic_complexity = "0"]
-fn lots_of_short_circuits() -> bool { //~ ERROR: the function has a cyclomatic complexity of 1
+fn lots_of_short_circuits() -> bool {
true && false && true && false && true && false && true
}
#[cyclomatic_complexity = "0"]
-fn lots_of_short_circuits2() -> bool { //~ ERROR: the function has a cyclomatic complexity of 1
+fn lots_of_short_circuits2() -> bool {
true || false || true || false || true || false || true
}
#[cyclomatic_complexity = "0"]
-fn baa() { //~ ERROR: the function has a cyclomatic complexity of 2
- let x = || match 99 { //~ ERROR: the function has a cyclomatic complexity of 2
+fn baa() {
+ let x = || match 99 {
0 => 0,
1 => 1,
2 => 2,
}
#[cyclomatic_complexity = "0"]
-fn bar() { //~ ERROR: the function has a cyclomatic complexity of 2
+fn bar() {
match 99 {
0 => println!("hi"),
_ => println!("bye"),
}
#[cyclomatic_complexity = "0"]
-fn barr() { //~ ERROR: the function has a cyclomatic complexity of 2
+fn barr() {
match 99 {
0 => println!("hi"),
1 => println!("bla"),
}
#[cyclomatic_complexity = "0"]
-fn barr2() { //~ ERROR: the function has a cyclomatic complexity of 3
+fn barr2() {
match 99 {
0 => println!("hi"),
1 => println!("bla"),
}
#[cyclomatic_complexity = "0"]
-fn barrr() { //~ ERROR: the function has a cyclomatic complexity of 2
+fn barrr() {
match 99 {
0 => println!("hi"),
1 => panic!("bla"),
}
#[cyclomatic_complexity = "0"]
-fn barrr2() { //~ ERROR: the function has a cyclomatic complexity of 3
+fn barrr2() {
match 99 {
0 => println!("hi"),
1 => panic!("bla"),
}
#[cyclomatic_complexity = "0"]
-fn barrrr() { //~ ERROR: the function has a cyclomatic complexity of 2
+fn barrrr() {
match 99 {
0 => println!("hi"),
1 => println!("bla"),
}
#[cyclomatic_complexity = "0"]
-fn barrrr2() { //~ ERROR: the function has a cyclomatic complexity of 3
+fn barrrr2() {
match 99 {
0 => println!("hi"),
1 => println!("bla"),
}
#[cyclomatic_complexity = "0"]
-fn cake() { //~ ERROR: the function has a cyclomatic complexity of 2
+fn cake() {
if 4 == 5 {
println!("yea");
} else {
#[cyclomatic_complexity = "0"]
-pub fn read_file(input_path: &str) -> String { //~ ERROR: the function has a cyclomatic complexity of 4
+pub fn read_file(input_path: &str) -> String {
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;
enum Void {}
#[cyclomatic_complexity = "0"]
-fn void(void: Void) { //~ ERROR: the function has a cyclomatic complexity of 1
+fn void(void: Void) {
if true {
match void {
}
}
#[cyclomatic_complexity = "0"]
-fn try() -> Result<i32, &'static str> { //~ ERROR: cyclomatic complexity of 1
+fn try() -> Result<i32, &'static str> {
match 5 {
5 => Ok(5),
_ => return Err("bla"),
}
#[cyclomatic_complexity = "0"]
-fn try_again() -> Result<i32, &'static str> { //~ ERROR: cyclomatic complexity of 1
+fn try_again() -> Result<i32, &'static str> {
let _ = try!(Ok(42));
let _ = try!(Ok(43));
let _ = try!(Ok(44));
}
#[cyclomatic_complexity = "0"]
-fn early() -> Result<i32, &'static str> { //~ ERROR: cyclomatic complexity of 1
+fn early() -> Result<i32, &'static str> {
return Ok(5);
return Ok(5);
return Ok(5);
}
#[cyclomatic_complexity = "0"]
-fn early_ret() -> i32 { //~ ERROR: cyclomatic complexity of 8
+fn early_ret() -> i32 {
let a = if true { 42 } else { return 0; };
let a = if a < 99 { 42 } else { return 0; };
let a = if a < 99 { 42 } else { return 0; };
error: the function has a cyclomatic complexity of 28
--> $DIR/cyclomatic_complexity.rs:7:1
|
-7 | fn main() { //~ERROR the function has a cyclomatic complexity of 28
+7 | fn main() {
| ^
|
note: lint level defined here
error: the function has a cyclomatic complexity of 7
--> $DIR/cyclomatic_complexity.rs:92:1
|
-92 | fn kaboom() { //~ ERROR: the function has a cyclomatic complexity of 7
+92 | fn kaboom() {
| ^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:138:1
|
-138 | fn lots_of_short_circuits() -> bool { //~ ERROR: the function has a cyclomatic complexity of 1
+138 | fn lots_of_short_circuits() -> bool {
| _^ starting here...
139 | | true && false && true && false && true && false && true
140 | | }
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:143:1
|
-143 | fn lots_of_short_circuits2() -> bool { //~ ERROR: the function has a cyclomatic complexity of 1
+143 | fn lots_of_short_circuits2() -> bool {
| _^ starting here...
144 | | true || false || true || false || true || false || true
145 | | }
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:148:1
|
-148 | fn baa() { //~ ERROR: the function has a cyclomatic complexity of 2
+148 | fn baa() {
| ^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:149:13
|
-149 | let x = || match 99 { //~ ERROR: the function has a cyclomatic complexity of 2
+149 | let x = || match 99 {
| _____________^ starting here...
150 | | 0 => 0,
151 | | 1 => 1,
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:166:1
|
-166 | fn bar() { //~ ERROR: the function has a cyclomatic complexity of 2
+166 | fn bar() {
| _^ starting here...
167 | | match 99 {
168 | | 0 => println!("hi"),
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:185:1
|
-185 | fn barr() { //~ ERROR: the function has a cyclomatic complexity of 2
+185 | fn barr() {
| _^ starting here...
186 | | match 99 {
187 | | 0 => println!("hi"),
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity.rs:195:1
|
-195 | fn barr2() { //~ ERROR: the function has a cyclomatic complexity of 3
+195 | fn barr2() {
| ^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:211:1
|
-211 | fn barrr() { //~ ERROR: the function has a cyclomatic complexity of 2
+211 | fn barrr() {
| _^ starting here...
212 | | match 99 {
213 | | 0 => println!("hi"),
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity.rs:221:1
|
-221 | fn barrr2() { //~ ERROR: the function has a cyclomatic complexity of 3
+221 | fn barrr2() {
| ^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:237:1
|
-237 | fn barrrr() { //~ ERROR: the function has a cyclomatic complexity of 2
+237 | fn barrrr() {
| _^ starting here...
238 | | match 99 {
239 | | 0 => println!("hi"),
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity.rs:247:1
|
-247 | fn barrrr2() { //~ ERROR: the function has a cyclomatic complexity of 3
+247 | fn barrrr2() {
| ^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:263:1
|
-263 | fn cake() { //~ ERROR: the function has a cyclomatic complexity of 2
+263 | fn cake() {
| _^ starting here...
264 | | if 4 == 5 {
265 | | println!("yea");
error: the function has a cyclomatic complexity of 4
--> $DIR/cyclomatic_complexity.rs:274:1
|
-274 | pub fn read_file(input_path: &str) -> String { //~ ERROR: the function has a cyclomatic complexity of 4
+274 | pub fn read_file(input_path: &str) -> String {
| ^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:305:1
|
-305 | fn void(void: Void) { //~ ERROR: the function has a cyclomatic complexity of 1
+305 | fn void(void: Void) {
| _^ starting here...
306 | | if true {
307 | | match void {
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:319:1
|
-319 | fn try() -> Result<i32, &'static str> { //~ ERROR: cyclomatic complexity of 1
+319 | fn try() -> Result<i32, &'static str> {
| _^ starting here...
320 | | match 5 {
321 | | 5 => Ok(5),
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:327:1
|
-327 | fn try_again() -> Result<i32, &'static str> { //~ ERROR: cyclomatic complexity of 1
+327 | fn try_again() -> Result<i32, &'static str> {
| ^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:343:1
|
-343 | fn early() -> Result<i32, &'static str> { //~ ERROR: cyclomatic complexity of 1
+343 | fn early() -> Result<i32, &'static str> {
| ^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 8
--> $DIR/cyclomatic_complexity.rs:356:1
|
-356 | fn early_ret() -> i32 { //~ ERROR: cyclomatic complexity of 8
+356 | fn early_ret() -> i32 {
| ^
|
= help: you could split it up into multiple smaller functions
}
#[cyclomatic_complexity = "0"]
-fn kaboom() { //~ ERROR: the function has a cyclomatic complexity of 3
+fn kaboom() {
if 42 == 43 {
panic!();
} else if "cake" == "lie" {
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity_attr_used.rs:11:1
|
-11 | fn kaboom() { //~ ERROR: the function has a cyclomatic complexity of 3
+11 | fn kaboom() {
| _^ starting here...
12 | | if 42 == 43 {
13 | | panic!();
}
#[derive(Hash)]
-//~^ ERROR you are deriving `Hash` but have implemented `PartialEq` explicitly
+
struct Bar;
impl PartialEq for Bar {
}
#[derive(Hash)]
-//~^ ERROR you are deriving `Hash` but have implemented `PartialEq` explicitly
+
struct Baz;
impl PartialEq<Baz> for Baz {
struct Bah;
impl Hash for Bah {
-//~^ ERROR you are implementing `Hash` explicitly but have derived `PartialEq`
+
fn hash<H: Hasher>(&self, _: &mut H) {}
}
struct Qux;
impl Clone for Qux {
-//~^ ERROR you are implementing `Clone` explicitly on a `Copy` type
+
fn clone(&self) -> Self { Qux }
}
}
impl<'a> Clone for Lt<'a> {
-//~^ ERROR you are implementing `Clone` explicitly on a `Copy` type
+
fn clone(&self) -> Self { unimplemented!() }
}
|
37 | impl Hash for Bah {
| _^ starting here...
-38 | | //~^ ERROR you are implementing `Hash` explicitly but have derived `PartialEq`
+38 | |
39 | | fn hash<H: Hasher>(&self, _: &mut H) {}
40 | | }
| |_^ ...ending here
|
45 | impl Clone for Qux {
| _^ starting here...
-46 | | //~^ ERROR you are implementing `Clone` explicitly on a `Copy` type
+46 | |
47 | | fn clone(&self) -> Self { Qux }
48 | | }
| |_^ ...ending here
|
45 | impl Clone for Qux {
| _^ starting here...
-46 | | //~^ ERROR you are implementing `Clone` explicitly on a `Copy` type
+46 | |
47 | | fn clone(&self) -> Self { Qux }
48 | | }
| |_^ ...ending here
|
70 | impl<'a> Clone for Lt<'a> {
| _^ starting here...
-71 | | //~^ ERROR you are implementing `Clone` explicitly on a `Copy` type
+71 | |
72 | | fn clone(&self) -> Self { unimplemented!() }
73 | | }
| |_^ ...ending here
|
70 | impl<'a> Clone for Lt<'a> {
| _^ starting here...
-71 | | //~^ ERROR you are implementing `Clone` explicitly on a `Copy` type
+71 | |
72 | | fn clone(&self) -> Self { unimplemented!() }
73 | | }
| |_^ ...ending here
#[allow(unused_variables, unnecessary_operation, short_circuit_statement)]
fn main() {
let b = true;
- b || diverge(); //~ ERROR sub-expression diverges
- b || A.foo(); //~ ERROR sub-expression diverges
+ b || diverge();
+ b || A.foo();
}
#[allow(dead_code, unused_variables)]
let x = match 5 {
4 => return,
5 => continue,
- 6 => true || return, //~ ERROR sub-expression diverges
- 7 => true || continue, //~ ERROR sub-expression diverges
+ 6 => true || return,
+ 7 => true || continue,
8 => break,
9 => diverge(),
- 3 => true || diverge(), //~ ERROR sub-expression diverges
+ 3 => true || diverge(),
10 => match 42 {
99 => return,
_ => true || panic!("boo"),
},
- _ => true || break, //~ ERROR sub-expression diverges
+ _ => true || break,
};
}
}
error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:18:10
|
-18 | b || diverge(); //~ ERROR sub-expression diverges
+18 | b || diverge();
| ^^^^^^^^^
|
note: lint level defined here
error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:19:10
|
-19 | b || A.foo(); //~ ERROR sub-expression diverges
+19 | b || A.foo();
| ^^^^^^^
error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:28:26
|
-28 | 6 => true || return, //~ ERROR sub-expression diverges
+28 | 6 => true || return,
| ^^^^^^
error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:29:26
|
-29 | 7 => true || continue, //~ ERROR sub-expression diverges
+29 | 7 => true || continue,
| ^^^^^^^^
error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:32:26
|
-32 | 3 => true || diverge(), //~ ERROR sub-expression diverges
+32 | 3 => true || diverge(),
| ^^^^^^^^^
error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:37:26
|
-37 | _ => true || break, //~ ERROR sub-expression diverges
+37 | _ => true || break,
| ^^^^^
error: aborting due to 6 previous errors
use collections::linked_list::LinkedList;
trait Foo {
- type Baz = LinkedList<u8>; //~ ERROR I see you're using a LinkedList!
- fn foo(LinkedList<u8>); //~ ERROR I see you're using a LinkedList!
- const BAR : Option<LinkedList<u8>>; //~ ERROR I see you're using a LinkedList!
+ type Baz = LinkedList<u8>;
+ fn foo(LinkedList<u8>);
+ const BAR : Option<LinkedList<u8>>;
}
// ok, we don’t want to warn for implementations, see #605
struct Bar;
impl Bar {
- fn foo(_: LinkedList<u8>) {} //~ ERROR I see you're using a LinkedList!
+ fn foo(_: LinkedList<u8>) {}
}
-pub fn test(my_favourite_linked_list: LinkedList<u8>) { //~ ERROR I see you're using a LinkedList!
+pub fn test(my_favourite_linked_list: LinkedList<u8>) {
println!("{:?}", my_favourite_linked_list)
}
-pub fn test_ret() -> Option<LinkedList<u8>> { //~ ERROR I see you're using a LinkedList!
+pub fn test_ret() -> Option<LinkedList<u8>> {
unimplemented!();
}
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
--> $DIR/dlist.rs:13:16
|
-13 | type Baz = LinkedList<u8>; //~ ERROR I see you're using a LinkedList!
+13 | type Baz = LinkedList<u8>;
| ^^^^^^^^^^^^^^
|
= note: #[deny(linkedlist)] implied by #[deny(clippy)]
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
--> $DIR/dlist.rs:14:12
|
-14 | fn foo(LinkedList<u8>); //~ ERROR I see you're using a LinkedList!
+14 | fn foo(LinkedList<u8>);
| ^^^^^^^^^^^^^^
|
= note: #[deny(linkedlist)] implied by #[deny(clippy)]
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
--> $DIR/dlist.rs:15:24
|
-15 | const BAR : Option<LinkedList<u8>>; //~ ERROR I see you're using a LinkedList!
+15 | const BAR : Option<LinkedList<u8>>;
| ^^^^^^^^^^^^^^
|
= note: #[deny(linkedlist)] implied by #[deny(clippy)]
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
--> $DIR/dlist.rs:26:15
|
-26 | fn foo(_: LinkedList<u8>) {} //~ ERROR I see you're using a LinkedList!
+26 | fn foo(_: LinkedList<u8>) {}
| ^^^^^^^^^^^^^^
|
= note: #[deny(linkedlist)] implied by #[deny(clippy)]
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
--> $DIR/dlist.rs:29:39
|
-29 | pub fn test(my_favourite_linked_list: LinkedList<u8>) { //~ ERROR I see you're using a LinkedList!
+29 | pub fn test(my_favourite_linked_list: LinkedList<u8>) {
| ^^^^^^^^^^^^^^
|
= note: #[deny(linkedlist)] implied by #[deny(clippy)]
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
--> $DIR/dlist.rs:33:29
|
-33 | pub fn test_ret() -> Option<LinkedList<u8>> { //~ ERROR I see you're using a LinkedList!
+33 | pub fn test_ret() -> Option<LinkedList<u8>> {
| ^^^^^^^^^^^^^^
|
= note: #[deny(linkedlist)] implied by #[deny(clippy)]
//! This file tests for the DOC_MARKDOWN lint
-//~^ ERROR: you should put `DOC_MARKDOWN` between ticks
+
#![feature(plugin)]
#![plugin(clippy)]
#![deny(doc_markdown)]
/// The foo_bar function does _nothing_. See also foo::bar. (note the dot there)
-//~^ ERROR: you should put `foo_bar` between ticks
-//~| ERROR: you should put `foo::bar` between ticks
+
+
/// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun
-//~^ ERROR: you should put `Foo::some_fun` between ticks
+
/// which should be reported only once despite being __doubly bad__.
/// Here be ::is::a::global:path.
-//~^ ERROR: you should put `is::a::global:path` between ticks
+
/// That's not code ~NotInCodeBlock~.
-//~^ ERROR: you should put `NotInCodeBlock` between ticks
+
/// be_sure_we_got_to_the_end_of_it
-//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
fn foo_bar() {
}
/// _foo bar_
/// ~~~
/// be_sure_we_got_to_the_end_of_it
-//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
fn multiline_codeblock() {
}
/// multiline
/// emphasis_.
/// be_sure_we_got_to_the_end_of_it
-//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
fn test_emphasis() {
}
/// 32kb 32Mb 32Gb 32Tb 32Pb 32Eb
/// NaN
/// be_sure_we_got_to_the_end_of_it
-//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
fn test_units() {
}
/// `💣`
/// `❤️`
/// ß_foo
-//~^ ERROR: you should put `ß_foo` between ticks
+
/// ℝ_foo
-//~^ ERROR: you should put `ℝ_foo` between ticks
+
/// 💣_foo
/// ❤️_foo
/// foo_ß
-//~^ ERROR: you should put `foo_ß` between ticks
+
/// foo_ℝ
-//~^ ERROR: you should put `foo_ℝ` between ticks
+
/// foo_💣
/// foo_❤️
/// [ßdummy textß][foo_1ß]
/// [foo3_💣]: dummy text
/// [foo4_❤️]: dummy text
/// be_sure_we_got_to_the_end_of_it
-//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
fn test_unicode() {
}
/// This test has [a link_with_underscores][chunked-example] inside it. See #823.
-//~^ ERROR: you should put `link_with_underscores` between ticks
+
/// See also [the issue tracker](https://github.com/Manishearth/rust-clippy/search?q=doc_markdown&type=Issues)
/// on GitHub (which is a camel-cased word, but is OK). And here is another [inline link][inline_link].
/// It can also be [inline_link2].
-//~^ ERROR: you should put `inline_link2` between ticks
+
///
/// [chunked-example]: https://en.wikipedia.org/wiki/Chunked_transfer_encoding#Example
/// [inline_link]: https://foobar
/// expression of the type `_ <bit_op> m <cmp_op> c` (where `<bit_op>`
/// is one of {`&`, '|'} and `<cmp_op>` is one of {`!=`, `>=`, `>` ,
/// be_sure_we_got_to_the_end_of_it
-//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
fn main() {
foo_bar();
multiline_codeblock();
/// # CamelCaseThing
///
/// Not a title #897 CamelCaseThing
-//~^ ERROR: you should put `CamelCaseThing` between ticks
+
/// be_sure_we_got_to_the_end_of_it
-//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
fn issue897() {
}
/// I am confused by brackets? (foo `x_y`)
/// I am confused by brackets? (`x_y` foo)
/// be_sure_we_got_to_the_end_of_it
-//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
fn issue900() {
}
/// [iterator]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html
/// [helper_types]: ../helper_types/index.html
/// be_sure_we_got_to_the_end_of_it
-//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
fn issue883() {
}
And BarQuz too.
be_sure_we_got_to_the_end_of_it
*/
-//~^^^^^^^^ ERROR: you should put `FooBar` between ticks
-//~^^^^ ERROR: you should put `BarQuz` between ticks
-//~^^^^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
+
+
fn issue1073() {
}
And BarQuz too.
be_sure_we_got_to_the_end_of_it
*/
-//~^^^^^^^^ ERROR: you should put `FooBar` between ticks
-//~^^^^ ERROR: you should put `BarQuz` between ticks
-//~^^^^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
+
+
fn issue1073_alt() {
}
/// StillDont
/// ````
/// be_sure_we_got_to_the_end_of_it
-//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
+
fn four_quotes() {
}
let x = 1;
-x;
-(-x);
- --x; //~ERROR: `--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op
+ --x;
}
error: `--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op
--> $DIR/double_neg.rs:9:5
|
-9 | --x; //~ERROR: `--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op
+9 | --x;
| ^^^
|
note: lint level defined here
}
fn simple_double_parens() -> i32 {
- ((0)) //~ERROR Consider removing unnecessary double parentheses
+ ((0))
}
fn fn_double_parens() {
- dummy_fn((0)); //~ERROR Consider removing unnecessary double parentheses
+ dummy_fn((0));
}
fn method_double_parens(x: DummyStruct) {
- x.dummy_method((0)); //~ERROR Consider removing unnecessary double parentheses
+ x.dummy_method((0));
}
fn tuple_double_parens() -> (i32, i32) {
- ((1, 2)) //~ERROR Consider removing unnecessary double parentheses
+ ((1, 2))
}
fn unit_double_parens() {
- (()) //~ERROR Consider removing unnecessary double parentheses
+ (())
}
fn fn_tuple_ok() {
error: Consider removing unnecessary double parentheses
--> $DIR/double_parens.rs:16:5
|
-16 | ((0)) //~ERROR Consider removing unnecessary double parentheses
+16 | ((0))
| ^^^^^
|
note: lint level defined here
error: Consider removing unnecessary double parentheses
--> $DIR/double_parens.rs:20:14
|
-20 | dummy_fn((0)); //~ERROR Consider removing unnecessary double parentheses
+20 | dummy_fn((0));
| ^^^
error: Consider removing unnecessary double parentheses
--> $DIR/double_parens.rs:24:20
|
-24 | x.dummy_method((0)); //~ERROR Consider removing unnecessary double parentheses
+24 | x.dummy_method((0));
| ^^^
error: Consider removing unnecessary double parentheses
--> $DIR/double_parens.rs:28:5
|
-28 | ((1, 2)) //~ERROR Consider removing unnecessary double parentheses
+28 | ((1, 2))
| ^^^^^^^^
error: Consider removing unnecessary double parentheses
--> $DIR/double_parens.rs:32:5
|
-32 | (()) //~ERROR Consider removing unnecessary double parentheses
+32 | (())
| ^^^^
error: aborting due to 5 previous errors
struct SomeStruct;
fn main() {
- drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument
- forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument
+ drop(&SomeStruct);
+ forget(&SomeStruct);
let mut owned1 = SomeStruct;
- drop(&owned1); //~ERROR call to `std::mem::drop` with a reference argument
- drop(&&owned1); //~ERROR call to `std::mem::drop` with a reference argument
- drop(&mut owned1); //~ERROR call to `std::mem::drop` with a reference argument
+ drop(&owned1);
+ drop(&&owned1);
+ drop(&mut owned1);
drop(owned1); //OK
let mut owned2 = SomeStruct;
- forget(&owned2); //~ERROR call to `std::mem::forget` with a reference argument
- forget(&&owned2); //~ERROR call to `std::mem::forget` with a reference argument
- forget(&mut owned2); //~ERROR call to `std::mem::forget` with a reference argument
+ forget(&owned2);
+ forget(&&owned2);
+ forget(&mut owned2);
forget(owned2); //OK
let reference1 = &SomeStruct;
- drop(reference1); //~ERROR call to `std::mem::drop` with a reference argument
- forget(&*reference1); //~ERROR call to `std::mem::forget` with a reference argument
+ drop(reference1);
+ forget(&*reference1);
let reference2 = &mut SomeStruct;
- drop(reference2); //~ERROR call to `std::mem::drop` with a reference argument
+ drop(reference2);
let reference3 = &mut SomeStruct;
- forget(reference3); //~ERROR call to `std::mem::forget` with a reference argument
+ forget(reference3);
let ref reference4 = SomeStruct;
- drop(reference4); //~ERROR call to `std::mem::drop` with a reference argument
- forget(reference4); //~ERROR call to `std::mem::forget` with a reference argument
+ drop(reference4);
+ forget(reference4);
}
#[allow(dead_code)]
fn test_generic_fn_drop<T>(val: T) {
- drop(&val); //~ERROR call to `std::mem::drop` with a reference argument
+ drop(&val);
drop(val); //OK
}
#[allow(dead_code)]
fn test_generic_fn_forget<T>(val: T) {
- forget(&val); //~ERROR call to `std::mem::forget` with a reference argument
+ forget(&val);
forget(val); //OK
}
fn test_similarly_named_function() {
fn drop<T>(_val: T) {}
drop(&SomeStruct); //OK; call to unrelated function which happens to have the same name
- std::mem::drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument
+ std::mem::drop(&SomeStruct);
fn forget<T>(_val: T) {}
forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name
- std::mem::forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument
+ std::mem::forget(&SomeStruct);
}
error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing
--> $DIR/drop_forget_ref.rs:12:5
|
-12 | drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument
+12 | drop(&SomeStruct);
| ^^^^^^^^^^^^^^^^^
|
note: lint level defined here
note: argument has type &SomeStruct
--> $DIR/drop_forget_ref.rs:12:10
|
-12 | drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument
+12 | drop(&SomeStruct);
| ^^^^^^^^^^^
error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing
--> $DIR/drop_forget_ref.rs:13:5
|
-13 | forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument
+13 | forget(&SomeStruct);
| ^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
note: argument has type &SomeStruct
--> $DIR/drop_forget_ref.rs:13:12
|
-13 | forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument
+13 | forget(&SomeStruct);
| ^^^^^^^^^^^
error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing
--> $DIR/drop_forget_ref.rs:16:5
|
-16 | drop(&owned1); //~ERROR call to `std::mem::drop` with a reference argument
+16 | drop(&owned1);
| ^^^^^^^^^^^^^
|
note: argument has type &SomeStruct
--> $DIR/drop_forget_ref.rs:16:10
|
-16 | drop(&owned1); //~ERROR call to `std::mem::drop` with a reference argument
+16 | drop(&owned1);
| ^^^^^^^
error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing
--> $DIR/drop_forget_ref.rs:17:5
|
-17 | drop(&&owned1); //~ERROR call to `std::mem::drop` with a reference argument
+17 | drop(&&owned1);
| ^^^^^^^^^^^^^^
|
note: argument has type &&SomeStruct
--> $DIR/drop_forget_ref.rs:17:10
|
-17 | drop(&&owned1); //~ERROR call to `std::mem::drop` with a reference argument
+17 | drop(&&owned1);
| ^^^^^^^^
error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing
--> $DIR/drop_forget_ref.rs:18:5
|
-18 | drop(&mut owned1); //~ERROR call to `std::mem::drop` with a reference argument
+18 | drop(&mut owned1);
| ^^^^^^^^^^^^^^^^^
|
note: argument has type &mut SomeStruct
--> $DIR/drop_forget_ref.rs:18:10
|
-18 | drop(&mut owned1); //~ERROR call to `std::mem::drop` with a reference argument
+18 | drop(&mut owned1);
| ^^^^^^^^^^^
error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing
--> $DIR/drop_forget_ref.rs:21:5
|
-21 | forget(&owned2); //~ERROR call to `std::mem::forget` with a reference argument
+21 | forget(&owned2);
| ^^^^^^^^^^^^^^^
|
note: argument has type &SomeStruct
--> $DIR/drop_forget_ref.rs:21:12
|
-21 | forget(&owned2); //~ERROR call to `std::mem::forget` with a reference argument
+21 | forget(&owned2);
| ^^^^^^^
error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing
--> $DIR/drop_forget_ref.rs:22:5
|
-22 | forget(&&owned2); //~ERROR call to `std::mem::forget` with a reference argument
+22 | forget(&&owned2);
| ^^^^^^^^^^^^^^^^
|
note: argument has type &&SomeStruct
--> $DIR/drop_forget_ref.rs:22:12
|
-22 | forget(&&owned2); //~ERROR call to `std::mem::forget` with a reference argument
+22 | forget(&&owned2);
| ^^^^^^^^
error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing
--> $DIR/drop_forget_ref.rs:23:5
|
-23 | forget(&mut owned2); //~ERROR call to `std::mem::forget` with a reference argument
+23 | forget(&mut owned2);
| ^^^^^^^^^^^^^^^^^^^
|
note: argument has type &mut SomeStruct
--> $DIR/drop_forget_ref.rs:23:12
|
-23 | forget(&mut owned2); //~ERROR call to `std::mem::forget` with a reference argument
+23 | forget(&mut owned2);
| ^^^^^^^^^^^
error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing
--> $DIR/drop_forget_ref.rs:27:5
|
-27 | drop(reference1); //~ERROR call to `std::mem::drop` with a reference argument
+27 | drop(reference1);
| ^^^^^^^^^^^^^^^^
|
note: argument has type &SomeStruct
--> $DIR/drop_forget_ref.rs:27:10
|
-27 | drop(reference1); //~ERROR call to `std::mem::drop` with a reference argument
+27 | drop(reference1);
| ^^^^^^^^^^
error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing
--> $DIR/drop_forget_ref.rs:28:5
|
-28 | forget(&*reference1); //~ERROR call to `std::mem::forget` with a reference argument
+28 | forget(&*reference1);
| ^^^^^^^^^^^^^^^^^^^^
|
note: argument has type &SomeStruct
--> $DIR/drop_forget_ref.rs:28:12
|
-28 | forget(&*reference1); //~ERROR call to `std::mem::forget` with a reference argument
+28 | forget(&*reference1);
| ^^^^^^^^^^^^
error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing
--> $DIR/drop_forget_ref.rs:31:5
|
-31 | drop(reference2); //~ERROR call to `std::mem::drop` with a reference argument
+31 | drop(reference2);
| ^^^^^^^^^^^^^^^^
|
note: argument has type &mut SomeStruct
--> $DIR/drop_forget_ref.rs:31:10
|
-31 | drop(reference2); //~ERROR call to `std::mem::drop` with a reference argument
+31 | drop(reference2);
| ^^^^^^^^^^
error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing
--> $DIR/drop_forget_ref.rs:33:5
|
-33 | forget(reference3); //~ERROR call to `std::mem::forget` with a reference argument
+33 | forget(reference3);
| ^^^^^^^^^^^^^^^^^^
|
note: argument has type &mut SomeStruct
--> $DIR/drop_forget_ref.rs:33:12
|
-33 | forget(reference3); //~ERROR call to `std::mem::forget` with a reference argument
+33 | forget(reference3);
| ^^^^^^^^^^
error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing
--> $DIR/drop_forget_ref.rs:36:5
|
-36 | drop(reference4); //~ERROR call to `std::mem::drop` with a reference argument
+36 | drop(reference4);
| ^^^^^^^^^^^^^^^^
|
note: argument has type &SomeStruct
--> $DIR/drop_forget_ref.rs:36:10
|
-36 | drop(reference4); //~ERROR call to `std::mem::drop` with a reference argument
+36 | drop(reference4);
| ^^^^^^^^^^
error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing
--> $DIR/drop_forget_ref.rs:37:5
|
-37 | forget(reference4); //~ERROR call to `std::mem::forget` with a reference argument
+37 | forget(reference4);
| ^^^^^^^^^^^^^^^^^^
|
note: argument has type &SomeStruct
--> $DIR/drop_forget_ref.rs:37:12
|
-37 | forget(reference4); //~ERROR call to `std::mem::forget` with a reference argument
+37 | forget(reference4);
| ^^^^^^^^^^
error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing
--> $DIR/drop_forget_ref.rs:42:5
|
-42 | drop(&val); //~ERROR call to `std::mem::drop` with a reference argument
+42 | drop(&val);
| ^^^^^^^^^^
|
note: argument has type &T
--> $DIR/drop_forget_ref.rs:42:10
|
-42 | drop(&val); //~ERROR call to `std::mem::drop` with a reference argument
+42 | drop(&val);
| ^^^^
error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing
--> $DIR/drop_forget_ref.rs:48:5
|
-48 | forget(&val); //~ERROR call to `std::mem::forget` with a reference argument
+48 | forget(&val);
| ^^^^^^^^^^^^
|
note: argument has type &T
--> $DIR/drop_forget_ref.rs:48:12
|
-48 | forget(&val); //~ERROR call to `std::mem::forget` with a reference argument
+48 | forget(&val);
| ^^^^
error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing
--> $DIR/drop_forget_ref.rs:56:5
|
-56 | std::mem::drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument
+56 | std::mem::drop(&SomeStruct);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: argument has type &SomeStruct
--> $DIR/drop_forget_ref.rs:56:20
|
-56 | std::mem::drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument
+56 | std::mem::drop(&SomeStruct);
| ^^^^^^^^^^^
error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing
--> $DIR/drop_forget_ref.rs:59:5
|
-59 | std::mem::forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument
+59 | std::mem::forget(&SomeStruct);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: argument has type &SomeStruct
--> $DIR/drop_forget_ref.rs:59:22
|
-59 | std::mem::forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument
+59 | std::mem::forget(&SomeStruct);
| ^^^^^^^^^^^
error: aborting due to 18 previous errors
#![deny(duplicate_underscore_argument)]
#[allow(dead_code, unused)]
-fn join_the_dark_side(darth: i32, _darth: i32) {} //~ERROR `darth` already exists
+fn join_the_dark_side(darth: i32, _darth: i32) {}
fn join_the_light_side(knight: i32, _master: i32) {} // the Force is strong with this one
fn main() {
join_the_dark_side(0, 0);
join_the_light_side(0, 0);
-}
\ No newline at end of file
+}
error: `darth` already exists, having another argument having almost the same name makes code comprehension and documentation more difficult
--> $DIR/duplicate_underscore_argument.rs:7:23
|
-7 | fn join_the_dark_side(darth: i32, _darth: i32) {} //~ERROR `darth` already exists
+7 | fn join_the_dark_side(darth: i32, _darth: i32) {}
| ^^^^^
|
note: lint level defined here
#![allow(dead_code)]
#![deny(empty_enum)]
-enum Empty {} //~ ERROR enum with no variants
- //~^ HELP consider using the uninhabited type `!` or a wrapper around it
+enum Empty {}
+
fn main() {
}
error: enum with no variants
--> $DIR/empty_enum.rs:7:1
|
-7 | enum Empty {} //~ ERROR enum with no variants
+7 | enum Empty {}
| ^^^^^^^^^^^^^
|
note: lint level defined here
help: consider using the uninhabited type `!` or a wrapper around it
--> $DIR/empty_enum.rs:7:1
|
-7 | enum Empty {} //~ ERROR enum with no variants
+7 | enum Empty {}
| ^^^^^^^^^^^^^
error: aborting due to previous error
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); }
- //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
- //~| HELP consider
- //~| SUGGESTION m.entry(k).or_insert(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); }
- //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
- //~| HELP consider
- //~| SUGGESTION m.entry(k)
+
+
+
}
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 };
- //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
- //~| HELP consider
- //~| SUGGESTION m.entry(k)
+
+
+
}
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) };
- //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
- //~| HELP consider
- //~| SUGGESTION m.entry(k)
+
+
+
}
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 };
- //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
- //~| HELP consider
- //~| SUGGESTION m.entry(k)
+
+
+
}
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) };
- //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
- //~| HELP consider
- //~| SUGGESTION m.entry(k)
+
+
+
}
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 };
- //~^ ERROR usage of `contains_key` followed by `insert` on a `BTreeMap`
- //~| HELP consider
- //~| SUGGESTION m.entry(k)
+
+
+
}
fn insert_other_if_absent<K: Eq + Hash, V>(m: &mut HashMap<K, V>, k: K, o: K, v: V) {
#![deny(clippy, clippy_pedantic)]
#![allow(unused_imports, dead_code, missing_docs_in_private_items)]
-use std::cmp::Ordering::*; //~ ERROR: don't use glob imports for enum variants
+use std::cmp::Ordering::*;
enum Enum {
_Foo,
}
-use self::Enum::*; //~ ERROR: don't use glob imports for enum variants
+use self::Enum::*;
fn blarg() {
use self::Enum::*; // ok, just for a function
error: don't use glob imports for enum variants
--> $DIR/enum_glob_use.rs:6:1
|
-6 | use std::cmp::Ordering::*; //~ ERROR: don't use glob imports for enum variants
+6 | use std::cmp::Ordering::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(enum_glob_use)] implied by #[deny(clippy_pedantic)]
error: don't use glob imports for enum variants
--> $DIR/enum_glob_use.rs:12:1
|
-12 | use self::Enum::*; //~ ERROR: don't use glob imports for enum variants
+12 | use self::Enum::*;
| ^^^^^^^^^^^^^^^^^^
|
= note: #[deny(enum_glob_use)] implied by #[deny(clippy_pedantic)]
}
enum Foo {
- cFoo, //~ ERROR: Variant name ends with the enum's name
+ cFoo,
cBar,
cBaz,
}
cBar,
}
-enum Food { //~ ERROR: All variants have the same prefix: `Food`
- FoodGood, //~ ERROR: Variant name starts with the enum's name
- FoodMiddle, //~ ERROR: Variant name starts with the enum's name
- FoodBad, //~ ERROR: Variant name starts with the enum's name
+enum Food {
+ FoodGood,
+ FoodMiddle,
+ FoodBad,
}
enum Stuff {
StuffBad, // no error
}
-enum BadCallType { //~ ERROR: All variants have the same prefix: `CallType`
+enum BadCallType {
CallTypeCall,
CallTypeCreate,
CallTypeDestroy,
CallTypeCreate,
}
-enum Consts { //~ ERROR: All variants have the same prefix: `Constant`
+enum Consts {
ConstantInt,
ConstantCake,
ConstantLie,
WithOut,
}
-enum Seallll { //~ ERROR: All variants have the same prefix: `With`
+enum Seallll {
WithOutCake,
WithOutTea,
WithOut,
}
-enum NonCaps { //~ ERROR: All variants have the same prefix: `Prefix`
+enum NonCaps {
Prefix的,
PrefixTea,
PrefixCake,
}
-pub enum PubSeall { //~ ERROR: All variants have the same prefix:
+pub enum PubSeall {
WithOutCake,
WithOutTea,
WithOut,
error: Variant name ends with the enum's name
--> $DIR/enum_variants.rs:14:5
|
-14 | cFoo, //~ ERROR: Variant name ends with the enum's name
+14 | cFoo,
| ^^^^
|
= note: #[deny(enum_variant_names)] implied by #[deny(clippy)]
error: Variant name starts with the enum's name
--> $DIR/enum_variants.rs:25:5
|
-25 | FoodGood, //~ ERROR: Variant name starts with the enum's name
+25 | FoodGood,
| ^^^^^^^^
|
= note: #[deny(enum_variant_names)] implied by #[deny(clippy)]
error: Variant name starts with the enum's name
--> $DIR/enum_variants.rs:26:5
|
-26 | FoodMiddle, //~ ERROR: Variant name starts with the enum's name
+26 | FoodMiddle,
| ^^^^^^^^^^
|
= note: #[deny(enum_variant_names)] implied by #[deny(clippy)]
error: Variant name starts with the enum's name
--> $DIR/enum_variants.rs:27:5
|
-27 | FoodBad, //~ ERROR: Variant name starts with the enum's name
+27 | FoodBad,
| ^^^^^^^
|
= note: #[deny(enum_variant_names)] implied by #[deny(clippy)]
error: All variants have the same prefix: `Food`
--> $DIR/enum_variants.rs:24:1
|
-24 | enum Food { //~ ERROR: All variants have the same prefix: `Food`
+24 | enum Food {
| _^ starting here...
-25 | | FoodGood, //~ ERROR: Variant name starts with the enum's name
-26 | | FoodMiddle, //~ ERROR: Variant name starts with the enum's name
-27 | | FoodBad, //~ ERROR: Variant name starts with the enum's name
+25 | | FoodGood,
+26 | | FoodMiddle,
+27 | | FoodBad,
28 | | }
| |_^ ...ending here
|
error: All variants have the same prefix: `CallType`
--> $DIR/enum_variants.rs:34:1
|
-34 | enum BadCallType { //~ ERROR: All variants have the same prefix: `CallType`
+34 | enum BadCallType {
| _^ starting here...
35 | | CallTypeCall,
36 | | CallTypeCreate,
error: All variants have the same prefix: `Constant`
--> $DIR/enum_variants.rs:45:1
|
-45 | enum Consts { //~ ERROR: All variants have the same prefix: `Constant`
+45 | enum Consts {
| _^ starting here...
46 | | ConstantInt,
47 | | ConstantCake,
error: All variants have the same prefix: `With`
--> $DIR/enum_variants.rs:78:1
|
-78 | enum Seallll { //~ ERROR: All variants have the same prefix: `With`
+78 | enum Seallll {
| _^ starting here...
79 | | WithOutCake,
80 | | WithOutTea,
error: All variants have the same prefix: `Prefix`
--> $DIR/enum_variants.rs:84:1
|
-84 | enum NonCaps { //~ ERROR: All variants have the same prefix: `Prefix`
+84 | enum NonCaps {
| _^ starting here...
85 | | Prefix的,
86 | | PrefixTea,
error: All variants have the same prefix: `With`
--> $DIR/enum_variants.rs:90:1
|
-90 | pub enum PubSeall { //~ ERROR: All variants have the same prefix:
+90 | pub enum PubSeall {
| _^ starting here...
91 | | WithOutCake,
92 | | WithOutTea,
#[repr(usize)]
enum NonPortable {
- X = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+ X = 0x1_0000_0000,
Y = 0,
Z = 0x7FFF_FFFF,
A = 0xFFFF_FFFF,
}
enum NonPortableNoHint {
- X = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+ X = 0x1_0000_0000,
Y = 0,
Z = 0x7FFF_FFFF,
- A = 0xFFFF_FFFF, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+ A = 0xFFFF_FFFF,
}
#[repr(isize)]
enum NonPortableSigned {
X = -1,
Y = 0x7FFF_FFFF,
- Z = 0xFFFF_FFFF, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
- A = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+ Z = 0xFFFF_FFFF,
+ A = 0x1_0000_0000,
B = std::i32::MIN as isize,
- C = (std::i32::MIN as isize) - 1, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+ C = (std::i32::MIN as isize) - 1,
}
enum NonPortableSignedNoHint {
X = -1,
Y = 0x7FFF_FFFF,
- Z = 0xFFFF_FFFF, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
- A = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+ Z = 0xFFFF_FFFF,
+ A = 0x1_0000_0000,
}
/*
error: Clike enum variant discriminant is not portable to 32-bit targets
--> $DIR/enums_clike.rs:10:5
|
-10 | X = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+10 | X = 0x1_0000_0000,
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)]
error: Clike enum variant discriminant is not portable to 32-bit targets
--> $DIR/enums_clike.rs:17:5
|
-17 | X = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+17 | X = 0x1_0000_0000,
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)]
error: Clike enum variant discriminant is not portable to 32-bit targets
--> $DIR/enums_clike.rs:20:5
|
-20 | A = 0xFFFF_FFFF, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+20 | A = 0xFFFF_FFFF,
| ^^^^^^^^^^^^^^^
|
= note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)]
error: Clike enum variant discriminant is not portable to 32-bit targets
--> $DIR/enums_clike.rs:27:5
|
-27 | Z = 0xFFFF_FFFF, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+27 | Z = 0xFFFF_FFFF,
| ^^^^^^^^^^^^^^^
|
= note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)]
error: Clike enum variant discriminant is not portable to 32-bit targets
--> $DIR/enums_clike.rs:28:5
|
-28 | A = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+28 | A = 0x1_0000_0000,
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)]
error: Clike enum variant discriminant is not portable to 32-bit targets
--> $DIR/enums_clike.rs:30:5
|
-30 | C = (std::i32::MIN as isize) - 1, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+30 | C = (std::i32::MIN as isize) - 1,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)]
error: Clike enum variant discriminant is not portable to 32-bit targets
--> $DIR/enums_clike.rs:36:5
|
-36 | Z = 0xFFFF_FFFF, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+36 | Z = 0xFFFF_FFFF,
| ^^^^^^^^^^^^^^^
|
= note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)]
error: Clike enum variant discriminant is not portable to 32-bit targets
--> $DIR/enums_clike.rs:37:5
|
-37 | A = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets
+37 | A = 0x1_0000_0000,
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)]
#[deny(nonminimal_bool)]
fn main() {
// simple values and comparisons
- 1 == 1; //~ERROR equal expressions
- "no" == "no"; //~ERROR equal expressions
+ 1 == 1;
+ "no" == "no";
// even though I agree that no means no ;-)
- false != false; //~ERROR equal expressions
- 1.5 < 1.5; //~ERROR equal expressions
- 1u64 >= 1u64; //~ERROR equal expressions
+ false != false;
+ 1.5 < 1.5;
+ 1u64 >= 1u64;
// casts, methods, parentheses
- (1 as u64) & (1 as u64); //~ERROR equal expressions
- 1 ^ ((((((1)))))); //~ERROR equal expressions
+ (1 as u64) & (1 as u64);
+ 1 ^ ((((((1))))));
// unary and binary operators
- (-(2) < -(2)); //~ERROR equal expressions
+ (-(2) < -(2));
((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
- //~^ ERROR equal expressions as operands to `==`
- //~^^ ERROR equal expressions as operands to `&`
- //~^^^ ERROR equal expressions as operands to `&`
- (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; //~ERROR equal expressions
+
+
+
+ (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
// various other things
- ([1] != [1]); //~ERROR equal expressions
- ((1, 2) != (1, 2)); //~ERROR equal expressions
+ ([1] != [1]);
+ ((1, 2) != (1, 2));
vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros
// const folding
- 1 + 1 == 2; //~ERROR equal expressions
- 1 - 1 == 0; //~ERROR equal expressions as operands to `==`
- //~^ ERROR equal expressions as operands to `-`
+ 1 + 1 == 2;
+ 1 - 1 == 0;
+
+
+ 1 - 1;
+ 1 / 1;
+ true && true;
+
+ true || true;
- 1 - 1; //~ERROR equal expressions
- 1 / 1; //~ERROR equal expressions
- true && true; //~ERROR equal expressions
- //~|ERROR this boolean expression can be simplified
- true || true; //~ERROR equal expressions
- //~|ERROR this boolean expression can be simplified
let a: u32 = 0;
let b: u32 = 0;
- a == b && b == a; //~ERROR equal expressions
- //~|ERROR this boolean expression can be simplified
- a != b && b != a; //~ERROR equal expressions
- //~|ERROR this boolean expression can be simplified
- a < b && b > a; //~ERROR equal expressions
- //~|ERROR this boolean expression can be simplified
- a <= b && b >= a; //~ERROR equal expressions
- //~|ERROR this boolean expression can be simplified
+ a == b && b == a;
+
+ a != b && b != a;
+
+ a < b && b > a;
+
+ a <= b && b >= a;
+
let mut a = vec![1];
- a == a; //~ERROR equal expressions
+ a == a;
2*a.len() == 2*a.len(); // ok, functions
a.pop() == a.pop(); // ok, functions
}
error: this boolean expression can be simplified
--> $DIR/eq_op.rs:41:5
|
-41 | true && true; //~ERROR equal expressions
+41 | true && true;
| ^^^^^^^^^^^^
|
note: lint level defined here
7 | #[deny(nonminimal_bool)]
| ^^^^^^^^^^^^^^^
help: try
- | true; //~ERROR equal expressions
+ | true;
error: this boolean expression can be simplified
--> $DIR/eq_op.rs:43:5
|
-43 | true || true; //~ERROR equal expressions
+43 | true || true;
| ^^^^^^^^^^^^
|
help: try
- | true; //~ERROR equal expressions
+ | true;
error: this boolean expression can be simplified
--> $DIR/eq_op.rs:49:5
|
-49 | a == b && b == a; //~ERROR equal expressions
+49 | a == b && b == a;
| ^^^^^^^^^^^^^^^^
|
help: try
- | a == b; //~ERROR equal expressions
+ | a == b;
error: this boolean expression can be simplified
--> $DIR/eq_op.rs:51:5
|
-51 | a != b && b != a; //~ERROR equal expressions
+51 | a != b && b != a;
| ^^^^^^^^^^^^^^^^
|
help: try
- | a != b; //~ERROR equal expressions
+ | a != b;
error: this boolean expression can be simplified
--> $DIR/eq_op.rs:53:5
|
-53 | a < b && b > a; //~ERROR equal expressions
+53 | a < b && b > a;
| ^^^^^^^^^^^^^^
|
help: try
- | a < b; //~ERROR equal expressions
+ | a < b;
error: this boolean expression can be simplified
--> $DIR/eq_op.rs:55:5
|
-55 | a <= b && b >= a; //~ERROR equal expressions
+55 | a <= b && b >= a;
| ^^^^^^^^^^^^^^^^
|
help: try
- | a <= b; //~ERROR equal expressions
+ | a <= b;
error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:10:5
|
-10 | 1 == 1; //~ERROR equal expressions
+10 | 1 == 1;
| ^^^^^^
|
note: lint level defined here
error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:11:5
|
-11 | "no" == "no"; //~ERROR equal expressions
+11 | "no" == "no";
| ^^^^^^^^^^^^
error: equal expressions as operands to `!=`
--> $DIR/eq_op.rs:13:5
|
-13 | false != false; //~ERROR equal expressions
+13 | false != false;
| ^^^^^^^^^^^^^^
error: equal expressions as operands to `<`
--> $DIR/eq_op.rs:14:5
|
-14 | 1.5 < 1.5; //~ERROR equal expressions
+14 | 1.5 < 1.5;
| ^^^^^^^^^
error: equal expressions as operands to `>=`
--> $DIR/eq_op.rs:15:5
|
-15 | 1u64 >= 1u64; //~ERROR equal expressions
+15 | 1u64 >= 1u64;
| ^^^^^^^^^^^^
error: equal expressions as operands to `&`
--> $DIR/eq_op.rs:18:5
|
-18 | (1 as u64) & (1 as u64); //~ERROR equal expressions
+18 | (1 as u64) & (1 as u64);
| ^^^^^^^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `^`
--> $DIR/eq_op.rs:19:5
|
-19 | 1 ^ ((((((1)))))); //~ERROR equal expressions
+19 | 1 ^ ((((((1))))));
| ^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `<`
--> $DIR/eq_op.rs:22:5
|
-22 | (-(2) < -(2)); //~ERROR equal expressions
+22 | (-(2) < -(2));
| ^^^^^^^^^^^^^
error: equal expressions as operands to `==`
error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:27:5
|
-27 | (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; //~ERROR equal expressions
+27 | (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `!=`
--> $DIR/eq_op.rs:30:5
|
-30 | ([1] != [1]); //~ERROR equal expressions
+30 | ([1] != [1]);
| ^^^^^^^^^^^^
error: equal expressions as operands to `!=`
--> $DIR/eq_op.rs:31:5
|
-31 | ((1, 2) != (1, 2)); //~ERROR equal expressions
+31 | ((1, 2) != (1, 2));
| ^^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:35:5
|
-35 | 1 + 1 == 2; //~ERROR equal expressions
+35 | 1 + 1 == 2;
| ^^^^^^^^^^
error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:36:5
|
-36 | 1 - 1 == 0; //~ERROR equal expressions as operands to `==`
+36 | 1 - 1 == 0;
| ^^^^^^^^^^
error: equal expressions as operands to `-`
--> $DIR/eq_op.rs:36:5
|
-36 | 1 - 1 == 0; //~ERROR equal expressions as operands to `==`
+36 | 1 - 1 == 0;
| ^^^^^
error: equal expressions as operands to `-`
--> $DIR/eq_op.rs:39:5
|
-39 | 1 - 1; //~ERROR equal expressions
+39 | 1 - 1;
| ^^^^^
error: equal expressions as operands to `/`
--> $DIR/eq_op.rs:40:5
|
-40 | 1 / 1; //~ERROR equal expressions
+40 | 1 / 1;
| ^^^^^
error: equal expressions as operands to `&&`
--> $DIR/eq_op.rs:41:5
|
-41 | true && true; //~ERROR equal expressions
+41 | true && true;
| ^^^^^^^^^^^^
error: equal expressions as operands to `||`
--> $DIR/eq_op.rs:43:5
|
-43 | true || true; //~ERROR equal expressions
+43 | true || true;
| ^^^^^^^^^^^^
error: equal expressions as operands to `&&`
--> $DIR/eq_op.rs:49:5
|
-49 | a == b && b == a; //~ERROR equal expressions
+49 | a == b && b == a;
| ^^^^^^^^^^^^^^^^
error: equal expressions as operands to `&&`
--> $DIR/eq_op.rs:51:5
|
-51 | a != b && b != a; //~ERROR equal expressions
+51 | a != b && b != a;
| ^^^^^^^^^^^^^^^^
error: equal expressions as operands to `&&`
--> $DIR/eq_op.rs:53:5
|
-53 | a < b && b > a; //~ERROR equal expressions
+53 | a < b && b > a;
| ^^^^^^^^^^^^^^
error: equal expressions as operands to `&&`
--> $DIR/eq_op.rs:55:5
|
-55 | a <= b && b >= a; //~ERROR equal expressions
+55 | a <= b && b >= a;
| ^^^^^^^^^^^^^^^^
error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:59:5
|
-59 | a == a; //~ERROR equal expressions
+59 | a == a;
| ^^^^^^
error: aborting due to 32 previous errors
}
fn warn_call() {
- let x = box A; //~ ERROR local variable
+ let x = box A;
x.foo();
}
-fn warn_arg(x: Box<A>) { //~ ERROR local variable
+fn warn_arg(x: Box<A>) {
x.foo();
}
fn warn_rename_call() {
let x = box A;
- let y = x; //~ ERROR local variable
+ let y = x;
y.foo(); // via autoderef
}
fn warn_notuse() {
- let bz = box A; //~ ERROR local variable
+ let bz = box A;
}
fn warn_pass() {
- let bz = box A; //~ ERROR local variable
+ let bz = box A;
take_ref(&bz); // via deref coercion
}
fn nowarn_ref_take() {
// false positive, should actually warn
- let x = box A; //~ ERROR local variable
+ let x = box A;
let y = &x;
take_box(y);
}
}
fn warn_match() {
- let x = box A; //~ ERROR local variable
+ let x = box A;
match &x { // not moved
ref y => ()
}
_peeked: I::Item,
}
-pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () { //~ ERROR local variable doesn't need
+pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {
}
error: local variable doesn't need to be boxed here
--> $DIR/escape_analysis.rs:33:9
|
-33 | let x = box A; //~ ERROR local variable
+33 | let x = box A;
| ^
|
note: lint level defined here
error: local variable doesn't need to be boxed here
--> $DIR/escape_analysis.rs:37:13
|
-37 | fn warn_arg(x: Box<A>) { //~ ERROR local variable
+37 | fn warn_arg(x: Box<A>) {
| ^
error: local variable doesn't need to be boxed here
--> $DIR/escape_analysis.rs:49:9
|
-49 | let y = x; //~ ERROR local variable
+49 | let y = x;
| ^
error: local variable doesn't need to be boxed here
--> $DIR/escape_analysis.rs:54:9
|
-54 | let bz = box A; //~ ERROR local variable
+54 | let bz = box A;
| ^^
error: local variable doesn't need to be boxed here
--> $DIR/escape_analysis.rs:58:9
|
-58 | let bz = box A; //~ ERROR local variable
+58 | let bz = box A;
| ^^
error: local variable doesn't need to be boxed here
--> $DIR/escape_analysis.rs:88:9
|
-88 | let x = box A; //~ ERROR local variable
+88 | let x = box A;
| ^
error: local variable doesn't need to be boxed here
--> $DIR/escape_analysis.rs:101:9
|
-101 | let x = box A; //~ ERROR local variable
+101 | let x = box A;
| ^
error: local variable doesn't need to be boxed here
--> $DIR/escape_analysis.rs:130:12
|
-130 | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () { //~ ERROR local variable doesn't need
+130 | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {
| ^^^^^^^^^^^
error: aborting due to 8 previous errors
fn main() {
let a = Some(1u8).map(|a| foo(a));
- //~^ ERROR redundant closure found
- //~| HELP remove closure as shown
- //~| SUGGESTION let a = Some(1u8).map(foo);
+
+
+
meta(|a| foo(a));
- //~^ ERROR redundant closure found
- //~| HELP remove closure as shown
- //~| SUGGESTION meta(foo);
+
+
+
let c = Some(1u8).map(|a| {1+2; foo}(a));
- //~^ ERROR redundant closure found
- //~| HELP remove closure as shown
- //~| SUGGESTION let c = Some(1u8).map({1+2; foo});
+
+
+
let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted?
all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
- //~^ WARN needless_borrow
+
unsafe {
Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn
}
// See #815
let e = Some(1u8).map(|a| divergent(a));
let e = Some(1u8).map(|a| generic(a));
- //~^ ERROR redundant closure found
- //~| HELP remove closure as shown
- //~| SUGGESTION map(generic);
+
+
+
let e = Some(1u8).map(generic);
// See #515
fn main() {
let mut x = 0;
let a = { x = 1; 1 } + x;
- //~^ ERROR unsequenced read
+
// Example from iss#277
- x += { x = 20; 2 }; //~ERROR unsequenced read
+ x += { x = 20; 2 };
// Does it work in weird places?
// ...in the base for a struct expression?
struct Foo { a: i32, b: i32 };
let base = Foo { a: 4, b: 5 };
let foo = Foo { a: x, .. { x = 6; base } };
- //~^ ERROR unsequenced read
+
// ...inside a closure?
let closure = || {
let mut x = 0;
- x += { x = 20; 2 }; //~ERROR unsequenced read
+ x += { x = 20; 2 };
};
// ...not across a closure?
let mut y = 0;
error: unsequenced read of a variable
--> $DIR/eval_order_dependence.rs:12:5
|
-12 | x += { x = 20; 2 }; //~ERROR unsequenced read
+12 | x += { x = 20; 2 };
| ^
|
note: whether read occurs before this write depends on evaluation order
--> $DIR/eval_order_dependence.rs:12:12
|
-12 | x += { x = 20; 2 }; //~ERROR unsequenced read
+12 | x += { x = 20; 2 };
| ^^^^^^
error: unsequenced read of a variable
error: unsequenced read of a variable
--> $DIR/eval_order_dependence.rs:23:9
|
-23 | x += { x = 20; 2 }; //~ERROR unsequenced read
+23 | x += { x = 20; 2 };
| ^
|
note: whether read occurs before this write depends on evaluation order
--> $DIR/eval_order_dependence.rs:23:16
|
-23 | x += { x = 20; 2 }; //~ERROR unsequenced read
+23 | x += { x = 20; 2 };
| ^^^^^^
error: aborting due to 4 previous errors
#![allow(missing_docs_in_private_items)]
fn main() {
- let _: Vec<_> = vec![5; 6].into_iter() //~ERROR called `filter(p).map(q)` on an `Iterator`
+ let _: Vec<_> = vec![5; 6].into_iter()
.filter(|&x| x == 0)
.map(|x| x * 2)
.collect();
- let _: Vec<_> = vec![5_i8; 6].into_iter() //~ERROR called `filter(p).flat_map(q)` on an `Iterator`
+ 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() //~ERROR called `filter_map(p).flat_map(q)` on an `Iterator`
+ 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() //~ERROR called `filter_map(p).map(q)` on an `Iterator`
+ let _: Vec<_> = vec![5_i8; 6].into_iter()
.filter_map(|x| x.checked_mul(2))
.map(|x| x.checked_mul(2))
.collect();
error: called `filter(p).map(q)` on an `Iterator`. This is more succinctly expressed by calling `.filter_map(..)` instead.
--> $DIR/filter_methods.rs:8:21
|
-8 | let _: Vec<_> = vec![5; 6].into_iter() //~ERROR called `filter(p).map(q)` on an `Iterator`
+8 | let _: Vec<_> = vec![5; 6].into_iter()
| _____________________^ starting here...
9 | | .filter(|&x| x == 0)
10 | | .map(|x| x * 2)
error: called `filter(p).flat_map(q)` on an `Iterator`. This is more succinctly expressed by calling `.flat_map(..)` and filtering by returning an empty Iterator.
--> $DIR/filter_methods.rs:13:21
|
-13 | let _: Vec<_> = vec![5_i8; 6].into_iter() //~ERROR called `filter(p).flat_map(q)` on an `Iterator`
+13 | let _: Vec<_> = vec![5_i8; 6].into_iter()
| _____________________^ starting here...
14 | | .filter(|&x| x == 0)
15 | | .flat_map(|x| x.checked_mul(2))
error: called `filter_map(p).flat_map(q)` on an `Iterator`. This is more succinctly expressed by calling `.flat_map(..)` and filtering by returning an empty Iterator.
--> $DIR/filter_methods.rs:18:21
|
-18 | let _: Vec<_> = vec![5_i8; 6].into_iter() //~ERROR called `filter_map(p).flat_map(q)` on an `Iterator`
+18 | let _: Vec<_> = vec![5_i8; 6].into_iter()
| _____________________^ starting here...
19 | | .filter_map(|x| x.checked_mul(2))
20 | | .flat_map(|x| x.checked_mul(2))
error: called `filter_map(p).map(q)` on an `Iterator`. This is more succinctly expressed by only calling `.filter_map(..)` instead.
--> $DIR/filter_methods.rs:23:21
|
-23 | let _: Vec<_> = vec![5_i8; 6].into_iter() //~ERROR called `filter_map(p).map(q)` on an `Iterator`
+23 | let _: Vec<_> = vec![5_i8; 6].into_iter()
| _____________________^ starting here...
24 | | .filter_map(|x| x.checked_mul(2))
25 | | .map(|x| x.checked_mul(2))
ZERO + ZERO != 1.0; //no error, comparison with zero is ok
ONE == 1f32;
- //~^ ERROR strict comparison of f32 or f64
- //~| HELP within some error
- //~| SUGGESTION (ONE - 1f32).abs() < error
+
+
+
ONE == 1.0 + 0.0;
- //~^ ERROR strict comparison of f32 or f64
- //~| HELP within some error
- //~| SUGGESTION (ONE - (1.0 + 0.0)).abs() < error
+
+
+
ONE + ONE == ZERO + ONE + ONE;
- //~^ ERROR strict comparison of f32 or f64
- //~| HELP within some error
- //~| SUGGESTION (ONE + ONE - (ZERO + ONE + ONE)).abs() < error
+
+
+
ONE != 2.0;
- //~^ ERROR strict comparison of f32 or f64
- //~| HELP within some error
- //~| SUGGESTION (ONE - 2.0).abs() < error
+
+
+
ONE != 0.0; // no error, comparison with zero is ok
twice(ONE) != ONE;
- //~^ ERROR strict comparison of f32 or f64
- //~| HELP within some error
- //~| SUGGESTION (twice(ONE) - ONE).abs() < error
+
+
+
ONE as f64 != 2.0;
- //~^ ERROR strict comparison of f32 or f64
- //~| HELP within some error
- //~| SUGGESTION (ONE as f64 - 2.0).abs() < error
+
+
+
ONE as f64 != 0.0; // no error, comparison with zero is ok
let x : f64 = 1.0;
x == 1.0;
- //~^ ERROR strict comparison of f32 or f64
- //~| HELP within some error
- //~| SUGGESTION (x - 1.0).abs() < error
+
+
+
x != 0f64; // no error, comparison with zero is ok
twice(x) != twice(ONE as f64);
- //~^ ERROR strict comparison of f32 or f64
- //~| HELP within some error
- //~| SUGGESTION (twice(x) - twice(ONE as f64)).abs() < error
+
+
+
x < 0.0; // no errors, lower or greater comparisons need no fuzzyness
// check FOR_LOOP_OVER_OPTION lint
for x in option {
- //~^ ERROR for loop over `option`, which is an `Option`.
- //~| HELP consider replacing `for x in option` with `if let Some(x) = option`
+
+
println!("{}", x);
}
// check FOR_LOOP_OVER_RESULT lint
for x in result {
- //~^ ERROR for loop over `result`, which is a `Result`.
- //~| HELP consider replacing `for x in result` with `if let Ok(x) = result`
+
+
println!("{}", x);
}
for x in option.ok_or("x not found") {
- //~^ ERROR for loop over `option.ok_or("x not found")`, which is a `Result`.
- //~| HELP consider replacing `for x in option.ok_or("x not found")` with `if let Ok(x) = option.ok_or("x not found")`
+
+
println!("{}", x);
}
// make sure LOOP_OVER_NEXT lint takes precedence when next() is the last call in the chain
for x in v.iter().next() {
- //~^ ERROR you are iterating over `Iterator::next()` which is an Option
+
println!("{}", x);
}
// make sure we lint when next() is not the last call in the chain
for x in v.iter().next().and(Some(0)) {
- //~^ ERROR for loop over `v.iter().next().and(Some(0))`, which is an `Option`
- //~| HELP consider replacing `for x in v.iter().next().and(Some(0))` with `if let Some(x) = v.iter().next().and(Some(0))`
+
+
println!("{}", x);
}
for x in v.iter().next().ok_or("x not found") {
- //~^ ERROR for loop over `v.iter().next().ok_or("x not found")`, which is a `Result`
- //~| HELP consider replacing `for x in v.iter().next().ok_or("x not found")` with `if let Ok(x) = v.iter().next().ok_or("x not found")`
+
+
println!("{}", x);
}
let mut vec = vec![1, 2, 3, 4];
let vec2 = vec![1, 2, 3, 4];
for i in 0..vec.len() {
- //~^ ERROR `i` is only used to index `vec`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for <item> in &vec {
+
+
+
+
println!("{}", vec[i]);
}
for i in 0..vec.len() {
- //~^ WARNING unused variable
+
let i = 42; // make a different `i`
println!("{}", vec[i]); // ok, not the `i` of the for-loop
}
for i in 0..vec.len() { let _ = vec[i]; }
- //~^ ERROR `i` is only used to index `vec`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for <item> in &vec { let _ = vec[i]; }
+
+
+
+
// ICE #746
for j in 0..4 {
- //~^ ERROR `j` is only used to index `STATIC`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for <item> in STATIC.iter().take(4) {
+
+
+
+
println!("{:?}", STATIC[j]);
}
for j in 0..4 {
- //~^ ERROR `j` is only used to index `CONST`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for <item> in CONST.iter().take(4) {
+
+
+
+
println!("{:?}", CONST[j]);
}
for i in 0..vec.len() {
- //~^ ERROR `i` is used to index `vec`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for (i, <item>) in vec.iter().enumerate() {
+
+
+
+
println!("{} {}", vec[i], i);
}
for i in 0..vec.len() { // not an error, indexing more than one variable
}
for i in 0..vec.len() {
- //~^ ERROR `i` is only used to index `vec2`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for <item> in vec2.iter().take(vec.len()) {
+
+
+
+
println!("{}", vec2[i]);
}
for i in 5..vec.len() {
- //~^ ERROR `i` is only used to index `vec`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for <item> in vec.iter().skip(5) {
+
+
+
+
println!("{}", vec[i]);
}
for i in 0..MAX_LEN {
- //~^ ERROR `i` is only used to index `vec`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for <item> in vec.iter().take(MAX_LEN) {
+
+
+
+
println!("{}", vec[i]);
}
for i in 0...MAX_LEN {
- //~^ ERROR `i` is only used to index `vec`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for <item> in vec.iter().take(MAX_LEN + 1) {
+
+
+
+
println!("{}", vec[i]);
}
for i in 5..10 {
- //~^ ERROR `i` is only used to index `vec`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for <item> in vec.iter().take(10).skip(5) {
+
+
+
+
println!("{}", vec[i]);
}
for i in 5...10 {
- //~^ ERROR `i` is only used to index `vec`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for <item> in vec.iter().take(10 + 1).skip(5) {
+
+
+
+
println!("{}", vec[i]);
}
for i in 5..vec.len() {
- //~^ ERROR `i` is used to index `vec`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for (i, <item>) in vec.iter().enumerate().skip(5) {
+
+
+
+
println!("{} {}", vec[i], i);
}
for i in 5..10 {
- //~^ ERROR `i` is used to index `vec`
- //~| HELP consider
- //~| HELP consider
- //~| SUGGESTION for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
+
+
+
+
println!("{} {}", vec[i], i);
}
for i in 10..0 {
- //~^ERROR this range is empty so this for loop will never run
- //~|HELP consider
- //~|SUGGESTION (0..10).rev()
+
+
+
println!("{}", i);
}
for i in 10...0 {
- //~^ERROR this range is empty so this for loop will never run
- //~|HELP consider
- //~|SUGGESTION (0...10).rev()
+
+
+
println!("{}", i);
}
- for i in MAX_LEN..0 { //~ERROR this range is empty so this for loop will never run
- //~|HELP consider
- //~|SUGGESTION (0..MAX_LEN).rev()
+ for i in MAX_LEN..0 {
+
+
println!("{}", i);
}
- for i in 5..5 { //~ERROR this range is empty so this for loop will never run
+ for i in 5..5 {
println!("{}", i);
}
// testing that the empty range lint folds constants
for i in 10..5+4 {
- //~^ ERROR this range is empty so this for loop will never run
- //~| HELP if you are attempting to iterate over this range in reverse
- //~| SUGGESTION for i in (5+4..10).rev() {
+
+
+
println!("{}", i);
}
for i in (5+2)..(3-1) {
- //~^ ERROR this range is empty so this for loop will never run
- //~| HELP if you are attempting to iterate over this range in reverse
- //~| SUGGESTION for i in ((3-1)..(5+2)).rev() {
+
+
+
println!("{}", i);
}
- for i in (5+2)..(8-1) { //~ERROR this range is empty so this for loop will never run
+ for i in (5+2)..(8-1) {
println!("{}", i);
}
}
for _v in vec.iter() { }
- //~^ ERROR it is more idiomatic to loop over `&vec`
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in &vec {
+
+
+
for _v in vec.iter_mut() { }
- //~^ ERROR it is more idiomatic to loop over `&mut vec`
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in &mut vec {
+
+
+
let out_vec = vec![1,2,3];
for _v in out_vec.into_iter() { }
- //~^ ERROR it is more idiomatic to loop over `out_vec` instead of `out_vec.into_iter()`
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in out_vec {
+
+
+
for _v in &vec { } // these are fine
for _v in &mut vec { } // these are fine
for _v in [1, 2, 3].iter() { }
- //~^ ERROR it is more idiomatic to loop over `&[
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in &[1, 2, 3] {
+
+
+
for _v in (&mut [1, 2, 3]).iter() { } // no error
for _v in [0; 32].iter() {}
- //~^ ERROR it is more idiomatic to loop over `&[
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in &[0; 32] {
+
+
+
for _v in [0; 33].iter() {} // no error
let ll: LinkedList<()> = LinkedList::new();
for _v in ll.iter() { }
- //~^ ERROR it is more idiomatic to loop over `&ll`
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in &ll {
+
+
+
let vd: VecDeque<()> = VecDeque::new();
for _v in vd.iter() { }
- //~^ ERROR it is more idiomatic to loop over `&vd`
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in &vd {
+
+
+
let bh: BinaryHeap<()> = BinaryHeap::new();
for _v in bh.iter() { }
- //~^ ERROR it is more idiomatic to loop over `&bh`
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in &bh {
+
+
+
let hm: HashMap<(), ()> = HashMap::new();
for _v in hm.iter() { }
- //~^ ERROR it is more idiomatic to loop over `&hm`
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in &hm {
+
+
+
let bt: BTreeMap<(), ()> = BTreeMap::new();
for _v in bt.iter() { }
- //~^ ERROR it is more idiomatic to loop over `&bt`
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in &bt {
+
+
+
let hs: HashSet<()> = HashSet::new();
for _v in hs.iter() { }
- //~^ ERROR it is more idiomatic to loop over `&hs`
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in &hs {
+
+
+
let bs: BTreeSet<()> = BTreeSet::new();
for _v in bs.iter() { }
- //~^ ERROR it is more idiomatic to loop over `&bs`
- //~| HELP to write this more concisely, try looping over
- //~| SUGGESTION for _v in &bs {
- for _v in vec.iter().next() { } //~ERROR you are iterating over `Iterator::next()`
+
+
+
+ for _v in vec.iter().next() { }
let u = Unrelated(vec![]);
for _v in u.next() { } // no error
for _v in u.iter() { } // no error
let mut out = vec![];
- vec.iter().map(|x| out.push(x)).collect::<Vec<_>>(); //~ERROR you are collect()ing an iterator
+ vec.iter().map(|x| out.push(x)).collect::<Vec<_>>();
let _y = vec.iter().map(|x| out.push(x)).collect::<Vec<_>>(); // this is fine
// Loop with explicit counter variable
let mut _index = 0;
- for _v in &vec { _index += 1 } //~ERROR the variable `_index` is used as a loop counter
+ for _v in &vec { _index += 1 }
let mut _index = 1;
_index = 0;
- for _v in &vec { _index += 1 } //~ERROR the variable `_index` is used as a loop counter
+ for _v in &vec { _index += 1 }
// Potential false positives
let mut _index = 0;
let m : HashMap<u64, u64> = HashMap::new();
for (_, v) in &m {
- //~^ you seem to want to iterate on a map's values
- //~| HELP use the corresponding method
- //~| HELP use the corresponding method
- //~| SUGGESTION for v in m.values() {
+
+
+
+
let _v = v;
}
let m : Rc<HashMap<u64, u64>> = Rc::new(HashMap::new());
for (_, v) in &*m {
- //~^ you seem to want to iterate on a map's values
- //~| HELP use the corresponding method
- //~| HELP use the corresponding method
- //~| SUGGESTION for v in (*m).values() {
+
+
+
+
let _v = v;
// Here the `*` is not actually necesarry, but the test tests that we don't suggest
// `in *m.values()` as we used to
let mut m : HashMap<u64, u64> = HashMap::new();
for (_, v) in &mut m {
- //~^ you seem to want to iterate on a map's values
- //~| HELP use the corresponding method
- //~| HELP use the corresponding method
- //~| SUGGESTION for v in m.values_mut()
+
+
+
+
let _v = v;
}
let m: &mut HashMap<u64, u64> = &mut HashMap::new();
for (_, v) in &mut *m {
- //~^ you seem to want to iterate on a map's values
- //~| HELP use the corresponding method
- //~| HELP use the corresponding method
- //~| SUGGESTION for v in (*m).values_mut()
+
+
+
+
let _v = v;
}
let m : HashMap<u64, u64> = HashMap::new();
let rm = &m;
for (k, _value) in rm {
- //~^ you seem to want to iterate on a map's keys
- //~| HELP use the corresponding method
- //~| HELP use the corresponding method
- //~| SUGGESTION for k in rm.keys() {
+
+
+
+
let _k = k;
}
|
40 | for x in v.iter().next() {
| _____^ starting here...
-41 | | //~^ ERROR you are iterating over `Iterator::next()` which is an Option
+41 | |
42 | | println!("{}", x);
43 | | }
| |_____^ ...ending here
|
99 | for i in 0..vec.len() {
| _____^ starting here...
-100 | | //~^ ERROR `i` is only used to index `vec`
-101 | | //~| HELP consider
-102 | | //~| HELP consider
-103 | | //~| SUGGESTION for <item> in &vec {
+100 | |
+101 | |
+102 | |
+103 | |
104 | | println!("{}", vec[i]);
105 | | }
| |_____^ ...ending here
|
120 | for j in 0..4 {
| _____^ starting here...
-121 | | //~^ ERROR `j` is only used to index `STATIC`
-122 | | //~| HELP consider
-123 | | //~| HELP consider
-124 | | //~| SUGGESTION for <item> in STATIC.iter().take(4) {
+121 | |
+122 | |
+123 | |
+124 | |
125 | | println!("{:?}", STATIC[j]);
126 | | }
| |_____^ ...ending here
|
128 | for j in 0..4 {
| _____^ starting here...
-129 | | //~^ ERROR `j` is only used to index `CONST`
-130 | | //~| HELP consider
-131 | | //~| HELP consider
-132 | | //~| SUGGESTION for <item> in CONST.iter().take(4) {
+129 | |
+130 | |
+131 | |
+132 | |
133 | | println!("{:?}", CONST[j]);
134 | | }
| |_____^ ...ending here
|
136 | for i in 0..vec.len() {
| _____^ starting here...
-137 | | //~^ ERROR `i` is used to index `vec`
-138 | | //~| HELP consider
-139 | | //~| HELP consider
-140 | | //~| SUGGESTION for (i, <item>) in vec.iter().enumerate() {
+137 | |
+138 | |
+139 | |
+140 | |
141 | | println!("{} {}", vec[i], i);
142 | | }
| |_____^ ...ending here
|
147 | for i in 0..vec.len() {
| _____^ starting here...
-148 | | //~^ ERROR `i` is only used to index `vec2`
-149 | | //~| HELP consider
-150 | | //~| HELP consider
-151 | | //~| SUGGESTION for <item> in vec2.iter().take(vec.len()) {
+148 | |
+149 | |
+150 | |
+151 | |
152 | | println!("{}", vec2[i]);
153 | | }
| |_____^ ...ending here
|
155 | for i in 5..vec.len() {
| _____^ starting here...
-156 | | //~^ ERROR `i` is only used to index `vec`
-157 | | //~| HELP consider
-158 | | //~| HELP consider
-159 | | //~| SUGGESTION for <item> in vec.iter().skip(5) {
+156 | |
+157 | |
+158 | |
+159 | |
160 | | println!("{}", vec[i]);
161 | | }
| |_____^ ...ending here
|
163 | for i in 0..MAX_LEN {
| _____^ starting here...
-164 | | //~^ ERROR `i` is only used to index `vec`
-165 | | //~| HELP consider
-166 | | //~| HELP consider
-167 | | //~| SUGGESTION for <item> in vec.iter().take(MAX_LEN) {
+164 | |
+165 | |
+166 | |
+167 | |
168 | | println!("{}", vec[i]);
169 | | }
| |_____^ ...ending here
|
171 | for i in 0...MAX_LEN {
| _____^ starting here...
-172 | | //~^ ERROR `i` is only used to index `vec`
-173 | | //~| HELP consider
-174 | | //~| HELP consider
-175 | | //~| SUGGESTION for <item> in vec.iter().take(MAX_LEN + 1) {
+172 | |
+173 | |
+174 | |
+175 | |
176 | | println!("{}", vec[i]);
177 | | }
| |_____^ ...ending here
|
179 | for i in 5..10 {
| _____^ starting here...
-180 | | //~^ ERROR `i` is only used to index `vec`
-181 | | //~| HELP consider
-182 | | //~| HELP consider
-183 | | //~| SUGGESTION for <item> in vec.iter().take(10).skip(5) {
+180 | |
+181 | |
+182 | |
+183 | |
184 | | println!("{}", vec[i]);
185 | | }
| |_____^ ...ending here
|
187 | for i in 5...10 {
| _____^ starting here...
-188 | | //~^ ERROR `i` is only used to index `vec`
-189 | | //~| HELP consider
-190 | | //~| HELP consider
-191 | | //~| SUGGESTION for <item> in vec.iter().take(10 + 1).skip(5) {
+188 | |
+189 | |
+190 | |
+191 | |
192 | | println!("{}", vec[i]);
193 | | }
| |_____^ ...ending here
|
195 | for i in 5..vec.len() {
| _____^ starting here...
-196 | | //~^ ERROR `i` is used to index `vec`
-197 | | //~| HELP consider
-198 | | //~| HELP consider
-199 | | //~| SUGGESTION for (i, <item>) in vec.iter().enumerate().skip(5) {
+196 | |
+197 | |
+198 | |
+199 | |
200 | | println!("{} {}", vec[i], i);
201 | | }
| |_____^ ...ending here
|
203 | for i in 5..10 {
| _____^ starting here...
-204 | | //~^ ERROR `i` is used to index `vec`
-205 | | //~| HELP consider
-206 | | //~| HELP consider
-207 | | //~| SUGGESTION for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
+204 | |
+205 | |
+206 | |
+207 | |
208 | | println!("{} {}", vec[i], i);
209 | | }
| |_____^ ...ending here
|
211 | for i in 10..0 {
| _____^ starting here...
-212 | | //~^ERROR this range is empty so this for loop will never run
-213 | | //~|HELP consider
-214 | | //~|SUGGESTION (0..10).rev()
+212 | |
+213 | |
+214 | |
215 | | println!("{}", i);
216 | | }
| |_____^ ...ending here
|
218 | for i in 10...0 {
| _____^ starting here...
-219 | | //~^ERROR this range is empty so this for loop will never run
-220 | | //~|HELP consider
-221 | | //~|SUGGESTION (0...10).rev()
+219 | |
+220 | |
+221 | |
222 | | println!("{}", i);
223 | | }
| |_____^ ...ending here
error: this range is empty so this for loop will never run
--> $DIR/for_loop.rs:225:5
|
-225 | for i in MAX_LEN..0 { //~ERROR this range is empty so this for loop will never run
+225 | for i in MAX_LEN..0 {
| _____^ starting here...
-226 | | //~|HELP consider
-227 | | //~|SUGGESTION (0..MAX_LEN).rev()
+226 | |
+227 | |
228 | | println!("{}", i);
229 | | }
| |_____^ ...ending here
|
help: consider using the following if you are attempting to iterate over this range in reverse
- | for i in (0..MAX_LEN).rev() { //~ERROR this range is empty so this for loop will never run
+ | for i in (0..MAX_LEN).rev() {
error: this range is empty so this for loop will never run
--> $DIR/for_loop.rs:231:5
|
-231 | for i in 5..5 { //~ERROR this range is empty so this for loop will never run
+231 | for i in 5..5 {
| _____^ starting here...
232 | | println!("{}", i);
233 | | }
|
252 | for i in 10..5+4 {
| _____^ starting here...
-253 | | //~^ ERROR this range is empty so this for loop will never run
-254 | | //~| HELP if you are attempting to iterate over this range in reverse
-255 | | //~| SUGGESTION for i in (5+4..10).rev() {
+253 | |
+254 | |
+255 | |
256 | | println!("{}", i);
257 | | }
| |_____^ ...ending here
|
259 | for i in (5+2)..(3-1) {
| _____^ starting here...
-260 | | //~^ ERROR this range is empty so this for loop will never run
-261 | | //~| HELP if you are attempting to iterate over this range in reverse
-262 | | //~| SUGGESTION for i in ((3-1)..(5+2)).rev() {
+260 | |
+261 | |
+262 | |
263 | | println!("{}", i);
264 | | }
| |_____^ ...ending here
error: this range is empty so this for loop will never run
--> $DIR/for_loop.rs:266:5
|
-266 | for i in (5+2)..(8-1) { //~ERROR this range is empty so this for loop will never run
+266 | for i in (5+2)..(8-1) {
| _____^ starting here...
267 | | println!("{}", i);
268 | | }
error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
--> $DIR/for_loop.rs:365:5
|
-365 | for _v in vec.iter().next() { } //~ERROR you are iterating over `Iterator::next()`
+365 | for _v in vec.iter().next() { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: you are collect()ing an iterator and throwing away the result. Consider using an explicit for loop to exhaust the iterator
--> $DIR/for_loop.rs:372:5
|
-372 | vec.iter().map(|x| out.push(x)).collect::<Vec<_>>(); //~ERROR you are collect()ing an iterator
+372 | vec.iter().map(|x| out.push(x)).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators
--> $DIR/for_loop.rs:377:5
|
-377 | for _v in &vec { _index += 1 } //~ERROR the variable `_index` is used as a loop counter
+377 | for _v in &vec { _index += 1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators
--> $DIR/for_loop.rs:381:5
|
-381 | for _v in &vec { _index += 1 } //~ERROR the variable `_index` is used as a loop counter
+381 | for _v in &vec { _index += 1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: you seem to want to iterate on a map's values
|
441 | for (_, v) in &m {
| _____^ starting here...
-442 | | //~^ you seem to want to iterate on a map's values
-443 | | //~| HELP use the corresponding method
-444 | | //~| HELP use the corresponding method
-445 | | //~| SUGGESTION for v in m.values() {
+442 | |
+443 | |
+444 | |
+445 | |
446 | | let _v = v;
447 | | }
| |_____^ ...ending here
|
450 | for (_, v) in &*m {
| _____^ starting here...
-451 | | //~^ you seem to want to iterate on a map's values
-452 | | //~| HELP use the corresponding method
-453 | | //~| HELP use the corresponding method
-454 | | //~| SUGGESTION for v in (*m).values() {
+451 | |
+452 | |
+453 | |
+454 | |
455 | | let _v = v;
456 | | // Here the `*` is not actually necesarry, but the test tests that we don't suggest
457 | | // `in *m.values()` as we used to
|
461 | for (_, v) in &mut m {
| _____^ starting here...
-462 | | //~^ you seem to want to iterate on a map's values
-463 | | //~| HELP use the corresponding method
-464 | | //~| HELP use the corresponding method
-465 | | //~| SUGGESTION for v in m.values_mut()
+462 | |
+463 | |
+464 | |
+465 | |
466 | | let _v = v;
467 | | }
| |_____^ ...ending here
|
470 | for (_, v) in &mut *m {
| _____^ starting here...
-471 | | //~^ you seem to want to iterate on a map's values
-472 | | //~| HELP use the corresponding method
-473 | | //~| HELP use the corresponding method
-474 | | //~| SUGGESTION for v in (*m).values_mut()
+471 | |
+472 | |
+473 | |
+474 | |
475 | | let _v = v;
476 | | }
| |_____^ ...ending here
|
480 | for (k, _value) in rm {
| _____^ starting here...
-481 | | //~^ you seem to want to iterate on a map's keys
-482 | | //~| HELP use the corresponding method
-483 | | //~| HELP use the corresponding method
-484 | | //~| SUGGESTION for k in rm.keys() {
+481 | |
+482 | |
+483 | |
+484 | |
485 | | let _k = k;
486 | | }
| |_____^ ...ending here
#![deny(useless_format)]
fn main() {
- format!("foo"); //~ERROR useless use of `format!`
+ format!("foo");
- format!("{}", "foo"); //~ERROR useless use of `format!`
+ format!("{}", "foo");
format!("{:?}", "foo"); // we only want to warn about `{}`
format!("{:+}", "foo"); // we only want to warn about `{}`
format!("foo {}", "bar");
format!("{} bar", "foo");
let arg: String = "".to_owned();
- format!("{}", arg); //~ERROR useless use of `format!`
+ format!("{}", arg);
format!("{:?}", arg); // we only want to warn about `{}`
format!("{:+}", arg); // we only want to warn about `{}`
format!("foo {}", arg);
error: useless use of `format!`
--> $DIR/format.rs:6:5
|
-6 | format!("foo"); //~ERROR useless use of `format!`
+6 | format!("foo");
| ^^^^^^^^^^^^^^^
|
note: lint level defined here
error: useless use of `format!`
--> $DIR/format.rs:8:5
|
-8 | format!("{}", "foo"); //~ERROR useless use of `format!`
+8 | format!("{}", "foo");
| ^^^^^^^^^^^^^^^^^^^^^
error: useless use of `format!`
--> $DIR/format.rs:15:5
|
-15 | format!("{}", arg); //~ERROR useless use of `format!`
+15 | format!("{}", arg);
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors
// weird `else if` formatting:
if foo() {
} if foo() {
- //~^ ERROR this looks like an `else if` but the `else` is missing
- //~| NOTE add the missing `else` or
+
+
}
let _ = { // if as the last expression
if foo() {
} if foo() {
- //~^ ERROR this looks like an `else if` but the `else` is missing
- //~| NOTE add the missing `else` or
+
+
}
else {
}
let _ = { // if in the middle of a block
if foo() {
} if foo() {
- //~^ ERROR this looks like an `else if` but the `else` is missing
- //~| NOTE add the missing `else` or
+
+
}
else {
}
if foo() {
} else
- //~^ ERROR this is an `else if` but the formatting might hide it
- //~| NOTE remove the `else` or
+
+
if foo() { // the span of the above error should continue here
}
if foo() {
}
- //~^ ERROR this is an `else if` but the formatting might hide it
- //~| NOTE remove the `else` or
+
+
else
if foo() { // the span of the above error should continue here
}
// weird op_eq formatting:
let mut a = 42;
a =- 35;
- //~^ ERROR this looks like you are trying to use `.. -= ..`, but you really are doing `.. = (- ..)`
- //~| NOTE to remove this lint, use either `-=` or `= -`
+
+
a =* &191;
- //~^ ERROR this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)`
- //~| NOTE to remove this lint, use either `*=` or `= *`
+
+
let mut b = true;
b =! false;
- //~^ ERROR this looks like you are trying to use `.. != ..`, but you really are doing `.. = (! ..)`
- //~| NOTE to remove this lint, use either `!=` or `= !`
+
+
// those are ok:
a = -35;
// possible missing comma in an array
let _ = &[
-1, -2, -3 // <= no coma here
- //~^ ERROR possibly missing a comma here
- //~| NOTE to remove this lint, add a comma or write the expr in a single line
+
+
-4, -5, -6
];
let _ = &[
-1, -2, -3 // <= no coma here
- //~^ ERROR possibly missing a comma here
- //~| NOTE to remove this lint, add a comma or write the expr in a single line
+
+
*4, -5, -6
];
|
45 | } else
| ______^ starting here...
-46 | | //~^ ERROR this is an `else if` but the formatting might hide it
-47 | | //~| NOTE remove the `else` or
+46 | |
+47 | |
48 | | if foo() { // the span of the above error should continue here
| |____^ ...ending here
|
|
52 | }
| ______^ starting here...
-53 | | //~^ ERROR this is an `else if` but the formatting might hide it
-54 | | //~| NOTE remove the `else` or
+53 | |
+54 | |
55 | | else
56 | | if foo() { // the span of the above error should continue here
| |____^ ...ending here
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: ()) {
- //~^ ERROR: this function has too many arguments (8/7)
+
}
// don't lint extern fns
pub trait Foo {
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: ());
- //~^ ERROR: this function has too many arguments (8/7)
+
fn ptr(p: *const u8);
}
impl Bar {
fn good_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
- //~^ ERROR: this function has too many arguments (8/7)
+
}
// ok, we don’t want to warn implementations
fn ptr(p: *const u8) {
println!("{}", unsafe { *p });
- //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
+
println!("{:?}", unsafe { p.as_ref() });
- //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
+
unsafe { std::ptr::read(p) };
- //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
+
}
}
pub fn public(p: *const u8) {
println!("{}", unsafe { *p });
- //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
+
println!("{:?}", unsafe { p.as_ref() });
- //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
+
unsafe { std::ptr::read(p) };
- //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
+
}
impl Bar {
pub fn public(self, p: *const u8) {
println!("{}", unsafe { *p });
- //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
+
println!("{:?}", unsafe { p.as_ref() });
- //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
+
unsafe { std::ptr::read(p) };
- //~^ ERROR: this public function dereferences a raw pointer but is not marked `unsafe`
+
}
pub fn public_ok(self, p: *const u8) {
|
11 | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {
| _^ starting here...
-12 | | //~^ ERROR: this function has too many arguments (8/7)
+12 | |
13 | | }
| |_^ ...ending here
|
fn main() {
let x = 0;
- x + 0; //~ERROR the operation is ineffective
- x + (1 - 1); //~ERROR the operation is ineffective
+ x + 0;
+ x + (1 - 1);
x + 1;
- 0 + x; //~ERROR the operation is ineffective
+ 0 + x;
1 + x;
x - ZERO; //no error, as we skip lookups (for now)
- x | (0); //~ERROR the operation is ineffective
+ x | (0);
((ZERO)) | x; //no error, as we skip lookups (for now)
- x * 1; //~ERROR the operation is ineffective
- 1 * x; //~ERROR the operation is ineffective
+ x * 1;
+ 1 * x;
x / ONE; //no error, as we skip lookups (for now)
x / 2; //no false positive
x & NEG_ONE; //no error, as we skip lookups (for now)
- -1 & x; //~ERROR the operation is ineffective
+ -1 & x;
}
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:13:5
|
-13 | x + 0; //~ERROR the operation is ineffective
+13 | x + 0;
| ^^^^^
|
note: lint level defined here
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:14:5
|
-14 | x + (1 - 1); //~ERROR the operation is ineffective
+14 | x + (1 - 1);
| ^^^^^^^^^^^
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:16:5
|
-16 | 0 + x; //~ERROR the operation is ineffective
+16 | 0 + x;
| ^^^^^
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:19:5
|
-19 | x | (0); //~ERROR the operation is ineffective
+19 | x | (0);
| ^^^^^^^
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:22:5
|
-22 | x * 1; //~ERROR the operation is ineffective
+22 | x * 1;
| ^^^^^
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:23:5
|
-23 | 1 * x; //~ERROR the operation is ineffective
+23 | 1 * x;
| ^^^^^
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:29:5
|
-29 | -1 & x; //~ERROR the operation is ineffective
+29 | -1 & x;
| ^^^^^^
error: aborting due to 7 previous errors
fn main() {
if let Ok(_) = Ok::<i32, i32>(42) {}
- //~^ERROR redundant pattern matching, consider using `is_ok()`
- //~| HELP try this
- //~| SUGGESTION if Ok::<i32, i32>(42).is_ok() {
+
+
+
if let Err(_) = Err::<i32, i32>(42) {
- //~^ERROR redundant pattern matching, consider using `is_err()`
- //~| HELP try this
- //~| SUGGESTION if Err::<i32, i32>(42).is_err() {
+
+
+
}
if let None = None::<()> {
- //~^ERROR redundant pattern matching, consider using `is_none()`
- //~| HELP try this
- //~| SUGGESTION if None::<()>.is_none() {
+
+
+
}
if let Some(_) = Some(42) {
- //~^ERROR redundant pattern matching, consider using `is_some()`
- //~| HELP try this
- //~| SUGGESTION if Some(42).is_some() {
+
+
+
}
if Ok::<i32, i32>(42).is_ok() {
fn bla() -> bool { unimplemented!() }
fn main() {
- if !bla() { //~ ERROR: Unnecessary boolean `not` operation
+ if !bla() {
println!("Bugs");
} else {
println!("Bunny");
}
- if 4 != 5 { //~ ERROR: Unnecessary `!=` operation
+ if 4 != 5 {
println!("Bugs");
} else {
println!("Bunny");
error: Unnecessary boolean `not` operation
--> $DIR/if_not_else.rs:9:5
|
-9 | if !bla() { //~ ERROR: Unnecessary boolean `not` operation
+9 | if !bla() {
| _____^ starting here...
10 | | println!("Bugs");
11 | | } else {
error: Unnecessary `!=` operation
--> $DIR/if_not_else.rs:14:5
|
-14 | if 4 != 5 { //~ ERROR: Unnecessary `!=` operation
+14 | if 4 != 5 {
| _____^ starting here...
15 | | println!("Bugs");
16 | | } else {
let zero: u32 = 0;
let u8_max: u8 = 255;
- (u8_max as u32) > 300; //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false
+ (u8_max as u32) > 300;
(u8_max as u32) > 20;
- (zero as i32) < -5; //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false
+ (zero as i32) < -5;
(zero as i32) < 10;
- -5 < (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always true
- 0 <= (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always true
+ -5 < (zero as i32);
+ 0 <= (zero as i32);
0 < (zero as i32);
- -5 > (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false
- -5 >= (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false
- 1337 == (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false
+ -5 > (zero as i32);
+ -5 >= (u8_max as i32);
+ 1337 == (u8_max as i32);
- -5 == (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false
- -5 != (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always true
+ -5 == (zero as i32);
+ -5 != (u8_max as i32);
// Those are Ok:
42 == (u8_max as i32);
error: because of the numeric bounds on `u8_max` prior to casting, this expression is always false
--> $DIR/invalid_upcast_comparisons.rs:10:5
|
-10 | (u8_max as u32) > 300; //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false
+10 | (u8_max as u32) > 300;
| ^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: because of the numeric bounds on `zero` prior to casting, this expression is always false
--> $DIR/invalid_upcast_comparisons.rs:13:5
|
-13 | (zero as i32) < -5; //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false
+13 | (zero as i32) < -5;
| ^^^^^^^^^^^^^^^^^^
error: because of the numeric bounds on `zero` prior to casting, this expression is always true
--> $DIR/invalid_upcast_comparisons.rs:16:5
|
-16 | -5 < (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always true
+16 | -5 < (zero as i32);
| ^^^^^^^^^^^^^^^^^^
error: because of the numeric bounds on `zero` prior to casting, this expression is always true
--> $DIR/invalid_upcast_comparisons.rs:17:5
|
-17 | 0 <= (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always true
+17 | 0 <= (zero as i32);
| ^^^^^^^^^^^^^^^^^^
error: because of the numeric bounds on `zero` prior to casting, this expression is always false
--> $DIR/invalid_upcast_comparisons.rs:20:5
|
-20 | -5 > (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false
+20 | -5 > (zero as i32);
| ^^^^^^^^^^^^^^^^^^
error: because of the numeric bounds on `u8_max` prior to casting, this expression is always false
--> $DIR/invalid_upcast_comparisons.rs:21:5
|
-21 | -5 >= (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false
+21 | -5 >= (u8_max as i32);
| ^^^^^^^^^^^^^^^^^^^^^
error: because of the numeric bounds on `u8_max` prior to casting, this expression is always false
--> $DIR/invalid_upcast_comparisons.rs:22:5
|
-22 | 1337 == (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false
+22 | 1337 == (u8_max as i32);
| ^^^^^^^^^^^^^^^^^^^^^^^
error: because of the numeric bounds on `zero` prior to casting, this expression is always false
--> $DIR/invalid_upcast_comparisons.rs:24:5
|
-24 | -5 == (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false
+24 | -5 == (zero as i32);
| ^^^^^^^^^^^^^^^^^^^
error: because of the numeric bounds on `u8_max` prior to casting, this expression is always true
--> $DIR/invalid_upcast_comparisons.rs:25:5
|
-25 | -5 != (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always true
+25 | -5 != (u8_max as i32);
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 9 previous errors
fn last() {
foo();
- fn foo() { println!("foo"); } //~ ERROR adding items after statements is confusing
+ fn foo() { println!("foo"); }
}
fn main() {
foo();
- fn foo() { println!("foo"); } //~ ERROR adding items after statements is confusing
+ fn foo() { println!("foo"); }
foo();
}
error: adding items after statements is confusing, since items exist from the start of the scope
--> $DIR/item_after_statement.rs:12:5
|
-12 | fn foo() { println!("foo"); } //~ ERROR adding items after statements is confusing
+12 | fn foo() { println!("foo"); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: adding items after statements is confusing, since items exist from the start of the scope
--> $DIR/item_after_statement.rs:17:5
|
-17 | fn foo() { println!("foo"); } //~ ERROR adding items after statements is confusing
+17 | fn foo() { println!("foo"); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
enum LargeEnum {
A(i32),
- B([i32; 8000]), //~ ERROR large enum variant found
- //~^ HELP consider boxing the large fields to reduce the total size of the enum
- //~| SUGGESTION Box<[i32; 8000]>
+ B([i32; 8000]),
+
+
}
enum GenericEnum<T> {
A(i32),
- B([i32; 8000]), //~ ERROR large enum variant found
- //~^ HELP consider boxing the large fields to reduce the total size of the enum
- //~| SUGGESTION Box<[i32; 8000]>
+ B([i32; 8000]),
+
+
C([T; 8000]),
- D(T, [i32; 8000]), //~ ERROR large enum variant found
- //~^ HELP consider boxing the large fields to reduce the total size of the enum
+ D(T, [i32; 8000]),
+
}
trait SomeTrait {
enum AnotherLargeEnum {
VariantOk(i32, u32),
- ContainingLargeEnum(LargeEnum), //~ ERROR large enum variant found
- //~^ HELP consider boxing the large fields to reduce the total size of the enum
- //~| SUGGESTION Box<LargeEnum>
- ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), //~ ERROR large enum variant found
- //~^ HELP consider boxing the large fields to reduce the total size of the enum
+ ContainingLargeEnum(LargeEnum),
+
+
+ ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]),
+
VoidVariant,
StructLikeLittle { x: i32, y: i32 },
- StructLikeLarge { x: [i32; 8000], y: i32 }, //~ ERROR large enum variant found
- //~^ HELP consider boxing the large fields to reduce the total size of the enum
- StructLikeLarge2 { //~ ERROR large enum variant found
+ StructLikeLarge { x: [i32; 8000], y: i32 },
+
+ StructLikeLarge2 {
x:
- [i32; 8000] //~ SUGGESTION Box<[i32; 8000]>
- //~^ HELP consider boxing the large fields to reduce the total size of the enum
+ [i32; 8000]
+
},
}
error: large enum variant found
--> $DIR/large_enum_variant.rs:10:5
|
-10 | B([i32; 8000]), //~ ERROR large enum variant found
+10 | B([i32; 8000]),
| ^^^^^^^^^^^^^^
|
note: lint level defined here
6 | #![deny(large_enum_variant)]
| ^^^^^^^^^^^^^^^^^^
help: consider boxing the large fields to reduce the total size of the enum
- | B(Box<[i32; 8000]>), //~ ERROR large enum variant found
+ | B(Box<[i32; 8000]>),
error: large enum variant found
--> $DIR/large_enum_variant.rs:17:5
|
-17 | B([i32; 8000]), //~ ERROR large enum variant found
+17 | B([i32; 8000]),
| ^^^^^^^^^^^^^^
|
help: consider boxing the large fields to reduce the total size of the enum
- | B(Box<[i32; 8000]>), //~ ERROR large enum variant found
+ | B(Box<[i32; 8000]>),
error: large enum variant found
--> $DIR/large_enum_variant.rs:21:5
|
-21 | D(T, [i32; 8000]), //~ ERROR large enum variant found
+21 | D(T, [i32; 8000]),
| ^^^^^^^^^^^^^^^^^
|
help: consider boxing the large fields to reduce the total size of the enum
--> $DIR/large_enum_variant.rs:21:5
|
-21 | D(T, [i32; 8000]), //~ ERROR large enum variant found
+21 | D(T, [i32; 8000]),
| ^^^^^^^^^^^^^^^^^
error: large enum variant found
--> $DIR/large_enum_variant.rs:35:5
|
-35 | ContainingLargeEnum(LargeEnum), //~ ERROR large enum variant found
+35 | ContainingLargeEnum(LargeEnum),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider boxing the large fields to reduce the total size of the enum
- | ContainingLargeEnum(Box<LargeEnum>), //~ ERROR large enum variant found
+ | ContainingLargeEnum(Box<LargeEnum>),
error: large enum variant found
--> $DIR/large_enum_variant.rs:38:5
|
-38 | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), //~ ERROR large enum variant found
+38 | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider boxing the large fields to reduce the total size of the enum
--> $DIR/large_enum_variant.rs:38:5
|
-38 | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), //~ ERROR large enum variant found
+38 | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: large enum variant found
--> $DIR/large_enum_variant.rs:42:5
|
-42 | StructLikeLarge { x: [i32; 8000], y: i32 }, //~ ERROR large enum variant found
+42 | StructLikeLarge { x: [i32; 8000], y: i32 },
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider boxing the large fields to reduce the total size of the enum
--> $DIR/large_enum_variant.rs:42:5
|
-42 | StructLikeLarge { x: [i32; 8000], y: i32 }, //~ ERROR large enum variant found
+42 | StructLikeLarge { x: [i32; 8000], y: i32 },
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: large enum variant found
--> $DIR/large_enum_variant.rs:44:5
|
-44 | StructLikeLarge2 { //~ ERROR large enum variant found
+44 | StructLikeLarge2 {
| _____^ starting here...
45 | | x:
-46 | | [i32; 8000] //~ SUGGESTION Box<[i32; 8000]>
-47 | | //~^ HELP consider boxing the large fields to reduce the total size of the enum
+46 | | [i32; 8000]
+47 | |
48 | | },
| |_____^ ...ending here
|
help: consider boxing the large fields to reduce the total size of the enum
- | Box<[i32; 8000]> //~ SUGGESTION Box<[i32; 8000]>
+ | Box<[i32; 8000]>
error: aborting due to 7 previous errors
pub struct PubOne;
impl PubOne {
- pub fn len(self: &Self) -> isize { //~ERROR item `PubOne` has a public `len` method but no corresponding `is_empty`
+ pub fn len(self: &Self) -> isize {
1
}
}
}
pub trait PubTraitsToo {
- fn len(self: &Self) -> isize; //~ERROR trait `PubTraitsToo` has a `len` method but no `is_empty`
+ fn len(self: &Self) -> isize;
}
impl PubTraitsToo for One {
pub struct HasIsEmpty;
impl HasIsEmpty {
- pub fn len(self: &Self) -> isize { //~ERROR item `HasIsEmpty` has a public `len` method but a private `is_empty`
+ pub fn len(self: &Self) -> isize {
1
}
pub struct HasWrongIsEmpty;
impl HasWrongIsEmpty {
- pub fn len(self: &Self) -> isize { //~ERROR item `HasWrongIsEmpty` has a public `len` method but no corresponding `is_empty`
+ pub fn len(self: &Self) -> isize {
1
}
fn main() {
let x = [1, 2];
if x.len() == 0 {
- //~^ERROR length comparison to zero
- //~|HELP consider using `is_empty`
- //~|SUGGESTION x.is_empty()
+
+
+
println!("This should not happen!");
}
if "".len() == 0 {
- //~^ERROR length comparison to zero
- //~|HELP consider using `is_empty`
- //~|SUGGESTION "".is_empty()
+
+
+
}
let y = One;
let has_is_empty = HasIsEmpty;
if has_is_empty.len() == 0 {
- //~^ERROR length comparison to zero
- //~|HELP consider using `is_empty`
- //~|SUGGESTION has_is_empty.is_empty()
+
+
+
println!("Or this!");
}
if has_is_empty.len() != 0 {
- //~^ERROR length comparison to zero
- //~|HELP consider using `is_empty`
- //~|SUGGESTION !has_is_empty.is_empty()
+
+
+
println!("Or this!");
}
if has_is_empty.len() > 0 {
- //~^ERROR length comparison to zero
- //~|HELP consider using `is_empty`
- //~|SUGGESTION !has_is_empty.is_empty()
+
+
+
println!("Or this!");
}
assert!(!has_is_empty.is_empty());
let with_is_empty: &WithIsEmpty = &Wither;
if with_is_empty.len() == 0 {
- //~^ERROR length comparison to zero
- //~|HELP consider using `is_empty`
- //~|SUGGESTION with_is_empty.is_empty()
+
+
+
println!("Or this!");
}
assert!(!with_is_empty.is_empty());
error: item `PubOne` has a public `len` method but no corresponding `is_empty` method
--> $DIR/len_zero.rs:10:5
|
-10 | pub fn len(self: &Self) -> isize { //~ERROR item `PubOne` has a public `len` method but no corresponding `is_empty`
+10 | pub fn len(self: &Self) -> isize {
| _____^ starting here...
11 | | 1
12 | | }
error: trait `PubTraitsToo` has a `len` method but no `is_empty` method
--> $DIR/len_zero.rs:32:5
|
-32 | fn len(self: &Self) -> isize; //~ERROR trait `PubTraitsToo` has a `len` method but no `is_empty`
+32 | fn len(self: &Self) -> isize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: item `HasIsEmpty` has a public `len` method but a private `is_empty` method
--> $DIR/len_zero.rs:66:5
|
-66 | pub fn len(self: &Self) -> isize { //~ERROR item `HasIsEmpty` has a public `len` method but a private `is_empty`
+66 | pub fn len(self: &Self) -> isize {
| _____^ starting here...
67 | | 1
68 | | }
error: item `HasWrongIsEmpty` has a public `len` method but no corresponding `is_empty` method
--> $DIR/len_zero.rs:95:5
|
-95 | pub fn len(self: &Self) -> isize { //~ERROR item `HasWrongIsEmpty` has a public `len` method but no corresponding `is_empty`
+95 | pub fn len(self: &Self) -> isize {
| _____^ starting here...
96 | | 1
97 | | }
issue985_alt();
let mut foo = 0;
- //~^ ERROR `if _ { .. } else { .. }` is an expression
- //~| HELP more idiomatic
- //~| SUGGESTION let <mut> foo = if f() { 42 } else { 0 };
+
+
+
if f() {
foo = 42;
}
let mut bar = 0;
- //~^ ERROR `if _ { .. } else { .. }` is an expression
- //~| HELP more idiomatic
- //~| SUGGESTION let <mut> bar = if f() { ..; 42 } else { ..; 0 };
+
+
+
if f() {
f();
bar = 42;
}
let quz;
- //~^ ERROR `if _ { .. } else { .. }` is an expression
- //~| HELP more idiomatic
- //~| SUGGESTION let quz = if f() { 42 } else { 0 };
+
+
+
if f() {
quz = 42;
// baz needs to be mut
let mut baz = 0;
- //~^ ERROR `if _ { .. } else { .. }` is an expression
- //~| HELP more idiomatic
- //~| SUGGESTION let <mut> baz = if f() { 42 } else { 0 };
+
+
+
if f() {
baz = 42;
}
|
57 | let mut foo = 0;
| _____^ starting here...
-58 | | //~^ ERROR `if _ { .. } else { .. }` is an expression
-59 | | //~| HELP more idiomatic
-60 | | //~| SUGGESTION let <mut> foo = if f() { 42 } else { 0 };
+58 | |
+59 | |
+60 | |
61 | | if f() {
62 | | foo = 42;
63 | | }
|
111 | let mut baz = 0;
| _____^ starting here...
-112 | | //~^ ERROR `if _ { .. } else { .. }` is an expression
-113 | | //~| HELP more idiomatic
-114 | | //~| SUGGESTION let <mut> baz = if f() { 42 } else { 0 };
+112 | |
+113 | |
+114 | |
115 | | if f() {
116 | | baz = 42;
117 | | }
fn test() -> i32 {
let _y = 0; // no warning
- let x = 5; //~NOTE this expression can be directly returned
- x //~ERROR returning the result of a let binding
+ let x = 5;
+ x
}
fn test_inner() -> i32 {
if true {
- let x = 5; //~NOTE this expression can be directly returned
- x //~ERROR returning the result of a let binding
+ let x = 5;
+ x
} else {
0
}
error: returning the result of a let binding from a block. Consider returning the expression directly.
--> $DIR/let_return.rs:10:5
|
-10 | x //~ERROR returning the result of a let binding
+10 | x
| ^
|
note: lint level defined here
note: this expression can be directly returned
--> $DIR/let_return.rs:9:13
|
-9 | let x = 5; //~NOTE this expression can be directly returned
+9 | let x = 5;
| ^
error: returning the result of a let binding from a block. Consider returning the expression directly.
--> $DIR/let_return.rs:16:9
|
-16 | x //~ERROR returning the result of a let binding
+16 | x
| ^
|
note: this expression can be directly returned
--> $DIR/let_return.rs:15:17
|
-15 | let x = 5; //~NOTE this expression can be directly returned
+15 | let x = 5;
| ^
error: aborting due to 2 previous errors
}
fn main() {
- let _x = println!("x"); //~ERROR this let-binding has unit value
+ let _x = println!("x");
let _y = 1; // this is fine
let _z = ((), 1); // this as well
if true {
- let _a = (); //~ERROR this let-binding has unit value
+ let _a = ();
}
let_and_return!(()) // should be fine
error: this let-binding has unit value. Consider omitting `let _x =`
--> $DIR/let_unit.rs:14:5
|
-14 | let _x = println!("x"); //~ERROR this let-binding has unit value
+14 | let _x = println!("x");
| ^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: this let-binding has unit value. Consider omitting `let _a =`
--> $DIR/let_unit.rs:18:9
|
-18 | let _a = (); //~ERROR this let-binding has unit value
+18 | let _a = ();
| ^^^^^^^^^^^^
error: aborting due to 2 previous errors
#![allow(dead_code)]
fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) { }
-//~^ERROR explicit lifetimes given
+
fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) { }
-//~^ERROR explicit lifetimes given
+
fn same_lifetime_on_input<'a>(_x: &'a u8, _y: &'a u8) { } // no error, same lifetime on two params
fn mut_and_static_input(_x: &mut u8, _y: &'static str) { }
fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { x }
-//~^ERROR explicit lifetimes given
+
fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 { x } // no error, multiple input refs
fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { x.unwrap() } // no error, two input refs
fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { Ok(x) }
-//~^ERROR explicit lifetimes given
+
// where clause, but without lifetimes
fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> where T: Copy { Ok(x) }
-//~^ERROR explicit lifetimes given
+
type Ref<'r> = &'r u8;
fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) { } // no error, same lifetime on two params
fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) { }
-//~^ERROR explicit lifetimes given
+
fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) { } // no error, bounded lifetime
where F: Fn(Lt<'a, I>) -> Lt<'a, I> // no error, fn bound references 'a
{ unreachable!() }
-fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> //~ERROR explicit lifetimes given
+fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>
{ unreachable!() }
impl X {
fn self_and_out<'s>(&'s self) -> &'s u8 { &self.x }
- //~^ERROR explicit lifetimes given
+
fn self_and_in_out<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { &self.x } // no error, multiple input refs
fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) { }
- //~^ERROR explicit lifetimes given
+
fn self_and_same_in<'s>(&'s self, _x: &'s u8) { } // no error, same lifetimes on two params
}
unimplemented!()
}
-fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { unimplemented!() } //~ERROR explicit lifetimes given
+fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { unimplemented!() }
// no warning, two input lifetimes (named on the reference, anonymous on Foo)
fn struct_with_lt2<'a>(_foo: &'a Foo) -> &'a str { unimplemented!() }
// this should warn because there is no lifetime on Drop, so this would be
// unambiguous if we elided the lifetime
-fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { unimplemented!() } //~ERROR explicit lifetimes given
+fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { unimplemented!() }
type FooAlias<'a> = Foo<'a>;
-fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() } //~ERROR explicit lifetimes given
+fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() }
// no warning, two input lifetimes (named on the reference, anonymous on Foo)
fn alias_with_lt2<'a>(_foo: &'a FooAlias) -> &'a str { unimplemented!() }
// no warning, two input lifetimes
fn alias_with_lt4<'a, 'b>(_foo: &'a FooAlias<'b> ) -> &'a str { unimplemented!() }
-fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() } //~ERROR explicit lifetimes given
+fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() }
fn elided_input_named_output<'a>(_arg: &str) -> &'a str { unimplemented!() }
-fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() } //~ERROR explicit lifetimes given
+fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() }
fn trait_bound<'a, T: WithLifetime<'a>>(_: &'a u8, _: T) { unimplemented!() }
fn main() {
error: explicit lifetimes given in parameter types where they could be elided
--> $DIR/lifetimes.rs:58:1
|
-58 | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> //~ERROR explicit lifetimes given
+58 | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
| _^ starting here...
59 | | where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>
60 | | { unreachable!() }
error: explicit lifetimes given in parameter types where they could be elided
--> $DIR/lifetimes.rs:89:1
|
-89 | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { unimplemented!() } //~ERROR explicit lifetimes given
+89 | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { unimplemented!() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided
--> $DIR/lifetimes.rs:109:1
|
-109 | fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { unimplemented!() } //~ERROR explicit lifetimes given
+109 | fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { unimplemented!() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided
--> $DIR/lifetimes.rs:113:1
|
-113 | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() } //~ERROR explicit lifetimes given
+113 | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided
--> $DIR/lifetimes.rs:124:1
|
-124 | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() } //~ERROR explicit lifetimes given
+124 | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided
--> $DIR/lifetimes.rs:128:1
|
-128 | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() } //~ERROR explicit lifetimes given
+128 | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 14 previous errors
declare_lint! { GOOD_LINT, Warn, "good lint" }
declare_lint! { MISSING_LINT, Warn, "missing lint" }
-//~^ ERROR: the lint `MISSING_LINT` is not added to any `LintPass`
+
pub struct Pass;
let ok4 = 0xab_cd_i32;
let ok5 = 0xAB_CD_u32;
let ok5 = 0xAB_CD_isize;
- let fail1 = 0xabCD; //~ERROR inconsistent casing in hexadecimal literal
- let fail2 = 0xabCD_u32; //~ERROR inconsistent casing in hexadecimal literal
- let fail2 = 0xabCD_isize; //~ERROR inconsistent casing in hexadecimal literal
+ let fail1 = 0xabCD;
+ let fail2 = 0xabCD_u32;
+ let fail2 = 0xabCD_isize;
let ok6 = 1234_i32;
let ok7 = 1234_f32;
let ok8 = 1234_isize;
- let fail3 = 1234i32; //~ERROR integer type suffix should be separated
- let fail4 = 1234u32; //~ERROR integer type suffix should be separated
- let fail5 = 1234isize; //~ERROR integer type suffix should be separated
- let fail6 = 1234usize; //~ERROR integer type suffix should be separated
- let fail7 = 1.5f32; //~ERROR float type suffix should be separated
+ let fail3 = 1234i32;
+ let fail4 = 1234u32;
+ let fail5 = 1234isize;
+ let fail6 = 1234usize;
+ let fail7 = 1.5f32;
let ok9 = 0;
let ok10 = 0_i64;
let fail8 = 0123;
- //~^ERROR decimal constant
- //~|HELP remove the `0`
- //~|SUGGESTION = 123;
- //~|HELP use `0o`
- //~|SUGGESTION = 0o123;
+
+
+
+
+
let ok11 = 0o123;
let ok12 = 0b101010;
error: inconsistent casing in hexadecimal literal
--> $DIR/literals.rs:14:17
|
-14 | let fail1 = 0xabCD; //~ERROR inconsistent casing in hexadecimal literal
+14 | let fail1 = 0xabCD;
| ^^^^^^
|
note: lint level defined here
error: inconsistent casing in hexadecimal literal
--> $DIR/literals.rs:15:17
|
-15 | let fail2 = 0xabCD_u32; //~ERROR inconsistent casing in hexadecimal literal
+15 | let fail2 = 0xabCD_u32;
| ^^^^^^^^^^
error: inconsistent casing in hexadecimal literal
--> $DIR/literals.rs:16:17
|
-16 | let fail2 = 0xabCD_isize; //~ERROR inconsistent casing in hexadecimal literal
+16 | let fail2 = 0xabCD_isize;
| ^^^^^^^^^^^^
error: integer type suffix should be separated by an underscore
--> $DIR/literals.rs:21:17
|
-21 | let fail3 = 1234i32; //~ERROR integer type suffix should be separated
+21 | let fail3 = 1234i32;
| ^^^^^^^
|
note: lint level defined here
error: integer type suffix should be separated by an underscore
--> $DIR/literals.rs:22:17
|
-22 | let fail4 = 1234u32; //~ERROR integer type suffix should be separated
+22 | let fail4 = 1234u32;
| ^^^^^^^
error: integer type suffix should be separated by an underscore
--> $DIR/literals.rs:23:17
|
-23 | let fail5 = 1234isize; //~ERROR integer type suffix should be separated
+23 | let fail5 = 1234isize;
| ^^^^^^^^^
error: integer type suffix should be separated by an underscore
--> $DIR/literals.rs:24:17
|
-24 | let fail6 = 1234usize; //~ERROR integer type suffix should be separated
+24 | let fail6 = 1234usize;
| ^^^^^^^^^
error: float type suffix should be separated by an underscore
--> $DIR/literals.rs:25:17
|
-25 | let fail7 = 1.5f32; //~ERROR float type suffix should be separated
+25 | let fail7 = 1.5f32;
| ^^^^^^
error: this is a decimal constant
fn map_clone_iter() {
let x = [1,2,3];
- x.iter().map(|y| y.clone()); //~ ERROR you seem to be using .map()
- //~^ HELP try
- x.iter().map(|&y| y); //~ ERROR you seem to be using .map()
- //~^ HELP try
- x.iter().map(|y| *y); //~ ERROR you seem to be using .map()
- //~^ HELP try
- x.iter().map(|y| { y.clone() }); //~ ERROR you seem to be using .map()
- //~^ HELP try
- x.iter().map(|&y| { y }); //~ ERROR you seem to be using .map()
- //~^ HELP try
- x.iter().map(|y| { *y }); //~ ERROR you seem to be using .map()
- //~^ HELP try
- x.iter().map(Clone::clone); //~ ERROR you seem to be using .map()
- //~^ HELP try
+ x.iter().map(|y| y.clone());
+
+ x.iter().map(|&y| y);
+
+ x.iter().map(|y| *y);
+
+ x.iter().map(|y| { y.clone() });
+
+ x.iter().map(|&y| { y });
+
+ x.iter().map(|y| { *y });
+
+ x.iter().map(Clone::clone);
+
}
fn map_clone_option() {
let x = Some(4);
- x.as_ref().map(|y| y.clone()); //~ ERROR you seem to be using .map()
- //~^ HELP try
- x.as_ref().map(|&y| y); //~ ERROR you seem to be using .map()
- //~^ HELP try
- x.as_ref().map(|y| *y); //~ ERROR you seem to be using .map()
- //~^ HELP try
+ x.as_ref().map(|y| y.clone());
+
+ x.as_ref().map(|&y| y);
+
+ x.as_ref().map(|y| *y);
+
}
fn not_linted_option() {
fn map_clone_deref() {
let x = Some(UnusualDeref);
- let _: Option<UnusualDeref> = x.as_ref().map(|y| *y); //~ ERROR you seem to be using .map()
- //~^ HELP try
+ let _: Option<UnusualDeref> = x.as_ref().map(|y| *y);
+
// Not linted: using deref conversion
let _: Option<i32> = x.map(|y| *y);
error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()`
--> $DIR/map_clone.rs:12:5
|
-12 | x.iter().map(|y| y.clone()); //~ ERROR you seem to be using .map()
+12 | x.iter().map(|y| y.clone());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()`
--> $DIR/map_clone.rs:14:5
|
-14 | x.iter().map(|&y| y); //~ ERROR you seem to be using .map()
+14 | x.iter().map(|&y| y);
| ^^^^^^^^^^^^^^^^^^^^
|
= help: try
error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()`
--> $DIR/map_clone.rs:16:5
|
-16 | x.iter().map(|y| *y); //~ ERROR you seem to be using .map()
+16 | x.iter().map(|y| *y);
| ^^^^^^^^^^^^^^^^^^^^
|
= help: try
error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()`
--> $DIR/map_clone.rs:18:5
|
-18 | x.iter().map(|y| { y.clone() }); //~ ERROR you seem to be using .map()
+18 | x.iter().map(|y| { y.clone() });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try
error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()`
--> $DIR/map_clone.rs:20:5
|
-20 | x.iter().map(|&y| { y }); //~ ERROR you seem to be using .map()
+20 | x.iter().map(|&y| { y });
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try
error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()`
--> $DIR/map_clone.rs:22:5
|
-22 | x.iter().map(|y| { *y }); //~ ERROR you seem to be using .map()
+22 | x.iter().map(|y| { *y });
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try
error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()`
--> $DIR/map_clone.rs:24:5
|
-24 | x.iter().map(Clone::clone); //~ ERROR you seem to be using .map()
+24 | x.iter().map(Clone::clone);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try
error: you seem to be using .map() to clone the contents of an Option, consider using `.cloned()`
--> $DIR/map_clone.rs:30:5
|
-30 | x.as_ref().map(|y| y.clone()); //~ ERROR you seem to be using .map()
+30 | x.as_ref().map(|y| y.clone());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try
error: you seem to be using .map() to clone the contents of an Option, consider using `.cloned()`
--> $DIR/map_clone.rs:32:5
|
-32 | x.as_ref().map(|&y| y); //~ ERROR you seem to be using .map()
+32 | x.as_ref().map(|&y| y);
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: try
error: you seem to be using .map() to clone the contents of an Option, consider using `.cloned()`
--> $DIR/map_clone.rs:34:5
|
-34 | x.as_ref().map(|y| *y); //~ ERROR you seem to be using .map()
+34 | x.as_ref().map(|y| *y);
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: try
error: you seem to be using .map() to clone the contents of an Option, consider using `.cloned()`
--> $DIR/map_clone.rs:90:35
|
-90 | let _: Option<UnusualDeref> = x.as_ref().map(|y| *y); //~ ERROR you seem to be using .map()
+90 | let _: Option<UnusualDeref> = x.as_ref().map(|y| *y);
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: try
fn unwrap_addr() -> Option<&'static ExprNode> {
match ExprNode::Butterflies {
- //~^ ERROR you seem to be trying to use match
- //~| HELP try
- //~| SUGGESTION if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { let x = 5; None }
+
+
+
ExprNode::ExprAddrOf => Some(&NODE),
_ => { let x = 5; None },
}
let x = Some(1u8);
match x {
- //~^ ERROR you seem to be trying to use match
- //~| HELP try
- //~| SUGGESTION if let Some(y) = x { println!("{:?}", y); };
+
+
+
Some(y) => { println!("{:?}", y); }
_ => ()
};
let z = (1u8,1u8);
match z {
- //~^ ERROR you seem to be trying to use match
- //~| HELP try
- //~| SUGGESTION if let (2...3, 7...9) = z { dummy() };
+
+
+
(2...3, 7...9) => dummy(),
_ => {}
};
let y : Result<_, i8> = Ok(1i8);
match x {
- //~^ ERROR you seem to be trying to use match
- //~| HELP try
- //~| SUGGESTION if let Some(y) = x { dummy() };
+
+
+
Some(y) => dummy(),
None => ()
};
match y {
- //~^ ERROR you seem to be trying to use match
- //~| HELP try
- //~| SUGGESTION if let Ok(y) = y { dummy() };
+
+
+
Ok(y) => dummy(),
Err(..) => ()
};
let c = Cow::Borrowed("");
match c {
- //~^ ERROR you seem to be trying to use match
- //~| HELP try
- //~| SUGGESTION if let Cow::Borrowed(..) = c { dummy() };
+
+
+
Cow::Borrowed(..) => dummy(),
Cow::Owned(..) => (),
};
let test: bool = true;
match test {
- //~^ ERROR you seem to be trying to match on a boolean expression
- //~| HELP consider
- //~| SUGGESTION if test { 0 } else { 42 };
+
+
+
true => 0,
false => 42,
};
let option = 1;
match option == 1 {
- //~^ ERROR you seem to be trying to match on a boolean expression
- //~| HELP consider
- //~| SUGGESTION if option == 1 { 1 } else { 0 };
+
+
+
true => 1,
false => 0,
};
match test {
- //~^ ERROR you seem to be trying to match on a boolean expression
- //~| HELP consider
- //~| SUGGESTION if !test { println!("Noooo!"); };
+
+
+
true => (),
false => { println!("Noooo!"); }
};
match test {
- //~^ ERROR you seem to be trying to match on a boolean expression
- //~| HELP consider
- //~| SUGGESTION if !test { println!("Noooo!"); };
+
+
+
false => { println!("Noooo!"); }
_ => (),
};
match test && test {
- //~^ ERROR you seem to be trying to match on a boolean expression
- //~| HELP consider
- //~| SUGGESTION if !(test && test) { println!("Noooo!"); };
- //~| ERROR equal expressions as operands
+
+
+
+
false => { println!("Noooo!"); }
_ => (),
};
match test {
- //~^ ERROR you seem to be trying to match on a boolean expression
- //~| HELP consider
- //~| SUGGESTION if test { println!("Yes!"); } else { println!("Noooo!"); };
+
+
+
false => { println!("Noooo!"); }
true => { println!("Yes!"); }
};
{
let v = &Some(0);
match v {
- //~^ERROR add `&` to all patterns
- //~|HELP instead of
- //~|SUGGESTION match *v { .. }
+
+
+
&Some(v) => println!("{:?}", v),
&None => println!("none"),
}
}
let tup =& (1, 2);
match tup {
- //~^ERROR add `&` to all patterns
- //~|HELP instead of
- //~|SUGGESTION match *tup { .. }
+
+
+
&(v, 1) => println!("{}", v),
_ => println!("none"),
}
// special case: using & both in expr and pats
let w = Some(0);
match &w {
- //~^ERROR add `&` to both
- //~|HELP try
- //~|SUGGESTION match w { .. }
+
+
+
&Some(v) => println!("{:?}", v),
&None => println!("none"),
}
let a = &Some(0);
if let &None = a {
- //~^ERROR add `&` to all patterns
- //~|HELP instead of
- //~|SUGGESTION if let .. = *a { .. }
+
+
+
println!("none");
}
let b = Some(0);
if let &None = &b {
- //~^ERROR add `&` to both
- //~|HELP try
- //~|SUGGESTION if let .. = b { .. }
+
+
+
println!("none");
}
}
const FOO : u64 = 2;
match 42 {
- 0 ... 10 => println!("0 ... 10"), //~ERROR: some ranges overlap
- 0 ... 11 => println!("0 ... 11"), //~NOTE overlaps with this
+ 0 ... 10 => println!("0 ... 10"),
+ 0 ... 11 => println!("0 ... 11"),
_ => (),
}
match 42 {
- 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
+ 0 ... 5 => println!("0 ... 5"),
6 ... 7 => println!("6 ... 7"),
- FOO ... 11 => println!("0 ... 11"), //~NOTE overlaps with this
+ FOO ... 11 => println!("0 ... 11"),
_ => (),
}
match 42 {
- 2 => println!("2"), //~NOTE overlaps with this
- 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
+ 2 => println!("2"),
+ 0 ... 5 => println!("0 ... 5"),
_ => (),
}
match 42 {
- 2 => println!("2"), //~NOTE overlaps with this
- 0 ... 2 => println!("0 ... 2"), //~ERROR: some ranges overlap
+ 2 => println!("2"),
+ 0 ... 2 => println!("0 ... 2"),
_ => (),
}
}
match 42 {
- 0 .. 11 => println!("0 .. 11"), //~ERROR: some ranges overlap
- 0 ... 11 => println!("0 ... 11"), //~NOTE overlaps with this
+ 0 .. 11 => println!("0 .. 11"),
+ 0 ... 11 => println!("0 ... 11"),
_ => (),
}
|
26 | match ExprNode::Butterflies {
| _____^ starting here...
-27 | | //~^ ERROR you seem to be trying to use match
-28 | | //~| HELP try
-29 | | //~| SUGGESTION if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { let x = 5; None }
+27 | |
+28 | |
+29 | |
30 | | ExprNode::ExprAddrOf => Some(&NODE),
31 | | _ => { let x = 5; None },
32 | | }
|
38 | match x {
| _____^ starting here...
-39 | | //~^ ERROR you seem to be trying to use match
-40 | | //~| HELP try
-41 | | //~| SUGGESTION if let Some(y) = x { println!("{:?}", y); };
+39 | |
+40 | |
+41 | |
42 | | Some(y) => { println!("{:?}", y); }
43 | | _ => ()
44 | | };
|
47 | match z {
| _____^ starting here...
-48 | | //~^ ERROR you seem to be trying to use match
-49 | | //~| HELP try
-50 | | //~| SUGGESTION if let (2...3, 7...9) = z { dummy() };
+48 | |
+49 | |
+50 | |
51 | | (2...3, 7...9) => dummy(),
52 | | _ => {}
53 | | };
|
72 | match x {
| _____^ starting here...
-73 | | //~^ ERROR you seem to be trying to use match
-74 | | //~| HELP try
-75 | | //~| SUGGESTION if let Some(y) = x { dummy() };
+73 | |
+74 | |
+75 | |
76 | | Some(y) => dummy(),
77 | | None => ()
78 | | };
|
80 | match y {
| _____^ starting here...
-81 | | //~^ ERROR you seem to be trying to use match
-82 | | //~| HELP try
-83 | | //~| SUGGESTION if let Ok(y) = y { dummy() };
+81 | |
+82 | |
+83 | |
84 | | Ok(y) => dummy(),
85 | | Err(..) => ()
86 | | };
|
90 | match c {
| _____^ starting here...
-91 | | //~^ ERROR you seem to be trying to use match
-92 | | //~| HELP try
-93 | | //~| SUGGESTION if let Cow::Borrowed(..) = c { dummy() };
+91 | |
+92 | |
+93 | |
94 | | Cow::Borrowed(..) => dummy(),
95 | | Cow::Owned(..) => (),
96 | | };
|
114 | match test {
| _____^ starting here...
-115 | | //~^ ERROR you seem to be trying to match on a boolean expression
-116 | | //~| HELP consider
-117 | | //~| SUGGESTION if test { 0 } else { 42 };
+115 | |
+116 | |
+117 | |
118 | | true => 0,
119 | | false => 42,
120 | | };
|
123 | match option == 1 {
| _____^ starting here...
-124 | | //~^ ERROR you seem to be trying to match on a boolean expression
-125 | | //~| HELP consider
-126 | | //~| SUGGESTION if option == 1 { 1 } else { 0 };
+124 | |
+125 | |
+126 | |
127 | | true => 1,
128 | | false => 0,
129 | | };
|
131 | match test {
| _____^ starting here...
-132 | | //~^ ERROR you seem to be trying to match on a boolean expression
-133 | | //~| HELP consider
-134 | | //~| SUGGESTION if !test { println!("Noooo!"); };
+132 | |
+133 | |
+134 | |
135 | | true => (),
136 | | false => { println!("Noooo!"); }
137 | | };
|
139 | match test {
| _____^ starting here...
-140 | | //~^ ERROR you seem to be trying to match on a boolean expression
-141 | | //~| HELP consider
-142 | | //~| SUGGESTION if !test { println!("Noooo!"); };
+140 | |
+141 | |
+142 | |
143 | | false => { println!("Noooo!"); }
144 | | _ => (),
145 | | };
|
147 | match test && test {
| _____^ starting here...
-148 | | //~^ ERROR you seem to be trying to match on a boolean expression
-149 | | //~| HELP consider
-150 | | //~| SUGGESTION if !(test && test) { println!("Noooo!"); };
-151 | | //~| ERROR equal expressions as operands
+148 | |
+149 | |
+150 | |
+151 | |
152 | | false => { println!("Noooo!"); }
153 | | _ => (),
154 | | };
|
156 | match test {
| _____^ starting here...
-157 | | //~^ ERROR you seem to be trying to match on a boolean expression
-158 | | //~| HELP consider
-159 | | //~| SUGGESTION if test { println!("Yes!"); } else { println!("Noooo!"); };
+157 | |
+158 | |
+159 | |
160 | | false => { println!("Noooo!"); }
161 | | true => { println!("Yes!"); }
162 | | };
|
175 | match v {
| _________^ starting here...
-176 | | //~^ERROR add `&` to all patterns
-177 | | //~|HELP instead of
-178 | | //~|SUGGESTION match *v { .. }
+176 | |
+177 | |
+178 | |
179 | | &Some(v) => println!("{:?}", v),
180 | | &None => println!("none"),
181 | | }
|
188 | match tup {
| _____^ starting here...
-189 | | //~^ERROR add `&` to all patterns
-190 | | //~|HELP instead of
-191 | | //~|SUGGESTION match *tup { .. }
+189 | |
+190 | |
+191 | |
192 | | &(v, 1) => println!("{}", v),
193 | | _ => println!("none"),
194 | | }
|
197 | match &w {
| _____^ starting here...
-198 | | //~^ERROR add `&` to both
-199 | | //~|HELP try
-200 | | //~|SUGGESTION match w { .. }
+198 | |
+199 | |
+200 | |
201 | | &Some(v) => println!("{:?}", v),
202 | | &None => println!("none"),
203 | | }
|
211 | if let &None = a {
| _____^ starting here...
-212 | | //~^ERROR add `&` to all patterns
-213 | | //~|HELP instead of
-214 | | //~|SUGGESTION if let .. = *a { .. }
+212 | |
+213 | |
+214 | |
215 | | println!("none");
216 | | }
| |_____^ ...ending here
|
219 | if let &None = &b {
| _____^ starting here...
-220 | | //~^ERROR add `&` to both
-221 | | //~|HELP try
-222 | | //~|SUGGESTION if let .. = b { .. }
+220 | |
+221 | |
+222 | |
223 | | println!("none");
224 | | }
| |_____^ ...ending here
error: some ranges overlap
--> $DIR/matches.rs:231:9
|
-231 | 0 ... 10 => println!("0 ... 10"), //~ERROR: some ranges overlap
+231 | 0 ... 10 => println!("0 ... 10"),
| ^^^^^^^^
|
= note: #[deny(match_overlapping_arm)] implied by #[deny(clippy)]
note: overlaps with this
--> $DIR/matches.rs:232:9
|
-232 | 0 ... 11 => println!("0 ... 11"), //~NOTE overlaps with this
+232 | 0 ... 11 => println!("0 ... 11"),
| ^^^^^^^^
error: some ranges overlap
--> $DIR/matches.rs:237:9
|
-237 | 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
+237 | 0 ... 5 => println!("0 ... 5"),
| ^^^^^^^
|
= note: #[deny(match_overlapping_arm)] implied by #[deny(clippy)]
note: overlaps with this
--> $DIR/matches.rs:239:9
|
-239 | FOO ... 11 => println!("0 ... 11"), //~NOTE overlaps with this
+239 | FOO ... 11 => println!("0 ... 11"),
| ^^^^^^^^^^
error: some ranges overlap
--> $DIR/matches.rs:245:9
|
-245 | 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
+245 | 0 ... 5 => println!("0 ... 5"),
| ^^^^^^^
|
= note: #[deny(match_overlapping_arm)] implied by #[deny(clippy)]
note: overlaps with this
--> $DIR/matches.rs:244:9
|
-244 | 2 => println!("2"), //~NOTE overlaps with this
+244 | 2 => println!("2"),
| ^
error: some ranges overlap
--> $DIR/matches.rs:251:9
|
-251 | 0 ... 2 => println!("0 ... 2"), //~ERROR: some ranges overlap
+251 | 0 ... 2 => println!("0 ... 2"),
| ^^^^^^^
|
= note: #[deny(match_overlapping_arm)] implied by #[deny(clippy)]
note: overlaps with this
--> $DIR/matches.rs:250:9
|
-250 | 2 => println!("2"), //~NOTE overlaps with this
+250 | 2 => println!("2"),
| ^
error: some ranges overlap
--> $DIR/matches.rs:274:9
|
-274 | 0 .. 11 => println!("0 .. 11"), //~ERROR: some ranges overlap
+274 | 0 .. 11 => println!("0 .. 11"),
| ^^^^^^^
|
= note: #[deny(match_overlapping_arm)] implied by #[deny(clippy)]
note: overlaps with this
--> $DIR/matches.rs:275:9
|
-275 | 0 ... 11 => println!("0 ... 11"), //~NOTE overlaps with this
+275 | 0 ... 11 => println!("0 ... 11"),
| ^^^^^^^^
error: aborting due to 23 previous errors
let six: Arc<i32> = Arc::new(6);
memstuff::forget(six);
- //~^ ERROR usage of mem::forget on Drop type
+
let seven: Rc<i32> = Rc::new(7);
std::mem::forget(seven);
- //~^ ERROR usage of mem::forget on Drop type
+
let eight: Vec<i32> = vec![8];
forgetSomething(eight);
- //~^ ERROR usage of mem::forget on Drop type
+
std::mem::forget(7);
}
struct T;
impl T {
- fn add(self, other: T) -> T { self } //~ERROR defining a method called `add`
- fn drop(&mut self) { } //~ERROR defining a method called `drop`
+ fn add(self, other: T) -> T { self }
+ fn drop(&mut self) { }
fn sub(&self, other: T) -> &T { self } // no error, self is a ref
fn div(self) -> T { self } // no error, different #arguments
fn rem(self, other: T) { } // no error, wrong return type
fn into_u32(self) -> u32 { 0 } // fine
- fn into_u16(&self) -> u16 { 0 } //~ERROR methods called `into_*` usually take self by value
+ fn into_u16(&self) -> u16 { 0 }
- fn to_something(self) -> u32 { 0 } //~ERROR methods called `to_*` usually take self by reference
+ fn to_something(self) -> u32 { 0 }
fn new(self) {}
- //~^ ERROR methods called `new` usually take no self
- //~| ERROR methods called `new` usually return `Self`
+
+
}
struct Lt<'a> {
// Check OPTION_MAP_UNWRAP_OR
// single line case
- let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)`
- //~| NOTE replace `map(|x| x + 1).unwrap_or(0)`
+ let _ = opt.map(|x| x + 1)
+
.unwrap_or(0); // should lint even though this call is on a separate line
// multi line cases
- let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or(a)`
+ let _ = opt.map(|x| {
x + 1
}
).unwrap_or(0);
- let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)`
+ let _ = opt.map(|x| x + 1)
.unwrap_or({
0
});
// Check OPTION_MAP_UNWRAP_OR_ELSE
// single line case
- let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)`
- //~| NOTE replace `map(|x| x + 1).unwrap_or_else(|| 0)`
+ let _ = opt.map(|x| x + 1)
+
.unwrap_or_else(|| 0); // should lint even though this call is on a separate line
// multi line cases
- let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or_else(g)`
+ let _ = opt.map(|x| {
x + 1
}
).unwrap_or_else(|| 0);
- let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)`
+ let _ = opt.map(|x| x + 1)
.unwrap_or_else(||
0
);
// check single-line case
let _ = v.iter().filter(|&x| *x < 0).next();
- //~^ ERROR called `filter(p).next()` on an `Iterator`.
- //~| NOTE replace `filter(|&x| *x < 0).next()`
+
+
// check multi-line case
- let _ = v.iter().filter(|&x| { //~ERROR called `filter(p).next()` on an `Iterator`.
+ let _ = v.iter().filter(|&x| {
*x < 0
}
).next();
// check `find().is_some()`, single-line
let _ = v.iter().find(|&x| *x < 0).is_some();
- //~^ ERROR called `is_some()` after searching
- //~| NOTE replace `find(|&x| *x < 0).is_some()`
+
+
// check `find().is_some()`, multi-line
- let _ = v.iter().find(|&x| { //~ERROR called `is_some()` after searching
+ let _ = v.iter().find(|&x| {
*x < 0
}
).is_some();
// check `position().is_some()`, single-line
let _ = v.iter().position(|&x| x < 0).is_some();
- //~^ ERROR called `is_some()` after searching
- //~| NOTE replace `position(|&x| x < 0).is_some()`
+
+
// check `position().is_some()`, multi-line
- let _ = v.iter().position(|&x| { //~ERROR called `is_some()` after searching
+ let _ = v.iter().position(|&x| {
x < 0
}
).is_some();
// check `rposition().is_some()`, single-line
let _ = v.iter().rposition(|&x| x < 0).is_some();
- //~^ ERROR called `is_some()` after searching
- //~| NOTE replace `rposition(|&x| x < 0).is_some()`
+
+
// check `rposition().is_some()`, multi-line
- let _ = v.iter().rposition(|&x| { //~ERROR called `is_some()` after searching
+ let _ = v.iter().rposition(|&x| {
x < 0
}
).is_some();
let with_constructor = Some(vec![1]);
with_constructor.unwrap_or(make());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_constructor.unwrap_or_else(make)
+
+
+
let with_new = Some(vec![1]);
with_new.unwrap_or(Vec::new());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_new.unwrap_or_default();
+
+
+
let with_const_args = Some(vec![1]);
with_const_args.unwrap_or(Vec::with_capacity(12));
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_const_args.unwrap_or_else(|| Vec::with_capacity(12));
+
+
+
let with_err : Result<_, ()> = Ok(vec![1]);
with_err.unwrap_or(make());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_err.unwrap_or_else(|_| make());
+
+
+
let with_err_args : Result<_, ()> = Ok(vec![1]);
with_err_args.unwrap_or(Vec::with_capacity(12));
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_err_args.unwrap_or_else(|_| Vec::with_capacity(12));
+
+
+
let with_default_trait = Some(1);
with_default_trait.unwrap_or(Default::default());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_default_trait.unwrap_or_default();
+
+
+
let with_default_type = Some(1);
with_default_type.unwrap_or(u64::default());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION with_default_type.unwrap_or_default();
+
+
+
let with_vec = Some(vec![1]);
with_vec.unwrap_or(vec![]);
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
+
+
// FIXME #944: ~|SUGGESTION with_vec.unwrap_or_else(|| vec![]);
let without_default = Some(Foo);
without_default.unwrap_or(Foo::new());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION without_default.unwrap_or_else(Foo::new);
+
+
+
let mut map = HashMap::<u64, String>::new();
map.entry(42).or_insert(String::new());
- //~^ERROR use of `or_insert` followed by a function call
- //~|HELP try this
- //~|SUGGESTION map.entry(42).or_insert_with(String::new);
+
+
+
let mut btree = BTreeMap::<u64, String>::new();
btree.entry(42).or_insert(String::new());
- //~^ERROR use of `or_insert` followed by a function call
- //~|HELP try this
- //~|SUGGESTION btree.entry(42).or_insert_with(String::new);
+
+
+
let stringy = Some(String::from(""));
let _ = stringy.unwrap_or("".to_owned());
- //~^ERROR use of `unwrap_or`
- //~|HELP try this
- //~|SUGGESTION stringy.unwrap_or_else(|| "".to_owned());
+
+
+
}
/// Checks implementation of `ITER_NTH` lint
{
// Make sure we lint `.iter()` for relevant types
let bad_vec = some_vec.iter().nth(3);
- //~^ERROR called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable
+
let bad_slice = &some_vec[..].iter().nth(3);
- //~^ERROR called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
+
let bad_boxed_slice = boxed_slice.iter().nth(3);
- //~^ERROR called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
+
let bad_vec_deque = some_vec_deque.iter().nth(3);
- //~^ERROR called `.iter().nth()` on a VecDeque. Calling `.get()` is both faster and more readable
+
}
{
// Make sure we lint `.iter_mut()` for relevant types
let bad_vec = some_vec.iter_mut().nth(3);
- //~^ERROR called `.iter_mut().nth()` on a Vec. Calling `.get_mut()` is both faster and more readable
+
}
{
let bad_slice = &some_vec[..].iter_mut().nth(3);
- //~^ERROR called `.iter_mut().nth()` on a slice. Calling `.get_mut()` is both faster and more readable
+
}
{
let bad_vec_deque = some_vec_deque.iter_mut().nth(3);
- //~^ERROR called `.iter_mut().nth()` on a VecDeque. Calling `.get_mut()` is both faster and more readable
+
}
// Make sure we don't lint for non-relevant types
let mut some_vec = vec![0, 1, 2, 3];
let _ = some_vec.iter().skip(42).next();
- //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
+
let _ = some_vec.iter().cycle().skip(42).next();
- //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
+
let _ = (1..10).skip(10).next();
- //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
+
let _ = &some_vec[..].iter().skip(3).next();
- //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
+
let foo = IteratorFalsePositives { foo : 0 };
let _ = foo.skip(42).next();
{ // Test `get().unwrap()`
let _ = boxed_slice.get(1).unwrap();
- //~^ERROR called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION boxed_slice[1]
+
+
+
let _ = some_slice.get(0).unwrap();
- //~^ERROR called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION some_slice[0]
+
+
+
let _ = some_vec.get(0).unwrap();
- //~^ERROR called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION some_vec[0]
+
+
+
let _ = some_vecdeque.get(0).unwrap();
- //~^ERROR called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION some_vecdeque[0]
+
+
+
let _ = some_hashmap.get(&1).unwrap();
- //~^ERROR called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION some_hashmap[&1]
+
+
+
let _ = some_btreemap.get(&1).unwrap();
- //~^ERROR called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION some_btreemap[&1]
+
+
+
let _ = false_positive.get(0).unwrap();
}
{ // Test `get_mut().unwrap()`
*boxed_slice.get_mut(0).unwrap() = 1;
- //~^ERROR called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION &mut boxed_slice[0]
+
+
+
*some_slice.get_mut(0).unwrap() = 1;
- //~^ERROR called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION &mut some_slice[0]
+
+
+
*some_vec.get_mut(0).unwrap() = 1;
- //~^ERROR called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION &mut some_vec[0]
+
+
+
*some_vecdeque.get_mut(0).unwrap() = 1;
- //~^ERROR called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
- //~|HELP try this
- //~|SUGGESTION &mut some_vecdeque[0]
+
+
+
// Check false positives
*some_hashmap.get_mut(&1).unwrap() = 'b';
use std::io;
let opt = Some(0);
- let _ = opt.unwrap(); //~ERROR used unwrap() on an Option
+ let _ = opt.unwrap();
let res: Result<i32, ()> = Ok(0);
- let _ = res.unwrap(); //~ERROR used unwrap() on a Result
+ let _ = res.unwrap();
- res.ok().expect("disaster!"); //~ERROR called `ok().expect()`
+ res.ok().expect("disaster!");
// the following should not warn, since `expect` isn't implemented unless
// the error type implements `Debug`
let res2: Result<i32, MyError> = Ok(0);
res2.ok().expect("oh noes!");
let res3: Result<u32, MyErrorWithParam<u8>>= Ok(0);
- res3.ok().expect("whoof"); //~ERROR called `ok().expect()`
+ res3.ok().expect("whoof");
let res4: Result<u32, io::Error> = Ok(0);
- res4.ok().expect("argh"); //~ERROR called `ok().expect()`
+ res4.ok().expect("argh");
let res5: io::Result<u32> = Ok(0);
- res5.ok().expect("oops"); //~ERROR called `ok().expect()`
+ res5.ok().expect("oops");
let res6: Result<u32, &str> = Ok(0);
- res6.ok().expect("meh"); //~ERROR called `ok().expect()`
+ res6.ok().expect("meh");
}
struct MyError(()); // doesn't implement Debug
#[allow(unnecessary_operation)]
fn starts_with() {
"".chars().next() == Some(' ');
- //~^ ERROR starts_with
- //~| HELP like this
- //~| SUGGESTION "".starts_with(' ')
+
+
+
Some(' ') != "".chars().next();
- //~^ ERROR starts_with
- //~| HELP like this
- //~| SUGGESTION !"".starts_with(' ')
+
+
+
}
fn str_extend_chars() {
s.push_str(abc);
s.extend(abc.chars());
- //~^ERROR calling `.extend(_.chars())`
- //~|HELP try this
- //~|SUGGESTION s.push_str(abc)
+
+
+
s.push_str("abc");
s.extend("abc".chars());
- //~^ERROR calling `.extend(_.chars())`
- //~|HELP try this
- //~|SUGGESTION s.push_str("abc")
+
+
+
s.push_str(&def);
s.extend(def.chars());
- //~^ERROR calling `.extend(_.chars())`
- //~|HELP try this
- //~|SUGGESTION s.push_str(&def)
+
+
+
s.extend(abc.chars().skip(1));
s.extend("abc".chars().skip(1));
}
fn clone_on_copy() {
- 42.clone(); //~ERROR using `clone` on a `Copy` type
- //~| HELP try removing the `clone` call
- //~| SUGGESTION 42
+ 42.clone();
+
+
vec![1].clone(); // ok, not a Copy type
Some(vec![1]).clone(); // ok, not a Copy type
- (&42).clone(); //~ERROR using `clone` on a `Copy` type
- //~| HELP try dereferencing it
- //~| SUGGESTION *(&42)
+ (&42).clone();
+
+
}
fn clone_on_copy_generic<T: Copy>(t: T) {
- t.clone(); //~ERROR using `clone` on a `Copy` type
- //~| HELP try removing the `clone` call
- //~| SUGGESTION t
- Some(t).clone(); //~ERROR using `clone` on a `Copy` type
- //~| HELP try removing the `clone` call
- //~| SUGGESTION Some(t)
+ t.clone();
+
+
+ Some(t).clone();
+
+
}
fn clone_on_double_ref() {
let x = vec![1];
let y = &&x;
- let z: &Vec<_> = y.clone(); //~ERROR using `clone` on a double
- //~| HELP try dereferencing it
- //~| SUGGESTION let z: &Vec<_> = (*y).clone();
+ let z: &Vec<_> = y.clone();
+
+
println!("{:p} {:p}",*y, z);
}
fn single_char_pattern() {
let x = "foo";
x.split("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.split('x');
+
+
+
x.split("xx");
x.split("❤️");
x.contains("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.contains('x');
+
+
+
x.starts_with("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.starts_with('x');
+
+
+
x.ends_with("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.ends_with('x');
+
+
+
x.find("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.find('x');
+
+
+
x.rfind("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rfind('x');
+
+
+
x.rsplit("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rsplit('x');
+
+
+
x.split_terminator("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.split_terminator('x');
+
+
+
x.rsplit_terminator("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rsplit_terminator('x');
+
+
+
x.splitn(0, "x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.splitn(0, 'x');
+
+
+
x.rsplitn(0, "x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rsplitn(0, 'x');
+
+
+
x.matches("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.matches('x');
+
+
+
x.rmatches("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rmatches('x');
+
+
+
x.match_indices("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.match_indices('x');
+
+
+
x.rmatch_indices("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.rmatch_indices('x');
+
+
+
x.trim_left_matches("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.trim_left_matches('x');
+
+
+
x.trim_right_matches("x");
- //~^ ERROR single-character string constant used as pattern
- //~| HELP try using a char instead:
- //~| SUGGESTION x.trim_right_matches('x');
+
+
+
let h = HashSet::<String>::new();
h.contains("X"); // should not warn
use std::ffi::CString;
CString::new("foo").unwrap().as_ptr();
- //~^ ERROR you are getting the inner pointer of a temporary `CString`
- //~| NOTE that pointer will be invalid outside this expression
- //~| HELP assign the `CString` to a variable to extend its lifetime
+
+
+
}
error: defining a method called `add` on this type; consider implementing the `std::ops::Add` trait or choosing a less ambiguous name
--> $DIR/methods.rs:18:5
|
-18 | fn add(self, other: T) -> T { self } //~ERROR defining a method called `add`
+18 | fn add(self, other: T) -> T { self }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(should_implement_trait)] implied by #[deny(clippy)]
error: defining a method called `drop` on this type; consider implementing the `std::ops::Drop` trait or choosing a less ambiguous name
--> $DIR/methods.rs:19:5
|
-19 | fn drop(&mut self) { } //~ERROR defining a method called `drop`
+19 | fn drop(&mut self) { }
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(should_implement_trait)] implied by #[deny(clippy)]
error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
--> $DIR/methods.rs:26:17
|
-26 | fn into_u16(&self) -> u16 { 0 } //~ERROR methods called `into_*` usually take self by value
+26 | fn into_u16(&self) -> u16 { 0 }
| ^^^^^
|
= note: #[deny(wrong_self_convention)] implied by #[deny(clippy)]
error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
--> $DIR/methods.rs:28:21
|
-28 | fn to_something(self) -> u32 { 0 } //~ERROR methods called `to_*` usually take self by reference
+28 | fn to_something(self) -> u32 { 0 }
| ^^^^
|
= note: #[deny(wrong_self_convention)] implied by #[deny(clippy)]
error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
--> $DIR/methods.rs:99:13
|
-99 | let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)`
+99 | let _ = opt.map(|x| x + 1)
| _____________^ starting here...
-100 | | //~| NOTE replace `map(|x| x + 1).unwrap_or(0)`
+100 | |
101 | | .unwrap_or(0); // should lint even though this call is on a separate line
| |____________________________^ ...ending here
|
error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
--> $DIR/methods.rs:103:13
|
-103 | let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or(a)`
+103 | let _ = opt.map(|x| {
| _____________^ starting here...
104 | | x + 1
105 | | }
error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
--> $DIR/methods.rs:107:13
|
-107 | let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)`
+107 | let _ = opt.map(|x| x + 1)
| _____________^ starting here...
108 | | .unwrap_or({
109 | | 0
error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead
--> $DIR/methods.rs:116:13
|
-116 | let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)`
+116 | let _ = opt.map(|x| x + 1)
| _____________^ starting here...
-117 | | //~| NOTE replace `map(|x| x + 1).unwrap_or_else(|| 0)`
+117 | |
118 | | .unwrap_or_else(|| 0); // should lint even though this call is on a separate line
| |____________________________________^ ...ending here
|
error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead
--> $DIR/methods.rs:120:13
|
-120 | let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or_else(g)`
+120 | let _ = opt.map(|x| {
| _____________^ starting here...
121 | | x + 1
122 | | }
error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead
--> $DIR/methods.rs:124:13
|
-124 | let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)`
+124 | let _ = opt.map(|x| x + 1)
| _____________^ starting here...
125 | | .unwrap_or_else(||
126 | | 0
error: called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` instead.
--> $DIR/methods.rs:201:13
|
-201 | let _ = v.iter().filter(|&x| { //~ERROR called `filter(p).next()` on an `Iterator`.
+201 | let _ = v.iter().filter(|&x| {
| _____________^ starting here...
202 | | *x < 0
203 | | }
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:221:13
|
-221 | let _ = v.iter().find(|&x| { //~ERROR called `is_some()` after searching
+221 | let _ = v.iter().find(|&x| {
| _____________^ starting here...
222 | | *x < 0
223 | | }
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:232:13
|
-232 | let _ = v.iter().position(|&x| { //~ERROR called `is_some()` after searching
+232 | let _ = v.iter().position(|&x| {
| _____________^ starting here...
233 | | x < 0
234 | | }
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:243:13
|
-243 | let _ = v.iter().rposition(|&x| { //~ERROR called `is_some()` after searching
+243 | let _ = v.iter().rposition(|&x| {
| _____________^ starting here...
244 | | x < 0
245 | | }
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
--> $DIR/methods.rs:488:13
|
-488 | let _ = opt.unwrap(); //~ERROR used unwrap() on an Option
+488 | let _ = opt.unwrap();
| ^^^^^^^^^^^^
|
= note: #[deny(option_unwrap_used)] implied by #[deny(clippy_pedantic)]
error: used unwrap() on a Result value. If you don't want to handle the Err case gracefully, consider using expect() to provide a better panic message
--> $DIR/methods.rs:491:13
|
-491 | let _ = res.unwrap(); //~ERROR used unwrap() on a Result
+491 | let _ = res.unwrap();
| ^^^^^^^^^^^^
|
= note: #[deny(result_unwrap_used)] implied by #[deny(clippy_pedantic)]
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
--> $DIR/methods.rs:493:5
|
-493 | res.ok().expect("disaster!"); //~ERROR called `ok().expect()`
+493 | res.ok().expect("disaster!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(ok_expect)] implied by #[deny(clippy)]
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
--> $DIR/methods.rs:499:5
|
-499 | res3.ok().expect("whoof"); //~ERROR called `ok().expect()`
+499 | res3.ok().expect("whoof");
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(ok_expect)] implied by #[deny(clippy)]
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
--> $DIR/methods.rs:501:5
|
-501 | res4.ok().expect("argh"); //~ERROR called `ok().expect()`
+501 | res4.ok().expect("argh");
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(ok_expect)] implied by #[deny(clippy)]
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
--> $DIR/methods.rs:503:5
|
-503 | res5.ok().expect("oops"); //~ERROR called `ok().expect()`
+503 | res5.ok().expect("oops");
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(ok_expect)] implied by #[deny(clippy)]
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
--> $DIR/methods.rs:505:5
|
-505 | res6.ok().expect("meh"); //~ERROR called `ok().expect()`
+505 | res6.ok().expect("meh");
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(ok_expect)] implied by #[deny(clippy)]
error: using `clone` on a `Copy` type
--> $DIR/methods.rs:560:5
|
-560 | 42.clone(); //~ERROR using `clone` on a `Copy` type
+560 | 42.clone();
| ^^^^^^^^^^
|
= note: #[deny(clone_on_copy)] implied by #[deny(clippy)]
5 | #![deny(clippy, clippy_pedantic)]
| ^^^^^^
help: try removing the `clone` call
- | 42; //~ERROR using `clone` on a `Copy` type
+ | 42;
error: using `clone` on a `Copy` type
--> $DIR/methods.rs:565:5
|
-565 | (&42).clone(); //~ERROR using `clone` on a `Copy` type
+565 | (&42).clone();
| ^^^^^^^^^^^^^
|
= note: #[deny(clone_on_copy)] implied by #[deny(clippy)]
help: try dereferencing it
- | *(&42); //~ERROR using `clone` on a `Copy` type
+ | *(&42);
error: using `clone` on a `Copy` type
--> $DIR/methods.rs:571:5
|
-571 | t.clone(); //~ERROR using `clone` on a `Copy` type
+571 | t.clone();
| ^^^^^^^^^
|
= note: #[deny(clone_on_copy)] implied by #[deny(clippy)]
help: try removing the `clone` call
- | t; //~ERROR using `clone` on a `Copy` type
+ | t;
error: using `clone` on a `Copy` type
--> $DIR/methods.rs:574:5
|
-574 | Some(t).clone(); //~ERROR using `clone` on a `Copy` type
+574 | Some(t).clone();
| ^^^^^^^^^^^^^^^
|
= note: #[deny(clone_on_copy)] implied by #[deny(clippy)]
help: try removing the `clone` call
- | Some(t); //~ERROR using `clone` on a `Copy` type
+ | Some(t);
error: using `clone` on a double-reference; this will copy the reference instead of cloning the inner type
--> $DIR/methods.rs:582:22
|
-582 | let z: &Vec<_> = y.clone(); //~ERROR using `clone` on a double
+582 | let z: &Vec<_> = y.clone();
| ^^^^^^^^^
|
= note: #[deny(clone_double_ref)] implied by #[deny(clippy)]
5 | #![deny(clippy, clippy_pedantic)]
| ^^^^^^
help: try dereferencing it
- | let z: &Vec<_> = (*y).clone(); //~ERROR using `clone` on a double
+ | let z: &Vec<_> = (*y).clone();
error: single-character string constant used as pattern
--> $DIR/methods.rs:590:13
fn main() {
let x;
x = 2usize;
- min(1, max(3, x)); //~ERROR this min/max combination leads to constant result
- min(max(3, x), 1); //~ERROR this min/max combination leads to constant result
- max(min(x, 1), 3); //~ERROR this min/max combination leads to constant result
- max(3, min(x, 1)); //~ERROR this min/max combination leads to constant result
+ min(1, max(3, x));
+ min(max(3, x), 1);
+ max(min(x, 1), 3);
+ max(3, min(x, 1));
- my_max(3, my_min(x, 1)); //~ERROR this min/max combination leads to constant result
+ my_max(3, my_min(x, 1));
min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x
let s;
s = "Hello";
- min("Apple", max("Zoo", s)); //~ERROR this min/max combination leads to constant result
- max(min(s, "Apple"), "Zoo"); //~ERROR this min/max combination leads to constant result
+ min("Apple", max("Zoo", s));
+ max(min(s, "Apple"), "Zoo");
max("Apple", min(s, "Zoo")); // ok
}
error: this min/max combination leads to constant result
--> $DIR/min_max.rs:15:5
|
-15 | min(1, max(3, x)); //~ERROR this min/max combination leads to constant result
+15 | min(1, max(3, x));
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(min_max)] implied by #[deny(clippy)]
error: this min/max combination leads to constant result
--> $DIR/min_max.rs:16:5
|
-16 | min(max(3, x), 1); //~ERROR this min/max combination leads to constant result
+16 | min(max(3, x), 1);
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(min_max)] implied by #[deny(clippy)]
error: this min/max combination leads to constant result
--> $DIR/min_max.rs:17:5
|
-17 | max(min(x, 1), 3); //~ERROR this min/max combination leads to constant result
+17 | max(min(x, 1), 3);
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(min_max)] implied by #[deny(clippy)]
error: this min/max combination leads to constant result
--> $DIR/min_max.rs:18:5
|
-18 | max(3, min(x, 1)); //~ERROR this min/max combination leads to constant result
+18 | max(3, min(x, 1));
| ^^^^^^^^^^^^^^^^^
|
= note: #[deny(min_max)] implied by #[deny(clippy)]
error: this min/max combination leads to constant result
--> $DIR/min_max.rs:20:5
|
-20 | my_max(3, my_min(x, 1)); //~ERROR this min/max combination leads to constant result
+20 | my_max(3, my_min(x, 1));
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(min_max)] implied by #[deny(clippy)]
error: this min/max combination leads to constant result
--> $DIR/min_max.rs:29:5
|
-29 | min("Apple", max("Zoo", s)); //~ERROR this min/max combination leads to constant result
+29 | min("Apple", max("Zoo", s));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(min_max)] implied by #[deny(clippy)]
error: this min/max combination leads to constant result
--> $DIR/min_max.rs:30:5
|
-30 | max(min(s, "Apple"), "Zoo"); //~ERROR this min/max combination leads to constant result
+30 | max(min(s, "Apple"), "Zoo");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(min_max)] implied by #[deny(clippy)]
//! Some garbage docs for the crate here
#![doc="More garbage"]
-type Typedef = String; //~ ERROR: missing documentation for a type alias
-pub type PubTypedef = String; //~ ERROR: missing documentation for a type alias
+type Typedef = String;
+pub type PubTypedef = String;
-struct Foo { //~ ERROR: missing documentation for a struct
- a: isize, //~ ERROR: missing documentation for a struct field
- b: isize, //~ ERROR: missing documentation for a struct field
+struct Foo {
+ a: isize,
+ b: isize,
}
-pub struct PubFoo { //~ ERROR: missing documentation for a struct
- pub a: isize, //~ ERROR: missing documentation for a struct field
- b: isize, //~ ERROR: missing documentation for a struct field
+pub struct PubFoo {
+ pub a: isize,
+ b: isize,
}
#[allow(missing_docs_in_private_items)]
pub c: isize,
}
-mod module_no_dox {} //~ ERROR: missing documentation for a module
-pub mod pub_module_no_dox {} //~ ERROR: missing documentation for a module
+mod module_no_dox {}
+pub mod pub_module_no_dox {}
/// dox
pub fn foo() {}
-pub fn foo2() {} //~ ERROR: missing documentation for a function
-fn foo3() {} //~ ERROR: missing documentation for a function
+pub fn foo2() {}
+fn foo3() {}
#[allow(missing_docs_in_private_items)] pub fn foo4() {}
/// dox
fn foo_with_impl(&self) {}
}
-pub trait C { //~ ERROR: missing documentation for a trait
- fn foo(&self); //~ ERROR: missing documentation for a trait method
- fn foo_with_impl(&self) {} //~ ERROR: missing documentation for a trait method
+pub trait C {
+ fn foo(&self);
+ fn foo_with_impl(&self) {}
}
#[allow(missing_docs_in_private_items)]
/// dox
pub trait E {
- type AssociatedType; //~ ERROR: missing documentation for an associated type
- type AssociatedTypeDef = Self; //~ ERROR: missing documentation for an associated type
+ type AssociatedType;
+ type AssociatedTypeDef = Self;
/// dox
type DocumentedType;
}
impl Foo {
- pub fn foo() {} //~ ERROR: missing documentation for a method
- fn bar() {} //~ ERROR: missing documentation for a method
+ pub fn foo() {}
+ fn bar() {}
}
impl PubFoo {
- pub fn foo() {} //~ ERROR: missing documentation for a method
+ pub fn foo() {}
/// dox
pub fn foo1() {}
- fn foo2() {} //~ ERROR: missing documentation for a method
+ fn foo2() {}
#[allow(missing_docs_in_private_items)] pub fn foo3() {}
}
}
}
-enum Baz { //~ ERROR: missing documentation for an enum
- BazA { //~ ERROR: missing documentation for a variant
- a: isize, //~ ERROR: missing documentation for a struct field
- b: isize //~ ERROR: missing documentation for a struct field
+enum Baz {
+ BazA {
+ a: isize,
+ b: isize
},
- BarB //~ ERROR: missing documentation for a variant
+ BarB
}
-pub enum PubBaz { //~ ERROR: missing documentation for an enum
- PubBazA { //~ ERROR: missing documentation for a variant
- a: isize, //~ ERROR: missing documentation for a struct field
+pub enum PubBaz {
+ PubBazA {
+ a: isize,
},
}
pub fn baz() {}
-const FOO: u32 = 0; //~ ERROR: missing documentation for a const
+const FOO: u32 = 0;
/// dox
pub const FOO1: u32 = 0;
#[allow(missing_docs_in_private_items)]
pub const FOO2: u32 = 0;
#[doc(hidden)]
pub const FOO3: u32 = 0;
-pub const FOO4: u32 = 0; //~ ERROR: missing documentation for a const
+pub const FOO4: u32 = 0;
-static BAR: u32 = 0; //~ ERROR: missing documentation for a static
+static BAR: u32 = 0;
/// dox
pub static BAR1: u32 = 0;
#[allow(missing_docs_in_private_items)]
pub static BAR2: u32 = 0;
#[doc(hidden)]
pub static BAR3: u32 = 0;
-pub static BAR4: u32 = 0; //~ ERROR: missing documentation for a static
+pub static BAR4: u32 = 0;
-mod internal_impl { //~ ERROR: missing documentation for a module
+mod internal_impl {
/// dox
pub fn documented() {}
- pub fn undocumented1() {} //~ ERROR: missing documentation for a function
- pub fn undocumented2() {} //~ ERROR: missing documentation for a function
- fn undocumented3() {} //~ ERROR: missing documentation for a function
+ pub fn undocumented1() {}
+ pub fn undocumented2() {}
+ fn undocumented3() {}
/// dox
pub mod globbed {
/// dox
pub fn also_documented() {}
- pub fn also_undocumented1() {} //~ ERROR: missing documentation for a function
- fn also_undocumented2() {} //~ ERROR: missing documentation for a function
+ pub fn also_undocumented1() {}
+ fn also_undocumented2() {}
}
}
/// dox
pub use internal_impl::globbed::*;
}
-fn main() {} //~ ERROR: missing documentation for a function
+fn main() {}
error: missing documentation for a type alias
--> $DIR/missing-doc.rs:26:1
|
-26 | type Typedef = String; //~ ERROR: missing documentation for a type alias
+26 | type Typedef = String;
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: missing documentation for a type alias
--> $DIR/missing-doc.rs:27:1
|
-27 | pub type PubTypedef = String; //~ ERROR: missing documentation for a type alias
+27 | pub type PubTypedef = String;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a struct
--> $DIR/missing-doc.rs:29:1
|
-29 | struct Foo { //~ ERROR: missing documentation for a struct
+29 | struct Foo {
| _^ starting here...
-30 | | a: isize, //~ ERROR: missing documentation for a struct field
-31 | | b: isize, //~ ERROR: missing documentation for a struct field
+30 | | a: isize,
+31 | | b: isize,
32 | | }
| |_^ ...ending here
error: missing documentation for a struct field
--> $DIR/missing-doc.rs:30:5
|
-30 | a: isize, //~ ERROR: missing documentation for a struct field
+30 | a: isize,
| ^^^^^^^^
error: missing documentation for a struct field
--> $DIR/missing-doc.rs:31:5
|
-31 | b: isize, //~ ERROR: missing documentation for a struct field
+31 | b: isize,
| ^^^^^^^^
error: missing documentation for a struct
--> $DIR/missing-doc.rs:34:1
|
-34 | pub struct PubFoo { //~ ERROR: missing documentation for a struct
+34 | pub struct PubFoo {
| _^ starting here...
-35 | | pub a: isize, //~ ERROR: missing documentation for a struct field
-36 | | b: isize, //~ ERROR: missing documentation for a struct field
+35 | | pub a: isize,
+36 | | b: isize,
37 | | }
| |_^ ...ending here
error: missing documentation for a struct field
--> $DIR/missing-doc.rs:35:5
|
-35 | pub a: isize, //~ ERROR: missing documentation for a struct field
+35 | pub a: isize,
| ^^^^^^^^^^^^
error: missing documentation for a struct field
--> $DIR/missing-doc.rs:36:5
|
-36 | b: isize, //~ ERROR: missing documentation for a struct field
+36 | b: isize,
| ^^^^^^^^
error: missing documentation for a module
--> $DIR/missing-doc.rs:45:1
|
-45 | mod module_no_dox {} //~ ERROR: missing documentation for a module
+45 | mod module_no_dox {}
| ^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a module
--> $DIR/missing-doc.rs:46:1
|
-46 | pub mod pub_module_no_dox {} //~ ERROR: missing documentation for a module
+46 | pub mod pub_module_no_dox {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
--> $DIR/missing-doc.rs:50:1
|
-50 | pub fn foo2() {} //~ ERROR: missing documentation for a function
+50 | pub fn foo2() {}
| ^^^^^^^^^^^^^^^^
error: missing documentation for a function
--> $DIR/missing-doc.rs:51:1
|
-51 | fn foo3() {} //~ ERROR: missing documentation for a function
+51 | fn foo3() {}
| ^^^^^^^^^^^^
error: missing documentation for a trait
--> $DIR/missing-doc.rs:68:1
|
-68 | pub trait C { //~ ERROR: missing documentation for a trait
+68 | pub trait C {
| _^ starting here...
-69 | | fn foo(&self); //~ ERROR: missing documentation for a trait method
-70 | | fn foo_with_impl(&self) {} //~ ERROR: missing documentation for a trait method
+69 | | fn foo(&self);
+70 | | fn foo_with_impl(&self) {}
71 | | }
| |_^ ...ending here
error: missing documentation for a trait method
--> $DIR/missing-doc.rs:69:5
|
-69 | fn foo(&self); //~ ERROR: missing documentation for a trait method
+69 | fn foo(&self);
| ^^^^^^^^^^^^^^
error: missing documentation for a trait method
--> $DIR/missing-doc.rs:70:5
|
-70 | fn foo_with_impl(&self) {} //~ ERROR: missing documentation for a trait method
+70 | fn foo_with_impl(&self) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for an associated type
--> $DIR/missing-doc.rs:80:5
|
-80 | type AssociatedType; //~ ERROR: missing documentation for an associated type
+80 | type AssociatedType;
| ^^^^^^^^^^^^^^^^^^^^
error: missing documentation for an associated type
--> $DIR/missing-doc.rs:81:5
|
-81 | type AssociatedTypeDef = Self; //~ ERROR: missing documentation for an associated type
+81 | type AssociatedTypeDef = Self;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a method
--> $DIR/missing-doc.rs:92:5
|
-92 | pub fn foo() {} //~ ERROR: missing documentation for a method
+92 | pub fn foo() {}
| ^^^^^^^^^^^^^^^
error: missing documentation for a method
--> $DIR/missing-doc.rs:93:5
|
-93 | fn bar() {} //~ ERROR: missing documentation for a method
+93 | fn bar() {}
| ^^^^^^^^^^^
error: missing documentation for a method
--> $DIR/missing-doc.rs:97:5
|
-97 | pub fn foo() {} //~ ERROR: missing documentation for a method
+97 | pub fn foo() {}
| ^^^^^^^^^^^^^^^
error: missing documentation for a method
--> $DIR/missing-doc.rs:100:5
|
-100 | fn foo2() {} //~ ERROR: missing documentation for a method
+100 | fn foo2() {}
| ^^^^^^^^^^^^
error: missing documentation for an enum
--> $DIR/missing-doc.rs:126:1
|
-126 | enum Baz { //~ ERROR: missing documentation for an enum
+126 | enum Baz {
| _^ starting here...
-127 | | BazA { //~ ERROR: missing documentation for a variant
-128 | | a: isize, //~ ERROR: missing documentation for a struct field
-129 | | b: isize //~ ERROR: missing documentation for a struct field
+127 | | BazA {
+128 | | a: isize,
+129 | | b: isize
130 | | },
-131 | | BarB //~ ERROR: missing documentation for a variant
+131 | | BarB
132 | | }
| |_^ ...ending here
error: missing documentation for a variant
--> $DIR/missing-doc.rs:127:5
|
-127 | BazA { //~ ERROR: missing documentation for a variant
+127 | BazA {
| _____^ starting here...
-128 | | a: isize, //~ ERROR: missing documentation for a struct field
-129 | | b: isize //~ ERROR: missing documentation for a struct field
+128 | | a: isize,
+129 | | b: isize
130 | | },
| |_____^ ...ending here
error: missing documentation for a struct field
--> $DIR/missing-doc.rs:128:9
|
-128 | a: isize, //~ ERROR: missing documentation for a struct field
+128 | a: isize,
| ^^^^^^^^
error: missing documentation for a struct field
--> $DIR/missing-doc.rs:129:9
|
-129 | b: isize //~ ERROR: missing documentation for a struct field
+129 | b: isize
| ^^^^^^^^
error: missing documentation for a variant
--> $DIR/missing-doc.rs:131:5
|
-131 | BarB //~ ERROR: missing documentation for a variant
+131 | BarB
| ^^^^
error: missing documentation for an enum
--> $DIR/missing-doc.rs:134:1
|
-134 | pub enum PubBaz { //~ ERROR: missing documentation for an enum
+134 | pub enum PubBaz {
| _^ starting here...
-135 | | PubBazA { //~ ERROR: missing documentation for a variant
-136 | | a: isize, //~ ERROR: missing documentation for a struct field
+135 | | PubBazA {
+136 | | a: isize,
137 | | },
138 | | }
| |_^ ...ending here
error: missing documentation for a variant
--> $DIR/missing-doc.rs:135:5
|
-135 | PubBazA { //~ ERROR: missing documentation for a variant
+135 | PubBazA {
| _____^ starting here...
-136 | | a: isize, //~ ERROR: missing documentation for a struct field
+136 | | a: isize,
137 | | },
| |_____^ ...ending here
error: missing documentation for a struct field
--> $DIR/missing-doc.rs:136:9
|
-136 | a: isize, //~ ERROR: missing documentation for a struct field
+136 | a: isize,
| ^^^^^^^^
error: missing documentation for a constant
--> $DIR/missing-doc.rs:160:1
|
-160 | const FOO: u32 = 0; //~ ERROR: missing documentation for a const
+160 | const FOO: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^
error: missing documentation for a constant
--> $DIR/missing-doc.rs:167:1
|
-167 | pub const FOO4: u32 = 0; //~ ERROR: missing documentation for a const
+167 | pub const FOO4: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a static
--> $DIR/missing-doc.rs:170:1
|
-170 | static BAR: u32 = 0; //~ ERROR: missing documentation for a static
+170 | static BAR: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a static
--> $DIR/missing-doc.rs:177:1
|
-177 | pub static BAR4: u32 = 0; //~ ERROR: missing documentation for a static
+177 | pub static BAR4: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a module
--> $DIR/missing-doc.rs:180:1
|
-180 | mod internal_impl { //~ ERROR: missing documentation for a module
+180 | mod internal_impl {
| ^
error: missing documentation for a function
--> $DIR/missing-doc.rs:183:5
|
-183 | pub fn undocumented1() {} //~ ERROR: missing documentation for a function
+183 | pub fn undocumented1() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
--> $DIR/missing-doc.rs:184:5
|
-184 | pub fn undocumented2() {} //~ ERROR: missing documentation for a function
+184 | pub fn undocumented2() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
--> $DIR/missing-doc.rs:185:5
|
-185 | fn undocumented3() {} //~ ERROR: missing documentation for a function
+185 | fn undocumented3() {}
| ^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
--> $DIR/missing-doc.rs:190:9
|
-190 | pub fn also_undocumented1() {} //~ ERROR: missing documentation for a function
+190 | pub fn also_undocumented1() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
--> $DIR/missing-doc.rs:191:9
|
-191 | fn also_undocumented2() {} //~ ERROR: missing documentation for a function
+191 | fn also_undocumented2() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
--> $DIR/missing-doc.rs:202:1
|
-202 | fn main() {} //~ ERROR: missing documentation for a function
+202 | fn main() {}
| ^^^^^^^^^^^^
error: aborting due to 40 previous errors
mod foo {
mod bar {
- mod bar { //~ ERROR module has the same name as its containing module
+ mod bar {
mod foo {}
}
mod foo {}
}
- mod foo { //~ ERROR module has the same name as its containing module
+ mod foo {
mod bar {}
}
}
error: module has the same name as its containing module
--> $DIR/module_inception.rs:7:9
|
-7 | mod bar { //~ ERROR module has the same name as its containing module
+7 | mod bar {
| _________^ starting here...
8 | | mod foo {}
9 | | }
error: module has the same name as its containing module
--> $DIR/module_inception.rs:12:5
|
-12 | mod foo { //~ ERROR module has the same name as its containing module
+12 | mod foo {
| _____^ starting here...
13 | | mod bar {}
14 | | }
#![allow(no_effect, unnecessary_operation)]
fn main() {
- 10 % 1; //~ERROR any number modulo 1 will be 0
+ 10 % 1;
10 % 2;
}
error: any number modulo 1 will be 0
--> $DIR/modulo_one.rs:7:5
|
-7 | 10 % 1; //~ERROR any number modulo 1 will be 0
+7 | 10 % 1;
| ^^^^^^
|
note: lint level defined here
//#![plugin(regex_macros)]
//extern crate regex;
-fn fun(x : &mut &mut u32) -> bool { //~ERROR generally you want to avoid `&mut &mut
+fn fun(x : &mut &mut u32) -> bool {
**x > 0
}
macro_rules! mut_ptr {
($p:expr) => { &mut $p }
- //~^ ERROR generally you want to avoid `&mut &mut
+
}
#[allow(unused_mut, unused_variables)]
fn main() {
- let mut x = &mut &mut 1u32; //~ERROR generally you want to avoid `&mut &mut
+ let mut x = &mut &mut 1u32;
{
- let mut y = &mut x; //~ERROR this expression mutably borrows a mutable reference
+ let mut y = &mut x;
}
if fun(x) {
let y : &mut &mut u32 = &mut &mut 2;
- //~^ ERROR generally you want to avoid `&mut &mut
- //~| ERROR generally you want to avoid `&mut &mut
- //~| ERROR generally you want to avoid `&mut &mut
+
+
+
**y + **x;
}
if fun(x) {
let y : &mut &mut &mut u32 = &mut &mut &mut 2;
- //~^ ERROR generally you want to avoid `&mut &mut
- //~| ERROR generally you want to avoid `&mut &mut
- //~| ERROR generally you want to avoid `&mut &mut
- //~| ERROR generally you want to avoid `&mut &mut
- //~| ERROR generally you want to avoid `&mut &mut
- //~| ERROR generally you want to avoid `&mut &mut
+
+
+
+
+
+
***y + **x;
}
let mut z = mut_ptr!(&mut 3u32);
- //~^ NOTE in this expansion of mut_ptr!
+
}
fn issue939() {
error: generally you want to avoid `&mut &mut _` if possible
--> $DIR/mut_mut.rs:10:12
|
-10 | fn fun(x : &mut &mut u32) -> bool { //~ERROR generally you want to avoid `&mut &mut
+10 | fn fun(x : &mut &mut u32) -> bool {
| ^^^^^^^^^^^^^
|
note: lint level defined here
error: generally you want to avoid `&mut &mut _` if possible
--> $DIR/mut_mut.rs:25:17
|
-25 | let mut x = &mut &mut 1u32; //~ERROR generally you want to avoid `&mut &mut
+25 | let mut x = &mut &mut 1u32;
| ^^^^^^^^^^^^^^
error: generally you want to avoid `&mut &mut _` if possible
error: this expression mutably borrows a mutable reference. Consider reborrowing
--> $DIR/mut_mut.rs:27:21
|
-27 | let mut y = &mut x; //~ERROR this expression mutably borrows a mutable reference
+27 | let mut y = &mut x;
| ^^^^^^
error: generally you want to avoid `&mut &mut _` if possible
#[deny(unnecessary_mut_passed)]
fn main() {
// Functions
- takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference
+ takes_an_immutable_reference(&mut 42);
let as_ptr: fn(&i32) = takes_an_immutable_reference;
- as_ptr(&mut 42); //~ERROR The function/method "as_ptr" doesn't need a mutable reference
+ as_ptr(&mut 42);
// Methods
let my_struct = MyStruct;
- my_struct.takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference
+ my_struct.takes_an_immutable_reference(&mut 42);
// No error
error: The function/method "takes_an_immutable_reference" doesn't need a mutable reference
--> $DIR/mut_reference.rs:22:34
|
-22 | takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference
+22 | takes_an_immutable_reference(&mut 42);
| ^^^^^^^
|
note: lint level defined here
error: The function/method "as_ptr" doesn't need a mutable reference
--> $DIR/mut_reference.rs:24:12
|
-24 | as_ptr(&mut 42); //~ERROR The function/method "as_ptr" doesn't need a mutable reference
+24 | as_ptr(&mut 42);
| ^^^^^^^
error: The function/method "takes_an_immutable_reference" doesn't need a mutable reference
--> $DIR/mut_reference.rs:28:44
|
-28 | my_struct.takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference
+28 | my_struct.takes_an_immutable_reference(&mut 42);
| ^^^^^^^
error: aborting due to 3 previous errors
fn main() {
use std::sync::Mutex;
- Mutex::new(true); //~ERROR Consider using an AtomicBool instead of a Mutex here.
- Mutex::new(5usize); //~ERROR Consider using an AtomicUsize instead of a Mutex here.
- Mutex::new(9isize); //~ERROR Consider using an AtomicIsize instead of a Mutex here.
+ Mutex::new(true);
+ Mutex::new(5usize);
+ Mutex::new(9isize);
let mut x = 4u32;
- Mutex::new(&x as *const u32); //~ERROR Consider using an AtomicPtr instead of a Mutex here.
- Mutex::new(&mut x as *mut u32); //~ERROR Consider using an AtomicPtr instead of a Mutex here.
- Mutex::new(0u32); //~ERROR Consider using an AtomicUsize instead of a Mutex here.
- Mutex::new(0i32); //~ERROR Consider using an AtomicIsize instead of a Mutex here.
+ Mutex::new(&x as *const u32);
+ Mutex::new(&mut x as *mut u32);
+ Mutex::new(0u32);
+ Mutex::new(0i32);
Mutex::new(0f32); // there are no float atomics, so this should not lint
}
error: Consider using an AtomicBool instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>.
--> $DIR/mutex_atomic.rs:9:5
|
-9 | Mutex::new(true); //~ERROR Consider using an AtomicBool instead of a Mutex here.
+9 | Mutex::new(true);
| ^^^^^^^^^^^^^^^^
|
= note: #[deny(mutex_atomic)] implied by #[deny(clippy)]
error: Consider using an AtomicUsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>.
--> $DIR/mutex_atomic.rs:10:5
|
-10 | Mutex::new(5usize); //~ERROR Consider using an AtomicUsize instead of a Mutex here.
+10 | Mutex::new(5usize);
| ^^^^^^^^^^^^^^^^^^
|
= note: #[deny(mutex_atomic)] implied by #[deny(clippy)]
error: Consider using an AtomicIsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>.
--> $DIR/mutex_atomic.rs:11:5
|
-11 | Mutex::new(9isize); //~ERROR Consider using an AtomicIsize instead of a Mutex here.
+11 | Mutex::new(9isize);
| ^^^^^^^^^^^^^^^^^^
|
= note: #[deny(mutex_atomic)] implied by #[deny(clippy)]
error: Consider using an AtomicPtr instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>.
--> $DIR/mutex_atomic.rs:13:5
|
-13 | Mutex::new(&x as *const u32); //~ERROR Consider using an AtomicPtr instead of a Mutex here.
+13 | Mutex::new(&x as *const u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(mutex_atomic)] implied by #[deny(clippy)]
error: Consider using an AtomicPtr instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>.
--> $DIR/mutex_atomic.rs:14:5
|
-14 | Mutex::new(&mut x as *mut u32); //~ERROR Consider using an AtomicPtr instead of a Mutex here.
+14 | Mutex::new(&mut x as *mut u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[deny(mutex_atomic)] implied by #[deny(clippy)]
error: Consider using an AtomicUsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>.
--> $DIR/mutex_atomic.rs:15:5
|
-15 | Mutex::new(0u32); //~ERROR Consider using an AtomicUsize instead of a Mutex here.
+15 | Mutex::new(0u32);
| ^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: Consider using an AtomicIsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>.
--> $DIR/mutex_atomic.rs:16:5
|
-16 | Mutex::new(0i32); //~ERROR Consider using an AtomicIsize instead of a Mutex here.
+16 | Mutex::new(0i32);
| ^^^^^^^^^^^^^^^^
error: aborting due to 7 previous errors
fn main() {
let x = true;
let y = false;
- if x { true } else { true }; //~ERROR this if-then-else expression will always return true
- if x { false } else { false }; //~ERROR this if-then-else expression will always return false
+ if x { true } else { true };
+ if x { false } else { false };
if x { true } else { false };
- //~^ ERROR this if-then-else expression returns a bool literal
- //~| HELP you can reduce it to
- //~| SUGGESTION x
+
+
+
if x { false } else { true };
- //~^ ERROR this if-then-else expression returns a bool literal
- //~| HELP you can reduce it to
- //~| SUGGESTION !x
+
+
+
if x && y { false } else { true };
- //~^ ERROR this if-then-else expression returns a bool literal
- //~| HELP you can reduce it to
- //~| SUGGESTION !(x && y)
+
+
+
if x { x } else { false }; // would also be questionable, but we don't catch this yet
bool_ret(x);
bool_ret2(x);
#[allow(if_same_then_else, needless_return)]
fn bool_ret(x: bool) -> bool {
if x { return true } else { return true };
- //~^ ERROR this if-then-else expression will always return true
+
}
#[allow(if_same_then_else, needless_return)]
fn bool_ret2(x: bool) -> bool {
if x { return false } else { return false };
- //~^ ERROR this if-then-else expression will always return false
+
}
#[allow(needless_return)]
fn bool_ret3(x: bool) -> bool {
if x { return true } else { return false };
- //~^ ERROR this if-then-else expression returns a bool literal
- //~| HELP you can reduce it to
- //~| SUGGESTION return x
+
+
+
}
#[allow(needless_return)]
fn bool_ret5(x: bool, y: bool) -> bool {
if x && y { return true } else { return false };
- //~^ ERROR this if-then-else expression returns a bool literal
- //~| HELP you can reduce it to
- //~| SUGGESTION return x && y
+
+
+
}
#[allow(needless_return)]
fn bool_ret4(x: bool) -> bool {
if x { return false } else { return true };
- //~^ ERROR this if-then-else expression returns a bool literal
- //~| HELP you can reduce it to
- //~| SUGGESTION return !x
+
+
+
}
#[allow(needless_return)]
fn bool_ret6(x: bool, y: bool) -> bool {
if x && y { return false } else { return true };
- //~^ ERROR this if-then-else expression returns a bool literal
- //~| HELP you can reduce it to
- //~| SUGGESTION return !(x && y)
+
+
+
}
error: this if-then-else expression will always return true
--> $DIR/needless_bool.rs:9:5
|
-9 | if x { true } else { true }; //~ERROR this if-then-else expression will always return true
+9 | if x { true } else { true };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: this if-then-else expression will always return false
--> $DIR/needless_bool.rs:10:5
|
-10 | if x { false } else { false }; //~ERROR this if-then-else expression will always return false
+10 | if x { false } else { false };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this if-then-else expression returns a bool literal
fn main() {
let a = 5;
let b = x(&a);
- let c = x(&&a); //~ ERROR: this expression borrows a reference that is immediately dereferenced by the compiler
+ let c = x(&&a);
let s = &String::from("hi");
let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not
let g_val = g(&Vec::new()); // should not error, because `&Vec<T>` derefs to `&[T]`
let vec = Vec::new();
let vec_val = g(&vec); // should not error, because `&Vec<T>` derefs to `&[T]`
h(&"foo"); // should not error, because the `&&str` is required, due to `&Trait`
- if let Some(ref cake) = Some(&5) {} //~ ERROR: this pattern creates a reference to a reference
+ if let Some(ref cake) = Some(&5) {}
}
fn f<T:Copy>(y: &T) -> T {
let mut v = Vec::<String>::new();
let _ = v.iter_mut().filter(|&ref a| a.is_empty());
let _ = v.iter().filter(|&ref a| a.is_empty());
- //~^WARNING this pattern creates a reference to a reference
+
let _ = v.iter().filter(|&a| a.is_empty());
}
error: this expression borrows a reference that is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:13:15
|
-13 | let c = x(&&a); //~ ERROR: this expression borrows a reference that is immediately dereferenced by the compiler
+13 | let c = x(&&a);
| ^^^
|
= note: #[deny(needless_borrow)] implied by #[deny(clippy)]
error: this pattern creates a reference to a reference
--> $DIR/needless_borrow.rs:20:17
|
-20 | if let Some(ref cake) = Some(&5) {} //~ ERROR: this pattern creates a reference to a reference
+20 | if let Some(ref cake) = Some(&5) {}
| ^^^^^^^^
|
= note: #[deny(needless_borrow)] implied by #[deny(clippy)]
return true;
}
return true;
- //~^ ERROR unneeded return statement
- //~| HELP remove `return` as shown
- //~| SUGGESTION true
+
+
+
}
fn test_no_semicolon() -> bool {
return true
- //~^ ERROR unneeded return statement
- //~| HELP remove `return` as shown
- //~| SUGGESTION true
+
+
+
}
fn test_if_block() -> bool {
if true {
return true;
- //~^ ERROR unneeded return statement
- //~| HELP remove `return` as shown
- //~| SUGGESTION true
+
+
+
} else {
return false;
- //~^ ERROR unneeded return statement
- //~| HELP remove `return` as shown
- //~| SUGGESTION false
+
+
+
}
}
fn test_match(x: bool) -> bool {
match x {
true => return false,
- //~^ ERROR unneeded return statement
- //~| HELP remove `return` as shown
- //~| SUGGESTION false
+
+
+
false => {
return true;
- //~^ ERROR unneeded return statement
- //~| HELP remove `return` as shown
- //~| SUGGESTION true
+
+
+
}
}
}
fn test_closure() {
let _ = || {
return true;
- //~^ ERROR unneeded return statement
- //~| HELP remove `return` as shown
- //~| SUGGESTION true
+
+
+
};
let _ = || return true;
- //~^ ERROR unneeded return statement
- //~| HELP remove `return` as shown
- //~| SUGGESTION true
+
+
+
}
fn main() {
let base = S { a: 0, b: 0 };
S { ..base }; // no error
S { a: 1, ..base }; // no error
- S { a: 1, b: 1, ..base }; //~ERROR struct update has no effect
+ S { a: 1, b: 1, ..base };
}
error: struct update has no effect, all the fields in the struct have already been specified
--> $DIR/needless_update.rs:16:23
|
-16 | S { a: 1, b: 1, ..base }; //~ERROR struct update has no effect
+16 | S { a: 1, b: 1, ..base };
| ^^^^
|
note: lint level defined here
let x = 0;
x * -1;
- //~^ ERROR Negation by multiplying with -1
+
-1 * x;
- //~^ ERROR Negation by multiplying with -1
+
-1 * -1; // should be ok
#![deny(new_without_default, new_without_default_derive)]
pub struct Foo;
-//~^HELP try this
-//~^^SUGGESTION #[derive(Default)]
-//~^^SUGGESTION pub struct Foo
+
+
+
impl Foo {
pub fn new() -> Foo { Foo }
- //~^ERROR: you should consider deriving a `Default` implementation for `Foo`
+
}
pub struct Bar;
-//~^HELP try this
-//~^^SUGGESTION #[derive(Default)]
-//~^^SUGGESTION pub struct Bar
+
+
+
impl Bar {
pub fn new() -> Self { Bar }
- //~^ERROR: you should consider deriving a `Default` implementation for `Bar`
+
}
pub struct Ok;
impl<'c> LtKo<'c> {
pub fn new() -> LtKo<'c> { unimplemented!() }
- //~^ERROR: you should consider adding a `Default` implementation for
- //~^^HELP try
- //~^^^SUGGESTION impl Default for LtKo<'c> {
- //~^^^SUGGESTION fn default() -> Self {
- //~^^^SUGGESTION Self::new()
- //~^^^SUGGESTION }
- //~^^^SUGGESTION }
+
+
+
+
+
+
+
// FIXME: that suggestion is missing lifetimes
}
let s = get_struct();
let s2 = get_struct();
- 0; //~ERROR statement with no effect
- s2; //~ERROR statement with no effect
- Unit; //~ERROR statement with no effect
- Tuple(0); //~ERROR statement with no effect
- Struct { field: 0 }; //~ERROR statement with no effect
- Struct { ..s }; //~ERROR statement with no effect
- Union { a: 0 }; //~ERROR statement with no effect
- Enum::Tuple(0); //~ERROR statement with no effect
- Enum::Struct { field: 0 }; //~ERROR statement with no effect
- 5 + 6; //~ERROR statement with no effect
- *&42; //~ERROR statement with no effect
- &6; //~ERROR statement with no effect
- (5, 6, 7); //~ERROR statement with no effect
- box 42; //~ERROR statement with no effect
- ..; //~ERROR statement with no effect
- 5..; //~ERROR statement with no effect
- ..5; //~ERROR statement with no effect
- 5..6; //~ERROR statement with no effect
- 5...6; //~ERROR statement with no effect
- [42, 55]; //~ERROR statement with no effect
- [42, 55][1]; //~ERROR statement with no effect
- (42, 55).1; //~ERROR statement with no effect
- [42; 55]; //~ERROR statement with no effect
- [42; 55][13]; //~ERROR statement with no effect
+ 0;
+ s2;
+ Unit;
+ Tuple(0);
+ Struct { field: 0 };
+ Struct { ..s };
+ Union { a: 0 };
+ Enum::Tuple(0);
+ Enum::Struct { field: 0 };
+ 5 + 6;
+ *&42;
+ &6;
+ (5, 6, 7);
+ box 42;
+ ..;
+ 5..;
+ ..5;
+ 5..6;
+ 5...6;
+ [42, 55];
+ [42, 55][1];
+ (42, 55).1;
+ [42; 55];
+ [42; 55][13];
let mut x = 0;
- || x += 5; //~ERROR statement with no effect
+ || x += 5;
// Do not warn
get_number();
unsafe { unsafe_fn() };
- Tuple(get_number()); //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_number();
- Struct { field: get_number() }; //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_number();
- Struct { ..get_struct() }; //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_struct();
- Enum::Tuple(get_number()); //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_number();
- Enum::Struct { field: get_number() }; //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_number();
- 5 + get_number(); //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION 5;get_number();
- *&get_number(); //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_number();
- &get_number(); //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_number();
- (5, 6, get_number()); //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION 5;6;get_number();
- box get_number(); //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_number();
- get_number()..; //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_number();
- ..get_number(); //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_number();
- 5..get_number(); //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION 5;get_number();
- [42, get_number()]; //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION 42;get_number();
- [42, 55][get_number() as usize]; //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION [42, 55];get_number() as usize;
- (42, get_number()).1; //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION 42;get_number();
- [get_number(); 55]; //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_number();
- [42; 55][get_number() as usize]; //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION [42; 55];get_number() as usize;
- {get_number()}; //~ERROR statement can be reduced
- //~^HELP replace it with
- //~|SUGGESTION get_number();
+ Tuple(get_number());
+
+
+ Struct { field: get_number() };
+
+
+ Struct { ..get_struct() };
+
+
+ Enum::Tuple(get_number());
+
+
+ Enum::Struct { field: get_number() };
+
+
+ 5 + get_number();
+
+
+ *&get_number();
+
+
+ &get_number();
+
+
+ (5, 6, get_number());
+
+
+ box get_number();
+
+
+ get_number()..;
+
+
+ ..get_number();
+
+
+ 5..get_number();
+
+
+ [42, get_number()];
+
+
+ [42, 55][get_number() as usize];
+
+
+ (42, get_number()).1;
+
+
+ [get_number(); 55];
+
+
+ [42; 55][get_number() as usize];
+
+
+ {get_number()};
+
+
}
error: statement with no effect
--> $DIR/no_effect.rs:34:5
|
-34 | 0; //~ERROR statement with no effect
+34 | 0;
| ^^
|
note: lint level defined here
error: statement with no effect
--> $DIR/no_effect.rs:35:5
|
-35 | s2; //~ERROR statement with no effect
+35 | s2;
| ^^^
error: statement with no effect
--> $DIR/no_effect.rs:36:5
|
-36 | Unit; //~ERROR statement with no effect
+36 | Unit;
| ^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:37:5
|
-37 | Tuple(0); //~ERROR statement with no effect
+37 | Tuple(0);
| ^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:38:5
|
-38 | Struct { field: 0 }; //~ERROR statement with no effect
+38 | Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:39:5
|
-39 | Struct { ..s }; //~ERROR statement with no effect
+39 | Struct { ..s };
| ^^^^^^^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:40:5
|
-40 | Union { a: 0 }; //~ERROR statement with no effect
+40 | Union { a: 0 };
| ^^^^^^^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:41:5
|
-41 | Enum::Tuple(0); //~ERROR statement with no effect
+41 | Enum::Tuple(0);
| ^^^^^^^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:42:5
|
-42 | Enum::Struct { field: 0 }; //~ERROR statement with no effect
+42 | Enum::Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:43:5
|
-43 | 5 + 6; //~ERROR statement with no effect
+43 | 5 + 6;
| ^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:44:5
|
-44 | *&42; //~ERROR statement with no effect
+44 | *&42;
| ^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:45:5
|
-45 | &6; //~ERROR statement with no effect
+45 | &6;
| ^^^
error: statement with no effect
--> $DIR/no_effect.rs:46:5
|
-46 | (5, 6, 7); //~ERROR statement with no effect
+46 | (5, 6, 7);
| ^^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:47:5
|
-47 | box 42; //~ERROR statement with no effect
+47 | box 42;
| ^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:48:5
|
-48 | ..; //~ERROR statement with no effect
+48 | ..;
| ^^^
error: statement with no effect
--> $DIR/no_effect.rs:49:5
|
-49 | 5..; //~ERROR statement with no effect
+49 | 5..;
| ^^^^
error: statement with no effect
--> $DIR/no_effect.rs:50:5
|
-50 | ..5; //~ERROR statement with no effect
+50 | ..5;
| ^^^^
error: statement with no effect
--> $DIR/no_effect.rs:51:5
|
-51 | 5..6; //~ERROR statement with no effect
+51 | 5..6;
| ^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:52:5
|
-52 | 5...6; //~ERROR statement with no effect
+52 | 5...6;
| ^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:53:5
|
-53 | [42, 55]; //~ERROR statement with no effect
+53 | [42, 55];
| ^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:54:5
|
-54 | [42, 55][1]; //~ERROR statement with no effect
+54 | [42, 55][1];
| ^^^^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:55:5
|
-55 | (42, 55).1; //~ERROR statement with no effect
+55 | (42, 55).1;
| ^^^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:56:5
|
-56 | [42; 55]; //~ERROR statement with no effect
+56 | [42; 55];
| ^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:57:5
|
-57 | [42; 55][13]; //~ERROR statement with no effect
+57 | [42; 55][13];
| ^^^^^^^^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:59:5
|
-59 | || x += 5; //~ERROR statement with no effect
+59 | || x += 5;
| ^^^^^^^^^^
error: statement can be reduced
--> $DIR/no_effect.rs:65:5
|
-65 | Tuple(get_number()); //~ERROR statement can be reduced
+65 | Tuple(get_number());
| ^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
4 | #![deny(no_effect, unnecessary_operation)]
| ^^^^^^^^^^^^^^^^^^^^^
help: replace it with
- | get_number(); //~ERROR statement can be reduced
+ | get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:68:5
|
-68 | Struct { field: get_number() }; //~ERROR statement can be reduced
+68 | Struct { field: get_number() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: replace it with
- | get_number(); //~ERROR statement can be reduced
+ | get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:71:5
|
-71 | Struct { ..get_struct() }; //~ERROR statement can be reduced
+71 | Struct { ..get_struct() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: replace it with
- | get_struct(); //~ERROR statement can be reduced
+ | get_struct();
error: statement can be reduced
--> $DIR/no_effect.rs:74:5
|
-74 | Enum::Tuple(get_number()); //~ERROR statement can be reduced
+74 | Enum::Tuple(get_number());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: replace it with
- | get_number(); //~ERROR statement can be reduced
+ | get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:77:5
|
-77 | Enum::Struct { field: get_number() }; //~ERROR statement can be reduced
+77 | Enum::Struct { field: get_number() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: replace it with
- | get_number(); //~ERROR statement can be reduced
+ | get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:80:5
|
-80 | 5 + get_number(); //~ERROR statement can be reduced
+80 | 5 + get_number();
| ^^^^^^^^^^^^^^^^^
|
help: replace it with
- | 5;get_number(); //~ERROR statement can be reduced
+ | 5;get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:83:5
|
-83 | *&get_number(); //~ERROR statement can be reduced
+83 | *&get_number();
| ^^^^^^^^^^^^^^^
|
help: replace it with
- | get_number(); //~ERROR statement can be reduced
+ | get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:86:5
|
-86 | &get_number(); //~ERROR statement can be reduced
+86 | &get_number();
| ^^^^^^^^^^^^^^
|
help: replace it with
- | get_number(); //~ERROR statement can be reduced
+ | get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:89:5
|
-89 | (5, 6, get_number()); //~ERROR statement can be reduced
+89 | (5, 6, get_number());
| ^^^^^^^^^^^^^^^^^^^^^
|
help: replace it with
- | 5;6;get_number(); //~ERROR statement can be reduced
+ | 5;6;get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:92:5
|
-92 | box get_number(); //~ERROR statement can be reduced
+92 | box get_number();
| ^^^^^^^^^^^^^^^^^
|
help: replace it with
- | get_number(); //~ERROR statement can be reduced
+ | get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:95:5
|
-95 | get_number()..; //~ERROR statement can be reduced
+95 | get_number()..;
| ^^^^^^^^^^^^^^^
|
help: replace it with
- | get_number(); //~ERROR statement can be reduced
+ | get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:98:5
|
-98 | ..get_number(); //~ERROR statement can be reduced
+98 | ..get_number();
| ^^^^^^^^^^^^^^^
|
help: replace it with
- | get_number(); //~ERROR statement can be reduced
+ | get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:101:5
|
-101 | 5..get_number(); //~ERROR statement can be reduced
+101 | 5..get_number();
| ^^^^^^^^^^^^^^^^
|
help: replace it with
- | 5;get_number(); //~ERROR statement can be reduced
+ | 5;get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:104:5
|
-104 | [42, get_number()]; //~ERROR statement can be reduced
+104 | [42, get_number()];
| ^^^^^^^^^^^^^^^^^^^
|
help: replace it with
- | 42;get_number(); //~ERROR statement can be reduced
+ | 42;get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:107:5
|
-107 | [42, 55][get_number() as usize]; //~ERROR statement can be reduced
+107 | [42, 55][get_number() as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: replace it with
- | [42, 55];get_number() as usize; //~ERROR statement can be reduced
+ | [42, 55];get_number() as usize;
error: statement can be reduced
--> $DIR/no_effect.rs:110:5
|
-110 | (42, get_number()).1; //~ERROR statement can be reduced
+110 | (42, get_number()).1;
| ^^^^^^^^^^^^^^^^^^^^^
|
help: replace it with
- | 42;get_number(); //~ERROR statement can be reduced
+ | 42;get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:113:5
|
-113 | [get_number(); 55]; //~ERROR statement can be reduced
+113 | [get_number(); 55];
| ^^^^^^^^^^^^^^^^^^^
|
help: replace it with
- | get_number(); //~ERROR statement can be reduced
+ | get_number();
error: statement can be reduced
--> $DIR/no_effect.rs:116:5
|
-116 | [42; 55][get_number() as usize]; //~ERROR statement can be reduced
+116 | [42; 55][get_number() as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: replace it with
- | [42; 55];get_number() as usize; //~ERROR statement can be reduced
+ | [42; 55];get_number() as usize;
error: statement can be reduced
--> $DIR/no_effect.rs:119:5
|
-119 | {get_number()}; //~ERROR statement can be reduced
+119 | {get_number()};
| ^^^^^^^^^^^^^^^
|
help: replace it with
- | get_number(); //~ERROR statement can be reduced
+ | get_number();
error: aborting due to 44 previous errors
#![feature(plugin)]
#![plugin(clippy)]
#![deny(clippy,similar_names)]
-//~^ NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
-//~| NOTE: lint level defined here
+
+
+
+
+
+
+
+
+
+
+
#![allow(unused)]
let specter: i32;
let spectre: i32;
- let apple: i32; //~ NOTE: existing binding defined here
- //~^ NOTE: existing binding defined here
- let bpple: i32; //~ ERROR: name is too similar
- //~| HELP: separate the discriminating character by an underscore like: `b_pple`
- let cpple: i32; //~ ERROR: name is too similar
- //~| HELP: separate the discriminating character by an underscore like: `c_pple`
+ let apple: i32;
+
+ let bpple: i32;
+
+ let cpple: i32;
+
let a_bar: i32;
let b_bar: i32;
let blubrhs: i32;
let blublhs: i32;
- let blubx: i32; //~ NOTE: existing binding defined here
- let bluby: i32; //~ ERROR: name is too similar
- //~| HELP: separate the discriminating character by an underscore like: `blub_y`
+ let blubx: i32;
+ let bluby: i32;
+
- let cake: i32; //~ NOTE: existing binding defined here
+ let cake: i32;
let cakes: i32;
- let coke: i32; //~ ERROR: name is too similar
+ let coke: i32;
match 5 {
cheese @ 1 => {},
let ipv6: i32;
let abcd1: i32;
let abdc2: i32;
- let xyz1abc: i32; //~ NOTE: existing binding defined here
+ let xyz1abc: i32;
let xyz2abc: i32;
- let xyzeabc: i32; //~ ERROR: name is too similar
+ let xyzeabc: i32;
- let parser: i32; //~ NOTE: existing binding defined here
+ let parser: i32;
let parsed: i32;
- let parsee: i32; //~ ERROR: name is too similar
- //~| HELP: separate the discriminating character by an underscore like: `parse_e`
+ let parsee: i32;
+
let setter: i32;
let getter: i32;
fn foo() {
let Foo { apple, bpple } = unimplemented!();
- let Foo { apple: spring, //~NOTE existing binding defined here
- bpple: sprang } = unimplemented!(); //~ ERROR: name is too similar
+ let Foo { apple: spring,
+ bpple: sprang } = unimplemented!();
}
#[derive(Clone, Debug)]
let blar: i32;
}
{
- let e: i32; //~ ERROR: 5th binding whose name is just one char
- //~^ NOTE implied by
+ let e: i32;
+
}
{
- let e: i32; //~ ERROR: 5th binding whose name is just one char
- //~^ NOTE implied by
- let f: i32; //~ ERROR: 6th binding whose name is just one char
- //~^ NOTE implied by
+ let e: i32;
+
+ let f: i32;
+
}
match 5 {
1 => println!(""),
- e => panic!(), //~ ERROR: 5th binding whose name is just one char
- //~^ NOTE implied by
+ e => panic!(),
+
}
match 5 {
1 => println!(""),
error: binding's name is too similar to existing binding
--> $DIR/non_expressive_names.rs:29:9
|
-29 | let bpple: i32; //~ ERROR: name is too similar
+29 | let bpple: i32;
| ^^^^^
|
note: lint level defined here
note: existing binding defined here
--> $DIR/non_expressive_names.rs:27:9
|
-27 | let apple: i32; //~ NOTE: existing binding defined here
+27 | let apple: i32;
| ^^^^^
help: separate the discriminating character by an underscore like: `b_pple`
--> $DIR/non_expressive_names.rs:29:9
|
-29 | let bpple: i32; //~ ERROR: name is too similar
+29 | let bpple: i32;
| ^^^^^
error: binding's name is too similar to existing binding
--> $DIR/non_expressive_names.rs:31:9
|
-31 | let cpple: i32; //~ ERROR: name is too similar
+31 | let cpple: i32;
| ^^^^^
|
note: existing binding defined here
--> $DIR/non_expressive_names.rs:27:9
|
-27 | let apple: i32; //~ NOTE: existing binding defined here
+27 | let apple: i32;
| ^^^^^
help: separate the discriminating character by an underscore like: `c_pple`
--> $DIR/non_expressive_names.rs:31:9
|
-31 | let cpple: i32; //~ ERROR: name is too similar
+31 | let cpple: i32;
| ^^^^^
error: binding's name is too similar to existing binding
--> $DIR/non_expressive_names.rs:56:9
|
-56 | let bluby: i32; //~ ERROR: name is too similar
+56 | let bluby: i32;
| ^^^^^
|
note: existing binding defined here
--> $DIR/non_expressive_names.rs:55:9
|
-55 | let blubx: i32; //~ NOTE: existing binding defined here
+55 | let blubx: i32;
| ^^^^^
help: separate the discriminating character by an underscore like: `blub_y`
--> $DIR/non_expressive_names.rs:56:9
|
-56 | let bluby: i32; //~ ERROR: name is too similar
+56 | let bluby: i32;
| ^^^^^
error: binding's name is too similar to existing binding
--> $DIR/non_expressive_names.rs:61:9
|
-61 | let coke: i32; //~ ERROR: name is too similar
+61 | let coke: i32;
| ^^^^
|
note: existing binding defined here
--> $DIR/non_expressive_names.rs:59:9
|
-59 | let cake: i32; //~ NOTE: existing binding defined here
+59 | let cake: i32;
| ^^^^
error: binding's name is too similar to existing binding
--> $DIR/non_expressive_names.rs:79:9
|
-79 | let xyzeabc: i32; //~ ERROR: name is too similar
+79 | let xyzeabc: i32;
| ^^^^^^^
|
note: existing binding defined here
--> $DIR/non_expressive_names.rs:77:9
|
-77 | let xyz1abc: i32; //~ NOTE: existing binding defined here
+77 | let xyz1abc: i32;
| ^^^^^^^
error: binding's name is too similar to existing binding
--> $DIR/non_expressive_names.rs:83:9
|
-83 | let parsee: i32; //~ ERROR: name is too similar
+83 | let parsee: i32;
| ^^^^^^
|
note: existing binding defined here
--> $DIR/non_expressive_names.rs:81:9
|
-81 | let parser: i32; //~ NOTE: existing binding defined here
+81 | let parser: i32;
| ^^^^^^
help: separate the discriminating character by an underscore like: `parse_e`
--> $DIR/non_expressive_names.rs:83:9
|
-83 | let parsee: i32; //~ ERROR: name is too similar
+83 | let parsee: i32;
| ^^^^^^
error: binding's name is too similar to existing binding
--> $DIR/non_expressive_names.rs:97:16
|
-97 | bpple: sprang } = unimplemented!(); //~ ERROR: name is too similar
+97 | bpple: sprang } = unimplemented!();
| ^^^^^^
|
note: existing binding defined here
--> $DIR/non_expressive_names.rs:96:22
|
-96 | let Foo { apple: spring, //~NOTE existing binding defined here
+96 | let Foo { apple: spring,
| ^^^^^^
error: 5th binding whose name is just one char
--> $DIR/non_expressive_names.rs:131:17
|
-131 | let e: i32; //~ ERROR: 5th binding whose name is just one char
+131 | let e: i32;
| ^
|
= note: #[deny(many_single_char_names)] implied by #[deny(clippy)]
error: 5th binding whose name is just one char
--> $DIR/non_expressive_names.rs:135:17
|
-135 | let e: i32; //~ ERROR: 5th binding whose name is just one char
+135 | let e: i32;
| ^
|
= note: #[deny(many_single_char_names)] implied by #[deny(clippy)]
error: 6th binding whose name is just one char
--> $DIR/non_expressive_names.rs:137:17
|
-137 | let f: i32; //~ ERROR: 6th binding whose name is just one char
+137 | let f: i32;
| ^
|
= note: #[deny(many_single_char_names)] implied by #[deny(clippy)]
error: 5th binding whose name is just one char
--> $DIR/non_expressive_names.rs:142:13
|
-142 | e => panic!(), //~ ERROR: 5th binding whose name is just one char
+142 | e => panic!(),
| ^
|
= note: #[deny(many_single_char_names)] implied by #[deny(clippy)]
fn str_to_int(x: &str) -> i32 {
if let Some(y) = x.parse().ok() {
- //~^ERROR Matching on `Some` with `ok()` is redundant
+
y
} else {
0
|
7 | if let Some(y) = x.parse().ok() {
| _____^ starting here...
-8 | | //~^ERROR Matching on `Some` with `ok()` is redundant
+8 | |
9 | | y
10 | | } else {
11 | | 0
#[allow(unused_must_use)]
#[deny(nonsensical_open_options)]
fn main() {
- OpenOptions::new().read(true).truncate(true).open("foo.txt"); //~ERROR file opened with "truncate" and "read"
- OpenOptions::new().append(true).truncate(true).open("foo.txt"); //~ERROR file opened with "append" and "truncate"
+ OpenOptions::new().read(true).truncate(true).open("foo.txt");
+ OpenOptions::new().append(true).truncate(true).open("foo.txt");
- OpenOptions::new().read(true).read(false).open("foo.txt"); //~ERROR the method "read" is called more than once
- OpenOptions::new().create(true).create(false).open("foo.txt"); //~ERROR the method "create" is called more than once
- OpenOptions::new().write(true).write(false).open("foo.txt"); //~ERROR the method "write" is called more than once
- OpenOptions::new().append(true).append(false).open("foo.txt"); //~ERROR the method "append" is called more than once
- OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); //~ERROR the method "truncate" is called more than once
+ OpenOptions::new().read(true).read(false).open("foo.txt");
+ OpenOptions::new().create(true).create(false).open("foo.txt");
+ OpenOptions::new().write(true).write(false).open("foo.txt");
+ OpenOptions::new().append(true).append(false).open("foo.txt");
+ OpenOptions::new().truncate(true).truncate(false).open("foo.txt");
}
error: file opened with "truncate" and "read"
--> $DIR/open_options.rs:8:5
|
-8 | OpenOptions::new().read(true).truncate(true).open("foo.txt"); //~ERROR file opened with "truncate" and "read"
+8 | OpenOptions::new().read(true).truncate(true).open("foo.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: file opened with "append" and "truncate"
--> $DIR/open_options.rs:9:5
|
-9 | OpenOptions::new().append(true).truncate(true).open("foo.txt"); //~ERROR file opened with "append" and "truncate"
+9 | OpenOptions::new().append(true).truncate(true).open("foo.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: the method "read" is called more than once
--> $DIR/open_options.rs:11:5
|
-11 | OpenOptions::new().read(true).read(false).open("foo.txt"); //~ERROR the method "read" is called more than once
+11 | OpenOptions::new().read(true).read(false).open("foo.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: the method "create" is called more than once
--> $DIR/open_options.rs:12:5
|
-12 | OpenOptions::new().create(true).create(false).open("foo.txt"); //~ERROR the method "create" is called more than once
+12 | OpenOptions::new().create(true).create(false).open("foo.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: the method "write" is called more than once
--> $DIR/open_options.rs:13:5
|
-13 | OpenOptions::new().write(true).write(false).open("foo.txt"); //~ERROR the method "write" is called more than once
+13 | OpenOptions::new().write(true).write(false).open("foo.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: the method "append" is called more than once
--> $DIR/open_options.rs:14:5
|
-14 | OpenOptions::new().append(true).append(false).open("foo.txt"); //~ERROR the method "append" is called more than once
+14 | OpenOptions::new().append(true).append(false).open("foo.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: the method "truncate" is called more than once
--> $DIR/open_options.rs:15:5
|
-15 | OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); //~ERROR the method "truncate" is called more than once
+15 | OpenOptions::new().truncate(true).truncate(false).open("foo.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 7 previous errors
let a: u32 = 1;
let b: u32 = 2;
let c: u32 = 3;
- if a + b < a { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust.
+ if a + b < a {
}
- if a > a + b { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust.
+ if a > a + b {
}
- if a + b < b { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust.
+ if a + b < b {
}
- if b > a + b { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust.
+ if b > a + b {
}
- if a - b > b { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust.
+ if a - b > b {
}
- if b < a - b { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust.
+ if b < a - b {
}
- if a - b > a { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust.
+ if a - b > a {
}
- if a < a - b { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust.
+ if a < a - b {
}
if a + b < c {
error: You are trying to use classic C overflow conditions that will fail in Rust.
--> $DIR/overflow_check_conditional.rs:11:5
|
-11 | \tif a + b < a { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust.
+11 | \tif a + b < a {
| \t ^^^^^^^^^
|
note: lint level defined here
error: You are trying to use classic C overflow conditions that will fail in Rust.
--> $DIR/overflow_check_conditional.rs:14:5
|
-14 | \tif a > a + b { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust.
+14 | \tif a > a + b {
| \t ^^^^^^^^^
error: You are trying to use classic C overflow conditions that will fail in Rust.
--> $DIR/overflow_check_conditional.rs:17:5
|
-17 | \tif a + b < b { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust.
+17 | \tif a + b < b {
| \t ^^^^^^^^^
error: You are trying to use classic C overflow conditions that will fail in Rust.
--> $DIR/overflow_check_conditional.rs:20:5
|
-20 | \tif b > a + b { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust.
+20 | \tif b > a + b {
| \t ^^^^^^^^^
error: You are trying to use classic C underflow conditions that will fail in Rust.
--> $DIR/overflow_check_conditional.rs:23:5
|
-23 | \tif a - b > b { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust.
+23 | \tif a - b > b {
| \t ^^^^^^^^^
error: You are trying to use classic C underflow conditions that will fail in Rust.
--> $DIR/overflow_check_conditional.rs:26:5
|
-26 | \tif b < a - b { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust.
+26 | \tif b < a - b {
| \t ^^^^^^^^^
error: You are trying to use classic C underflow conditions that will fail in Rust.
--> $DIR/overflow_check_conditional.rs:29:5
|
-29 | \tif a - b > a { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust.
+29 | \tif a - b > a {
| \t ^^^^^^^^^
error: You are trying to use classic C underflow conditions that will fail in Rust.
--> $DIR/overflow_check_conditional.rs:32:5
|
-32 | \tif a < a - b { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust.
+32 | \tif a < a - b {
| \t ^^^^^^^^^
error: aborting due to 8 previous errors
fn missing() {
if true {
- panic!("{}"); //~ERROR: you probably are missing some parameter
+ panic!("{}");
} else if false {
- panic!("{:?}"); //~ERROR: you probably are missing some parameter
+ panic!("{:?}");
} else {
- assert!(true, "here be missing values: {}"); //~ERROR you probably are missing some parameter
+ assert!(true, "here be missing values: {}");
}
}
error: you probably are missing some parameter in your format string
--> $DIR/panic.rs:8:16
|
-8 | panic!("{}"); //~ERROR: you probably are missing some parameter
+8 | panic!("{}");
| ^^^^
|
note: lint level defined here
error: you probably are missing some parameter in your format string
--> $DIR/panic.rs:10:16
|
-10 | panic!("{:?}"); //~ERROR: you probably are missing some parameter
+10 | panic!("{:?}");
| ^^^^^^
error: you probably are missing some parameter in your format string
--> $DIR/panic.rs:12:23
|
-12 | assert!(true, "here be missing values: {}"); //~ERROR you probably are missing some parameter
+12 | assert!(true, "here be missing values: {}");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors
impl PartialEq for Foo {
fn eq(&self, _: &Foo) -> bool { true }
fn ne(&self, _: &Foo) -> bool { false }
- //~^ ERROR re-implementing `PartialEq::ne` is unnecessary
+
}
fn main() {}
let v = Some(true);
match v {
Some(x) => (),
- y @ _ => (), //~ERROR the `y @ _` pattern can be written as just `y`
+ y @ _ => (),
}
match v {
Some(x) => (),
error: the `y @ _` pattern can be written as just `y`
--> $DIR/patterns.rs:10:9
|
-10 | y @ _ => (), //~ERROR the `y @ _` pattern can be written as just `y`
+10 | y @ _ => (),
| ^^^^^
|
= note: #[deny(redundant_pattern)] implied by #[deny(clippy)]
#[allow(eq_op)]
fn main() {
1 << 2 + 3;
- //~^ ERROR operator precedence can trip
- //~| SUGGESTION 1 << (2 + 3)
+
+
1 + 2 << 3;
- //~^ERROR operator precedence can trip
- //~| SUGGESTION (1 + 2) << 3
+
+
4 >> 1 + 1;
- //~^ERROR operator precedence can trip
- //~| SUGGESTION 4 >> (1 + 1)
+
+
1 + 3 >> 2;
- //~^ERROR operator precedence can trip
- //~| SUGGESTION (1 + 3) >> 2
+
+
1 ^ 1 - 1;
- //~^ERROR operator precedence can trip
- //~| SUGGESTION 1 ^ (1 - 1)
+
+
3 | 2 - 1;
- //~^ERROR operator precedence can trip
- //~| SUGGESTION 3 | (2 - 1)
+
+
3 & 5 - 2;
- //~^ERROR operator precedence can trip
- //~| SUGGESTION 3 & (5 - 2)
+
+
-1i32.abs();
- //~^ERROR unary minus has lower precedence
- //~| SUGGESTION -(1i32.abs())
+
+
-1f32.abs();
- //~^ERROR unary minus has lower precedence
- //~| SUGGESTION -(1f32.abs())
+
+
// These should not trigger an error
let _ = (-1i32).abs();
impl Display for Foo {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "{:?}", 43.1415)
- //~^ ERROR use of `Debug`-based formatting
+
}
}
}
fn main() {
- println!("Hello"); //~ERROR use of `println!`
- print!("Hello"); //~ERROR use of `print!`
+ println!("Hello");
+ print!("Hello");
- print!("Hello {}", "World"); //~ERROR use of `print!`
+ print!("Hello {}", "World");
print!("Hello {:?}", "World");
- //~^ ERROR use of `print!`
- //~| ERROR use of `Debug`-based formatting
+
+
print!("Hello {:#?}", "#orld");
- //~^ ERROR use of `print!`
- //~| ERROR use of `Debug`-based formatting
+
+
assert_eq!(42, 1337);
error: use of `println!`
--> $DIR/print.rs:25:5
|
-25 | println!("Hello"); //~ERROR use of `println!`
+25 | println!("Hello");
| ^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: use of `print!`
--> $DIR/print.rs:26:5
|
-26 | print!("Hello"); //~ERROR use of `print!`
+26 | print!("Hello");
| ^^^^^^^^^^^^^^^^
error: use of `print!`
--> $DIR/print.rs:28:5
|
-28 | print!("Hello {}", "World"); //~ERROR use of `print!`
+28 | print!("Hello {}", "World");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: use of `print!`
#![deny(print_with_newline)]
fn main() {
- print!("Hello\n"); //~ERROR using `print!()` with a format string
- print!("Hello {}\n", "world"); //~ERROR using `print!()` with a format string
- print!("Hello {} {}\n\n", "world", "#2"); //~ERROR using `print!()` with a format string
- print!("{}\n", 1265); //~ERROR using `print!()` with a format string
+ print!("Hello\n");
+ print!("Hello {}\n", "world");
+ print!("Hello {} {}\n\n", "world", "#2");
+ print!("{}\n", 1265);
// these are all fine
print!("");
error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead
--> $DIR/print_with_newline.rs:6:5
|
-6 | print!("Hello/n"); //~ERROR using `print!()` with a format string
+6 | print!("Hello/n");
| ^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead
--> $DIR/print_with_newline.rs:7:5
|
-7 | print!("Hello {}/n", "world"); //~ERROR using `print!()` with a format string
+7 | print!("Hello {}/n", "world");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead
--> $DIR/print_with_newline.rs:8:5
|
-8 | print!("Hello {} {}/n/n", "world", "#2"); //~ERROR using `print!()` with a format string
+8 | print!("Hello {} {}/n/n", "world", "#2");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead
--> $DIR/print_with_newline.rs:9:5
|
-9 | print!("{}/n", 1265); //~ERROR using `print!()` with a format string
+9 | print!("{}/n", 1265);
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors
#![allow(unused)]
#![deny(ptr_arg)]
-fn do_vec(x: &Vec<i64>) { //~ERROR writing `&Vec<_>` instead of `&[_]`
+fn do_vec(x: &Vec<i64>) {
//Nothing here
}
//Nothing here
}
-fn do_str(x: &String) { //~ERROR writing `&String` instead of `&str`
+fn do_str(x: &String) {
//Nothing here either
}
trait Foo {
type Item;
- fn do_vec(x: &Vec<i64>); //~ERROR writing `&Vec<_>`
+ fn do_vec(x: &Vec<i64>);
fn do_item(x: &Self::Item);
}
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices. Consider changing the type to `&[...]`
--> $DIR/ptr_arg.rs:6:14
|
-6 | fn do_vec(x: &Vec<i64>) { //~ERROR writing `&Vec<_>` instead of `&[_]`
+6 | fn do_vec(x: &Vec<i64>) {
| ^^^^^^^^^
|
note: lint level defined here
error: writing `&String` instead of `&str` involves a new object where a slice will do. Consider changing the type to `&str`
--> $DIR/ptr_arg.rs:14:14
|
-14 | fn do_str(x: &String) { //~ERROR writing `&String` instead of `&str`
+14 | fn do_str(x: &String) {
| ^^^^^^^
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices. Consider changing the type to `&[...]`
--> $DIR/ptr_arg.rs:27:18
|
-27 | fn do_vec(x: &Vec<i64>); //~ERROR writing `&Vec<_>`
+27 | fn do_vec(x: &Vec<i64>);
| ^^^^^^^^^
error: aborting due to 3 previous errors
#[deny(range_step_by_zero, range_zip_with_len)]
fn main() {
- (0..1).step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator
+ (0..1).step_by(0);
// No warning for non-zero step
(0..1).step_by(1);
- (1..).step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator
- (1...2).step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator
+ (1..).step_by(0);
+ (1...2).step_by(0);
let x = 0..1;
- x.step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator
+ x.step_by(0);
// No error, not a range.
let y = NotARange;
let v1 = vec![1,2,3];
let v2 = vec![4,5];
- let _x = v1.iter().zip(0..v1.len()); //~ERROR It is more idiomatic to use v1.iter().enumerate()
+ let _x = v1.iter().zip(0..v1.len());
let _y = v1.iter().zip(0..v2.len()); // No error
}
error: Range::step_by(0) produces an infinite iterator. Consider using `std::iter::repeat()` instead
--> $DIR/range.rs:13:5
|
-13 | (0..1).step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator
+13 | (0..1).step_by(0);
| ^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: Range::step_by(0) produces an infinite iterator. Consider using `std::iter::repeat()` instead
--> $DIR/range.rs:17:5
|
-17 | (1..).step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator
+17 | (1..).step_by(0);
| ^^^^^^^^^^^^^^^^
error: Range::step_by(0) produces an infinite iterator. Consider using `std::iter::repeat()` instead
--> $DIR/range.rs:18:5
|
-18 | (1...2).step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator
+18 | (1...2).step_by(0);
| ^^^^^^^^^^^^^^^^^^
error: Range::step_by(0) produces an infinite iterator. Consider using `std::iter::repeat()` instead
--> $DIR/range.rs:21:5
|
-21 | x.step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator
+21 | x.step_by(0);
| ^^^^^^^^^^^^
error: It is more idiomatic to use v1.iter().enumerate()
--> $DIR/range.rs:29:14
|
-29 | let _x = v1.iter().zip(0..v1.len()); //~ERROR It is more idiomatic to use v1.iter().enumerate()
+29 | let _x = v1.iter().zip(0..v1.len());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
fn main() {
let a = (|| 42)();
- //~^ ERROR Try not to call a closure in the expression where it is declared.
- //~| HELP Try doing something like:
- //~| SUGGESTION let a = 42;
+
+
+
let mut i = 1;
- let k = (|m| m+1)(i); //~ERROR Try not to call a closure in the expression where it is declared.
+ let k = (|m| m+1)(i);
- k = (|a,b| a*b)(1,5); //~ERROR Try not to call a closure in the expression where it is declared.
+ k = (|a,b| a*b)(1,5);
let closure = || 32;
- i = closure(); //~ERROR Closure called just once immediately after it was declared
+ i = closure();
let closure = |i| i+1;
- i = closure(3); //~ERROR Closure called just once immediately after it was declared
+ i = closure(3);
i = closure(4);
}
error: Closure called just once immediately after it was declared
--> $DIR/redundant_closure_call.rs:18:2
|
-18 | \ti = closure(); //~ERROR Closure called just once immediately after it was declared
+18 | \ti = closure();
| \t^^^^^^^^^^^^^
|
note: lint level defined here
error: Closure called just once immediately after it was declared
--> $DIR/redundant_closure_call.rs:21:2
|
-21 | \ti = closure(3); //~ERROR Closure called just once immediately after it was declared
+21 | \ti = closure(3);
| \t^^^^^^^^^^^^^^
error: Try not to call a closure in the expression where it is declared.
error: Try not to call a closure in the expression where it is declared.
--> $DIR/redundant_closure_call.rs:13:10
|
-13 | \tlet k = (|m| m+1)(i); //~ERROR Try not to call a closure in the expression where it is declared.
+13 | \tlet k = (|m| m+1)(i);
| \t ^^^^^^^^^^^^
error: Try not to call a closure in the expression where it is declared.
--> $DIR/redundant_closure_call.rs:15:6
|
-15 | \tk = (|a,b| a*b)(1,5); //~ERROR Try not to call a closure in the expression where it is declared.
+15 | \tk = (|a,b| a*b)(1,5);
| \t ^^^^^^^^^^^^^^^^
error: aborting due to 5 previous errors
let aref = &a;
let b = *&a;
- //~^ERROR immediately dereferencing a reference
- //~|HELP try this
- //~|SUGGESTION let b = a;
+
+
+
let b = *&get_number();
- //~^ERROR immediately dereferencing a reference
- //~|HELP try this
- //~|SUGGESTION let b = get_number();
+
+
+
let b = *get_reference(&a);
let bytes : Vec<usize> = vec![1, 2, 3, 4];
let b = *&bytes[1..2][0];
- //~^ERROR immediately dereferencing a reference
- //~|HELP try this
- //~|SUGGESTION let b = bytes[1..2][0];
+
+
+
//This produces a suggestion of 'let b = (a);' which
//will trigger the 'unused_parens' lint
let b = *&(a);
- //~^ERROR immediately dereferencing a reference
- //~|HELP try this
- //~|SUGGESTION let b = (a)
+
+
+
let b = *(&a);
- //~^ERROR immediately dereferencing a reference
- //~|HELP try this
- //~|SUGGESTION let b = a;
+
+
+
let b = *((&a));
- //~^ERROR immediately dereferencing a reference
- //~|HELP try this
- //~|SUGGESTION let b = a
+
+
+
let b = *&&a;
- //~^ERROR immediately dereferencing a reference
- //~|HELP try this
- //~|SUGGESTION let b = &a;
+
+
+
let b = **&aref;
- //~^ERROR immediately dereferencing a reference
- //~|HELP try this
- //~|SUGGESTION let b = *aref;
+
+
+
//This produces a suggestion of 'let b = *&a;' which
//will trigger the 'deref_addrof' lint again
let b = **&&a;
- //~^ERROR immediately dereferencing a reference
- //~|HELP try this
- //~|SUGGESTION let b = *&a;
+
+
+
{
let mut x = 10;
let y = *&mut x;
- //~^ERROR immediately dereferencing a reference
- //~|HELP try this
- //~|SUGGESTION let y = x;
+
+
+
}
{
//will trigger the 'deref_addrof' lint again
let mut x = 10;
let y = **&mut &mut x;
- //~^ERROR immediately dereferencing a reference
- //~|HELP try this
- //~|SUGGESTION let y = *&mut x;
+
+
+
}
}
fn syntax_error() {
let pipe_in_wrong_position = Regex::new("|");
- //~^ERROR: regex syntax error: empty alternate
+
let pipe_in_wrong_position_builder = RegexBuilder::new("|");
- //~^ERROR: regex syntax error: empty alternate
+
let wrong_char_ranice = Regex::new("[z-a]");
- //~^ERROR: regex syntax error: invalid character class range
+
let some_unicode = Regex::new("[é-è]");
- //~^ERROR: regex syntax error: invalid character class range
+
let some_regex = Regex::new(OPENING_PAREN);
- //~^ERROR: regex syntax error on position 0: unclosed
+
let binary_pipe_in_wrong_position = BRegex::new("|");
- //~^ERROR: regex syntax error: empty alternate
+
let some_binary_regex = BRegex::new(OPENING_PAREN);
- //~^ERROR: regex syntax error on position 0: unclosed
+
let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN);
- //~^ERROR: regex syntax error on position 0: unclosed
+
let closing_paren = ")";
let not_linted = Regex::new(closing_paren);
let set_error = RegexSet::new(&[
OPENING_PAREN,
- //~^ERROR: regex syntax error on position 0: unclosed
+
r"[a-z]+\.(com|org|net)",
]);
let bset_error = BRegexSet::new(&[
OPENING_PAREN,
- //~^ERROR: regex syntax error on position 0: unclosed
+
r"[a-z]+\.(com|org|net)",
]);
}
fn trivial_regex() {
let trivial_eq = Regex::new("^foobar$");
- //~^ERROR: trivial regex
- //~|HELP consider using `==` on `str`s
+
+
let trivial_eq_builder = RegexBuilder::new("^foobar$");
- //~^ERROR: trivial regex
- //~|HELP consider using `==` on `str`s
+
+
let trivial_starts_with = Regex::new("^foobar");
- //~^ERROR: trivial regex
- //~|HELP consider using `str::starts_with`
+
+
let trivial_ends_with = Regex::new("foobar$");
- //~^ERROR: trivial regex
- //~|HELP consider using `str::ends_with`
+
+
let trivial_contains = Regex::new("foobar");
- //~^ERROR: trivial regex
- //~|HELP consider using `str::contains`
+
+
let trivial_contains = Regex::new(NOT_A_REAL_REGEX);
- //~^ERROR: trivial regex
- //~|HELP consider using `str::contains`
+
+
let trivial_backslash = Regex::new("a\\.b");
- //~^ERROR: trivial regex
- //~|HELP consider using `str::contains`
+
+
// unlikely corner cases
let trivial_empty = Regex::new("");
- //~^ERROR: trivial regex
- //~|HELP the regex is unlikely to be useful
+
+
let trivial_empty = Regex::new("^");
- //~^ERROR: trivial regex
- //~|HELP the regex is unlikely to be useful
+
+
let trivial_empty = Regex::new("^$");
- //~^ERROR: trivial regex
- //~|HELP consider using `str::is_empty`
+
+
let binary_trivial_empty = BRegex::new("^$");
- //~^ERROR: trivial regex
- //~|HELP consider using `str::is_empty`
+
+
// non-trivial regexes
let non_trivial_dot = Regex::new("a.b");
}
fn visit_string<E>(self, _v: String) -> Result<Self::Value, E>
- //~^ ERROR you should not implement `visit_string` without also implementing `visit_str`
+
where E: serde::de::Error,
{
unimplemented!()
|
39 | fn visit_string<E>(self, _v: String) -> Result<Self::Value, E>
| _____^ starting here...
-40 | | //~^ ERROR you should not implement `visit_string` without also implementing `visit_str`
+40 | |
41 | | where E: serde::de::Error,
42 | | {
43 | | unimplemented!()
fn main() {
let mut x = 1;
- let x = &mut x; //~ERROR `x` is shadowed by itself in `&mut x`
- let x = { x }; //~ERROR `x` is shadowed by itself in `{ x }`
- let x = (&*x); //~ERROR `x` is shadowed by itself in `(&*x)`
- let x = { *x + 1 }; //~ERROR `x` is shadowed by `{ *x + 1 }` which reuses
- let x = id(x); //~ERROR `x` is shadowed by `id(x)` which reuses
- let x = (1, x); //~ERROR `x` is shadowed by `(1, x)` which reuses
- let x = first(x); //~ERROR `x` is shadowed by `first(x)` which reuses
+ let x = &mut x;
+ let x = { x };
+ let x = (&*x);
+ let x = { *x + 1 };
+ let x = id(x);
+ let x = (1, x);
+ let x = first(x);
let y = 1;
- let x = y; //~ERROR `x` is shadowed by `y`
+ let x = y;
- let x; //~ERROR `x` shadows a previous declaration
+ let x;
x = 42;
let o = Some(1_u8);
error: `x` is shadowed by itself in `&mut x`
--> $DIR/shadow.rs:13:9
|
-13 | let x = &mut x; //~ERROR `x` is shadowed by itself in `&mut x`
+13 | let x = &mut x;
| ^^^^^^^^^^
|
= note: #[deny(shadow_same)] implied by #[deny(clippy_pedantic)]
error: `x` is shadowed by itself in `{ x }`
--> $DIR/shadow.rs:14:9
|
-14 | let x = { x }; //~ERROR `x` is shadowed by itself in `{ x }`
+14 | let x = { x };
| ^^^^^^^^^
|
= note: #[deny(shadow_same)] implied by #[deny(clippy_pedantic)]
note: previous binding is here
--> $DIR/shadow.rs:13:9
|
-13 | let x = &mut x; //~ERROR `x` is shadowed by itself in `&mut x`
+13 | let x = &mut x;
| ^
error: `x` is shadowed by itself in `(&*x)`
--> $DIR/shadow.rs:15:9
|
-15 | let x = (&*x); //~ERROR `x` is shadowed by itself in `(&*x)`
+15 | let x = (&*x);
| ^^^^^^^^^
|
= note: #[deny(shadow_same)] implied by #[deny(clippy_pedantic)]
note: previous binding is here
--> $DIR/shadow.rs:14:9
|
-14 | let x = { x }; //~ERROR `x` is shadowed by itself in `{ x }`
+14 | let x = { x };
| ^
error: `x` is shadowed by `{ *x + 1 }` which reuses the original value
--> $DIR/shadow.rs:16:9
|
-16 | let x = { *x + 1 }; //~ERROR `x` is shadowed by `{ *x + 1 }` which reuses
+16 | let x = { *x + 1 };
| ^
|
= note: #[deny(shadow_reuse)] implied by #[deny(clippy_pedantic)]
note: initialization happens here
--> $DIR/shadow.rs:16:13
|
-16 | let x = { *x + 1 }; //~ERROR `x` is shadowed by `{ *x + 1 }` which reuses
+16 | let x = { *x + 1 };
| ^^^^^^^^^^
note: previous binding is here
--> $DIR/shadow.rs:15:9
|
-15 | let x = (&*x); //~ERROR `x` is shadowed by itself in `(&*x)`
+15 | let x = (&*x);
| ^
error: `x` is shadowed by `id(x)` which reuses the original value
--> $DIR/shadow.rs:17:9
|
-17 | let x = id(x); //~ERROR `x` is shadowed by `id(x)` which reuses
+17 | let x = id(x);
| ^
|
= note: #[deny(shadow_reuse)] implied by #[deny(clippy_pedantic)]
note: initialization happens here
--> $DIR/shadow.rs:17:13
|
-17 | let x = id(x); //~ERROR `x` is shadowed by `id(x)` which reuses
+17 | let x = id(x);
| ^^^^^
note: previous binding is here
--> $DIR/shadow.rs:16:9
|
-16 | let x = { *x + 1 }; //~ERROR `x` is shadowed by `{ *x + 1 }` which reuses
+16 | let x = { *x + 1 };
| ^
error: `x` is shadowed by `(1, x)` which reuses the original value
--> $DIR/shadow.rs:18:9
|
-18 | let x = (1, x); //~ERROR `x` is shadowed by `(1, x)` which reuses
+18 | let x = (1, x);
| ^
|
= note: #[deny(shadow_reuse)] implied by #[deny(clippy_pedantic)]
note: initialization happens here
--> $DIR/shadow.rs:18:13
|
-18 | let x = (1, x); //~ERROR `x` is shadowed by `(1, x)` which reuses
+18 | let x = (1, x);
| ^^^^^^
note: previous binding is here
--> $DIR/shadow.rs:17:9
|
-17 | let x = id(x); //~ERROR `x` is shadowed by `id(x)` which reuses
+17 | let x = id(x);
| ^
error: `x` is shadowed by `first(x)` which reuses the original value
--> $DIR/shadow.rs:19:9
|
-19 | let x = first(x); //~ERROR `x` is shadowed by `first(x)` which reuses
+19 | let x = first(x);
| ^
|
= note: #[deny(shadow_reuse)] implied by #[deny(clippy_pedantic)]
note: initialization happens here
--> $DIR/shadow.rs:19:13
|
-19 | let x = first(x); //~ERROR `x` is shadowed by `first(x)` which reuses
+19 | let x = first(x);
| ^^^^^^^^
note: previous binding is here
--> $DIR/shadow.rs:18:9
|
-18 | let x = (1, x); //~ERROR `x` is shadowed by `(1, x)` which reuses
+18 | let x = (1, x);
| ^
error: `x` is shadowed by `y`
--> $DIR/shadow.rs:21:9
|
-21 | let x = y; //~ERROR `x` is shadowed by `y`
+21 | let x = y;
| ^
|
= note: #[deny(shadow_unrelated)] implied by #[deny(clippy_pedantic)]
note: initialization happens here
--> $DIR/shadow.rs:21:13
|
-21 | let x = y; //~ERROR `x` is shadowed by `y`
+21 | let x = y;
| ^
note: previous binding is here
--> $DIR/shadow.rs:19:9
|
-19 | let x = first(x); //~ERROR `x` is shadowed by `first(x)` which reuses
+19 | let x = first(x);
| ^
error: `x` shadows a previous declaration
--> $DIR/shadow.rs:23:9
|
-23 | let x; //~ERROR `x` shadows a previous declaration
+23 | let x;
| ^
|
= note: #[deny(shadow_unrelated)] implied by #[deny(clippy_pedantic)]
note: previous binding is here
--> $DIR/shadow.rs:21:9
|
-21 | let x = y; //~ERROR `x` is shadowed by `y`
+21 | let x = y;
| ^
error: aborting due to 9 previous errors
fn main() {
f() && g();
- //~^ ERROR boolean short circuit operator
- //~| HELP replace it with
- //~| SUGGESTION if f() { g(); }
+
+
+
f() || g();
- //~^ ERROR boolean short circuit operator
- //~| HELP replace it with
- //~| SUGGESTION if !f() { g(); }
+
+
+
1 == 2 || g();
- //~^ ERROR boolean short circuit operator
- //~| HELP replace it with
- //~| SUGGESTION if !(1 == 2) { g(); }
+
+
+
}
fn f() -> bool {
let mut x = "".to_owned();
for _ in 1..3 {
- x = x + "."; //~ERROR you added something to a string.
+ x = x + ".";
}
let y = "".to_owned();
- let z = y + "..."; //~ERROR you added something to a string.
+ let z = y + "...";
assert_eq!(&x, &z);
}
let mut x = "".to_owned();
for _ in 1..3 {
- x = x + "."; //~ERROR you assigned the result of adding something to this string.
+ x = x + ".";
}
let y = "".to_owned();
let mut x = "".to_owned();
for _ in 1..3 {
- x = x + "."; //~ERROR you assigned the result of adding something to this string.
+ x = x + ".";
}
let y = "".to_owned();
- let z = y + "..."; //~ERROR you added something to a string.
+ let z = y + "...";
assert_eq!(&x, &z);
}
#[deny(string_lit_as_bytes)]
fn str_lit_as_bytes() {
let bs = "hello there".as_bytes();
- //~^ERROR calling `as_bytes()`
- //~|HELP byte string literal
- //~|SUGGESTION b"hello there"
+
+
+
// no warning, because this cannot be written as a byte string literal:
let ubs = "☃".as_bytes();
// the add is only caught for `String`
let mut x = 1;
; x = x + 1;
- //~^ WARN manual implementation of an assign operation
- //~| HELP replace
- //~| SUGGESTION ; x += 1;
+
+
+
assert_eq!(2, x);
}
error: you added something to a string. Consider using `String::push_str()` instead
--> $DIR/strings.rs:10:13
|
-10 | x = x + "."; //~ERROR you added something to a string.
+10 | x = x + ".";
| ^^^^^^^
|
note: lint level defined here
error: you added something to a string. Consider using `String::push_str()` instead
--> $DIR/strings.rs:14:13
|
-14 | let z = y + "..."; //~ERROR you added something to a string.
+14 | let z = y + "...";
| ^^^^^^^^^
error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead
--> $DIR/strings.rs:24:9
|
-24 | x = x + "."; //~ERROR you assigned the result of adding something to this string.
+24 | x = x + ".";
| ^^^^^^^^^^^
|
note: lint level defined here
error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead
--> $DIR/strings.rs:38:9
|
-38 | x = x + "."; //~ERROR you assigned the result of adding something to this string.
+38 | x = x + ".";
| ^^^^^^^^^^^
|
note: lint level defined here
error: you added something to a string. Consider using `String::push_str()` instead
--> $DIR/strings.rs:42:13
|
-42 | let z = y + "..."; //~ERROR you added something to a string.
+42 | let z = y + "...";
| ^^^^^^^^^
|
note: lint level defined here
mod foo {
pub fn foo() {}
- pub fn foo_bar() {} //~ ERROR: item name starts with its containing module's name
- pub fn bar_foo() {} //~ ERROR: item name ends with its containing module's name
- pub struct FooCake {} //~ ERROR: item name starts with its containing module's name
- pub enum CakeFoo {} //~ ERROR: item name ends with its containing module's name
+ pub fn foo_bar() {}
+ pub fn bar_foo() {}
+ pub struct FooCake {}
+ pub enum CakeFoo {}
}
fn main() {}
error: item name starts with its containing module's name
--> $DIR/stutter.rs:8:5
|
-8 | pub fn foo_bar() {} //~ ERROR: item name starts with its containing module's name
+8 | pub fn foo_bar() {}
| ^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: item name ends with its containing module's name
--> $DIR/stutter.rs:9:5
|
-9 | pub fn bar_foo() {} //~ ERROR: item name ends with its containing module's name
+9 | pub fn bar_foo() {}
| ^^^^^^^^^^^^^^^^^^^
error: item name starts with its containing module's name
--> $DIR/stutter.rs:10:5
|
-10 | pub struct FooCake {} //~ ERROR: item name starts with its containing module's name
+10 | pub struct FooCake {}
| ^^^^^^^^^^^^^^^^^^^^^
error: item name ends with its containing module's name
--> $DIR/stutter.rs:11:5
|
-11 | pub enum CakeFoo {} //~ ERROR: item name ends with its containing module's name
+11 | pub enum CakeFoo {}
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors
fn array() {
let mut foo = [1, 2];
- let temp = foo[0]; //~ NOTE implied by
+ let temp = foo[0];
foo[0] = foo[1];
foo[1] = temp;
- //~^^^ ERROR this looks like you are swapping elements of `foo` manually
- //~| HELP try
- //~| SUGGESTION foo.swap(0, 1);
+
+
+
foo.swap(0, 1);
}
fn slice() {
let foo = &mut [1, 2];
- let temp = foo[0]; //~ NOTE implied by
+ let temp = foo[0];
foo[0] = foo[1];
foo[1] = temp;
- //~^^^ ERROR this looks like you are swapping elements of `foo` manually
- //~| HELP try
- //~| SUGGESTION foo.swap(0, 1);
+
+
+
foo.swap(0, 1);
}
fn vec() {
let mut foo = vec![1, 2];
- let temp = foo[0]; //~ NOTE implied by
+ let temp = foo[0];
foo[0] = foo[1];
foo[1] = temp;
- //~^^^ ERROR this looks like you are swapping elements of `foo` manually
- //~| HELP try
- //~| SUGGESTION foo.swap(0, 1);
+
+
+
foo.swap(0, 1);
}
let mut a = 42;
let mut b = 1337;
- a = b; //~ NOTE implied by
+ a = b;
b = a;
- //~^^ ERROR this looks like you are trying to swap `a` and `b`
- //~| HELP try
- //~| SUGGESTION std::mem::swap(&mut a, &mut b);
- //~| NOTE or maybe you should use `std::mem::replace`?
- ; let t = a; //~ NOTE implied by
+
+
+
+
+ ; let t = a;
a = b;
b = t;
- //~^^^ ERROR this looks like you are swapping `a` and `b` manually
- //~| HELP try
- //~| SUGGESTION ; std::mem::swap(&mut a, &mut b);
- //~| NOTE or maybe you should use `std::mem::replace`?
+
+
+
+
let mut c = Foo(42);
- c.0 = a; //~ NOTE implied by
+ c.0 = a;
a = c.0;
- //~^^ ERROR this looks like you are trying to swap `c.0` and `a`
- //~| HELP try
- //~| SUGGESTION std::mem::swap(&mut c.0, &mut a);
- //~| NOTE or maybe you should use `std::mem::replace`?
- ; let t = c.0; //~ NOTE implied by
+
+
+
+
+ ; let t = c.0;
c.0 = a;
a = t;
- //~^^^ ERROR this looks like you are swapping `c.0` and `a` manually
- //~| HELP try
- //~| SUGGESTION ; std::mem::swap(&mut c.0, &mut a);
- //~| NOTE or maybe you should use `std::mem::replace`?
+
+
+
+
}
error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:11:5
|
-11 | let temp = foo[0]; //~ NOTE implied by
+11 | let temp = foo[0];
| _____^ starting here...
12 | | foo[0] = foo[1];
13 | | foo[1] = temp;
error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:23:5
|
-23 | let temp = foo[0]; //~ NOTE implied by
+23 | let temp = foo[0];
| _____^ starting here...
24 | | foo[0] = foo[1];
25 | | foo[1] = temp;
error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:35:5
|
-35 | let temp = foo[0]; //~ NOTE implied by
+35 | let temp = foo[0];
| _____^ starting here...
36 | | foo[0] = foo[1];
37 | | foo[1] = temp;
error: this looks like you are swapping `a` and `b` manually
--> $DIR/swap.rs:60:7
|
-60 | ; let t = a; //~ NOTE implied by
+60 | ; let t = a;
| _______^ starting here...
61 | | a = b;
62 | | b = t;
error: this looks like you are swapping `c.0` and `a` manually
--> $DIR/swap.rs:77:7
|
-77 | ; let t = c.0; //~ NOTE implied by
+77 | ; let t = c.0;
| _______^ starting here...
78 | | c.0 = a;
79 | | a = t;
error: this looks like you are trying to swap `a` and `b`
--> $DIR/swap.rs:53:5
|
-53 | a = b; //~ NOTE implied by
+53 | a = b;
| _____^ starting here...
54 | | b = a;
| |_________^ ...ending here
error: this looks like you are trying to swap `c.0` and `a`
--> $DIR/swap.rs:70:5
|
-70 | c.0 = a; //~ NOTE implied by
+70 | c.0 = a;
| _____^ starting here...
71 | | a = c.0;
| |___________^ ...ending here
let mut s = Struct { field: 0 };
let mut t = (0, 0);
- Struct { field: 0 }.field = 1; //~ERROR assignment to temporary
- (0, 0).0 = 1; //~ERROR assignment to temporary
+ Struct { field: 0 }.field = 1;
+ (0, 0).0 = 1;
// no error
s.field = 1;
error: assignment to temporary
--> $DIR/temporary_assignment.rs:29:5
|
-29 | Struct { field: 0 }.field = 1; //~ERROR assignment to temporary
+29 | Struct { field: 0 }.field = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: assignment to temporary
--> $DIR/temporary_assignment.rs:30:5
|
-30 | (0, 0).0 = 1; //~ERROR assignment to temporary
+30 | (0, 0).0 = 1;
| ^^^^^^^^^^^^
error: aborting due to 2 previous errors
#![deny(clippy)]
#![allow(unused)]
-fn the_answer(ref mut x: u8) { //~ ERROR `ref` directly on a function argument is ignored
+fn the_answer(ref mut x: u8) {
*x = 42;
}
y(1u8);
let ref x = 1;
- //~^ ERROR `ref` on an entire `let` pattern is discouraged
- //~| HELP try
- //~| SUGGESTION let x = &1;
+
+
+
let ref y: (&_, u8) = (&1, 2);
- //~^ ERROR `ref` on an entire `let` pattern is discouraged
- //~| HELP try
- //~| SUGGESTION let y: &(&_, u8) = &(&1, 2);
+
+
+
let ref z = 1 + 2;
- //~^ ERROR `ref` on an entire `let` pattern is discouraged
- //~| HELP try
- //~| SUGGESTION let z = &(1 + 2);
+
+
+
let ref mut z = 1 + 2;
- //~^ ERROR `ref` on an entire `let` pattern is discouraged
- //~| HELP try
- //~| SUGGESTION let z = &mut (1 + 2);
+
+
+
let (ref x, _) = (1,2); // okay, not top level
println!("The answer is {}.", x);
error: `ref` directly on a function argument is ignored. Consider using a reference type instead.
--> $DIR/toplevel_ref_arg.rs:7:15
|
-7 | fn the_answer(ref mut x: u8) { //~ ERROR `ref` directly on a function argument is ignored
+7 | fn the_answer(ref mut x: u8) {
| ^^^^^^^^^
|
= note: #[deny(toplevel_ref_arg)] implied by #[deny(clippy)]
#[deny(useless_transmute)]
unsafe fn _generic<'a, T, U: 'a>(t: &'a T) {
let _: &'a T = core::intrinsics::transmute(t);
- //~^ ERROR transmute from a type (`&'a T`) to itself
+
let _: &'a U = core::intrinsics::transmute(t);
let _: *const T = core::intrinsics::transmute(t);
- //~^ ERROR transmute from a reference to a pointer
- //~| HELP try
- //~| SUGGESTION = t as *const T
+
+
+
let _: *mut T = core::intrinsics::transmute(t);
- //~^ ERROR transmute from a reference to a pointer
- //~| HELP try
- //~| SUGGESTION = t as *const T as *mut T
+
+
+
let _: *const U = core::intrinsics::transmute(t);
- //~^ ERROR transmute from a reference to a pointer
- //~| HELP try
- //~| SUGGESTION = t as *const T as *const U
+
+
+
}
#[deny(transmute_ptr_to_ref)]
unsafe fn _ptr_to_ref<T, U>(p: *const T, m: *mut T, o: *const U, om: *mut U) {
let _: &T = std::mem::transmute(p);
- //~^ ERROR transmute from a pointer type (`*const T`) to a reference type (`&T`)
- //~| HELP try
- //~| SUGGESTION = &*p;
+
+
+
let _: &T = &*p;
let _: &mut T = std::mem::transmute(m);
- //~^ ERROR transmute from a pointer type (`*mut T`) to a reference type (`&mut T`)
- //~| HELP try
- //~| SUGGESTION = &mut *m;
+
+
+
let _: &mut T = &mut *m;
let _: &T = std::mem::transmute(m);
- //~^ ERROR transmute from a pointer type (`*mut T`) to a reference type (`&T`)
- //~| HELP try
- //~| SUGGESTION = &*m;
+
+
+
let _: &T = &*m;
let _: &mut T = std::mem::transmute(p as *mut T);
- //~^ ERROR transmute from a pointer type (`*mut T`) to a reference type (`&mut T`)
- //~| HELP try
- //~| SUGGESTION = &mut *(p as *mut T);
+
+
+
let _ = &mut *(p as *mut T);
let _: &T = std::mem::transmute(o);
- //~^ ERROR transmute from a pointer type (`*const U`) to a reference type (`&T`)
- //~| HELP try
- //~| SUGGESTION = &*(o as *const T);
+
+
+
let _: &T = &*(o as *const T);
let _: &mut T = std::mem::transmute(om);
- //~^ ERROR transmute from a pointer type (`*mut U`) to a reference type (`&mut T`)
- //~| HELP try
- //~| SUGGESTION = &mut *(om as *mut T);
+
+
+
let _: &mut T = &mut *(om as *mut T);
let _: &T = std::mem::transmute(om);
- //~^ ERROR transmute from a pointer type (`*mut U`) to a reference type (`&T`)
- //~| HELP try
- //~| SUGGESTION = &*(om as *const T);
+
+
+
let _: &T = &*(om as *const T);
}
let raw = 0 as *const i32;
let _: &Foo<u8> = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) };
- //~^ ERROR transmute from a pointer type
- //~| HELP try
- //~| SUGGESTION unsafe { &*(raw as *const Foo<_>) };
+
+
+
let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) };
- //~^ ERROR transmute from a pointer type
- //~| HELP try
- //~| SUGGESTION unsafe { &*(raw as *const Foo<&_>) };
+
+
+
type Bar<'a> = &'a u8;
let raw = 0 as *const i32;
unsafe { std::mem::transmute::<_, Bar>(raw) };
- //~^ ERROR transmute from a pointer type
- //~| HELP try
- //~| SUGGESTION unsafe { &*(raw as *const u8) };
+
+
+
}
#[deny(useless_transmute)]
fn useless() {
unsafe {
let _: Vec<i32> = core::intrinsics::transmute(my_vec());
- //~^ ERROR transmute from a type (`std::vec::Vec<i32>`) to itself
+
let _: Vec<i32> = core::mem::transmute(my_vec());
- //~^ ERROR transmute from a type (`std::vec::Vec<i32>`) to itself
+
let _: Vec<i32> = std::intrinsics::transmute(my_vec());
- //~^ ERROR transmute from a type (`std::vec::Vec<i32>`) to itself
+
let _: Vec<i32> = std::mem::transmute(my_vec());
- //~^ ERROR transmute from a type (`std::vec::Vec<i32>`) to itself
+
let _: Vec<i32> = my_transmute(my_vec());
- //~^ ERROR transmute from a type (`std::vec::Vec<i32>`) to itself
+
let _: Vec<u32> = core::intrinsics::transmute(my_vec());
let _: Vec<u32> = core::mem::transmute(my_vec());
let _: Vec<u32> = my_transmute(my_vec());
let _: *const usize = std::mem::transmute(5_isize);
- //~^ ERROR transmute from an integer to a pointer
- //~| HELP try
- //~| SUGGESTION 5_isize as *const usize
+
+
+
let _ = 5_isize as *const usize;
let _: *const usize = std::mem::transmute(1+1usize);
- //~^ ERROR transmute from an integer to a pointer
- //~| HELP try
- //~| SUGGESTION (1+1usize) as *const usize
+
+
+
let _ = (1+1_usize) as *const usize;
}
}
unsafe {
let _: Usize = core::intrinsics::transmute(int_const_ptr);
- //~^ ERROR transmute from a type (`*const Usize`) to the type that it points to (`Usize`)
+
let _: Usize = core::intrinsics::transmute(int_mut_ptr);
- //~^ ERROR transmute from a type (`*mut Usize`) to the type that it points to (`Usize`)
+
let _: *const Usize = core::intrinsics::transmute(my_int());
- //~^ ERROR transmute from a type (`Usize`) to a pointer to that type (`*const Usize`)
+
let _: *mut Usize = core::intrinsics::transmute(my_int());
- //~^ ERROR transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`)
+
}
}
fn main() {
unsafe {
let _: *const usize = std::mem::transmute(6.0f32);
- //~^ ERROR transmute from a `f32` to a pointer
+
let _: *mut usize = std::mem::transmute(6.0f32);
- //~^ ERROR transmute from a `f32` to a pointer
+
let _: *const usize = std::mem::transmute('x');
- //~^ ERROR transmute from a `char` to a pointer
+
let _: *mut usize = std::mem::transmute('x');
- //~^ ERROR transmute from a `char` to a pointer
+
}
}
fn main() {
unsafe {
let _: *const usize = std::mem::transmute(6.0f64);
- //~^ ERROR transmute from a `f64` to a pointer
+
let _: *mut usize = std::mem::transmute(6.0f64);
- //~^ ERROR transmute from a `f64` to a pointer
+
}
}
#[deny(zero_width_space)]
fn zero() {
print!("Here >< is a ZWS, and another");
- //~^ ERROR zero-width space detected
+
print!("This\u{200B}is\u{200B}fine");
}
#[deny(unicode_not_nfc)]
fn canon() {
- print!("̀àh?"); //~ERROR non-nfc unicode sequence detected
+ print!("̀àh?");
print!("a\u{0300}h?"); // also okay
}
#[deny(non_ascii_literal)]
fn uni() {
- print!("Üben!"); //~ERROR literal non-ASCII character detected
+ print!("Üben!");
print!("\u{DC}ben!"); // this is okay
}
error: non-nfc unicode sequence detected
--> $DIR/unicode.rs:13:12
|
-13 | print!("̀àh?"); //~ERROR non-nfc unicode sequence detected
+13 | print!("̀àh?");
| ^^^^^^^
|
note: lint level defined here
error: literal non-ASCII character detected
--> $DIR/unicode.rs:19:12
|
-19 | print!("Üben!"); //~ERROR literal non-ASCII character detected
+19 | print!("Üben!");
| ^^^^^^^
|
note: lint level defined here
}
// this warns
- if { true; } == { false; } { //~ERROR ==-comparison of unit values detected. This will always be true
+ if { true; } == { false; } {
}
- if { true; } > { false; } { //~ERROR >-comparison of unit values detected. This will always be false
+ if { true; } > { false; } {
}
}
error: ==-comparison of unit values detected. This will always be true
--> $DIR/unit_cmp.rs:16:8
|
-16 | if { true; } == { false; } { //~ERROR ==-comparison of unit values detected. This will always be true
+16 | if { true; } == { false; } {
| ^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
error: >-comparison of unit values detected. This will always be false
--> $DIR/unit_cmp.rs:19:8
|
-19 | if { true; } > { false; } { //~ERROR >-comparison of unit values detected. This will always be false
+19 | if { true; } > { false; } {
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
let f = Foo { a: 0, b: 0, c: 0 };
match f {
- Foo { a: _, b: 0, .. } => {} //~ERROR You matched a field with a wildcard pattern
- //~^ HELP Try with `Foo { b: 0, .. }`
- Foo { a: _, b: _, c: _ } => {} //~ERROR All the struct fields are matched to a
- //~^ HELP Try with `Foo { .. }`
+ Foo { a: _, b: 0, .. } => {}
+
+ Foo { a: _, b: _, c: _ } => {}
+
}
match f {
Foo { b: 0, .. } => {} // should be OK
error: You matched a field with a wildcard pattern. Consider using `..` instead
--> $DIR/unneeded_field_pattern.rs:17:15
|
-17 | Foo { a: _, b: 0, .. } => {} //~ERROR You matched a field with a wildcard pattern
+17 | Foo { a: _, b: 0, .. } => {}
| ^^^^
|
note: lint level defined here
error: All the struct fields are matched to a wildcard pattern, consider using `..`.
--> $DIR/unneeded_field_pattern.rs:19:9
|
-19 | Foo { a: _, b: _, c: _ } => {} //~ERROR All the struct fields are matched to a
+19 | Foo { a: _, b: _, c: _ } => {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: Try with `Foo { .. }` instead
#![deny(unsafe_removed_from_name)]
use std::cell::{UnsafeCell as TotallySafeCell};
-//~^ ERROR removed "unsafe" from the name of `UnsafeCell` in use as `TotallySafeCell`
+
use std::cell::UnsafeCell as TotallySafeCellAgain;
-//~^ ERROR removed "unsafe" from the name of `UnsafeCell` in use as `TotallySafeCellAgain`
+
// Shouldn't error
use std::cell::{UnsafeCell as SuperDangerousUnsafeCell};
}
use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety;
-//~^ ERROR removed "unsafe" from the name of `Unsafe` in use as `LieAboutModSafety`
+
// Shouldn't error
use mod_with_some_unsafe_things::Safe as IPromiseItsSafeThisTime;
fn question_mark<T: io::Read + io::Write>(s: &mut T) -> io::Result<()> {
s.write(b"test")?;
- //~^ ERROR handle written amount returned
+
let mut buf = [0u8; 4];
s.read(&mut buf)?;
- //~^ ERROR handle read amount returned
+
Ok(())
}
fn unwrap<T: io::Read + io::Write>(s: &mut T) {
s.write(b"test").unwrap();
- //~^ ERROR handle written amount returned
+
let mut buf = [0u8; 4];
s.read(&mut buf).unwrap();
- //~^ ERROR handle read amount returned
+
}
fn main() {
#![deny(unused_label)]
fn unused_label() {
- 'label: for i in 1..2 { //~ERROR: unused label `'label`
+ 'label: for i in 1..2 {
if i > 4 { continue }
}
}
fn bla() {
- 'a: loop { break } //~ERROR: unused label `'a`
+ 'a: loop { break }
fn blub() {}
}
}
}
- 'same_label_in_two_fns: loop { //~ERROR: unused label `'same_label_in_two_fns`
+ 'same_label_in_two_fns: loop {
let _ = 1;
}
}
error: unused label `'label`
--> $DIR/unused_labels.rs:8:5
|
-8 | 'label: for i in 1..2 { //~ERROR: unused label `'label`
+8 | 'label: for i in 1..2 {
| _____^ starting here...
9 | | if i > 4 { continue }
10 | | }
error: unused label `'a`
--> $DIR/unused_labels.rs:21:5
|
-21 | 'a: loop { break } //~ERROR: unused label `'a`
+21 | 'a: loop { break }
| ^^^^^^^^^^^^^^^^^^
error: unused label `'same_label_in_two_fns`
--> $DIR/unused_labels.rs:32:5
|
-32 | 'same_label_in_two_fns: loop { //~ERROR: unused label `'same_label_in_two_fns`
+32 | 'same_label_in_two_fns: loop {
| _____^ starting here...
33 | | let _ = 1;
34 | | }
}
-fn unused_lt<'a>(x: u8) { //~ ERROR this lifetime
+fn unused_lt<'a>(x: u8) {
}
-fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) { //~ ERROR this lifetime
+fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) {
// 'a is useless here since it's not directly bound
}
struct Bar;
impl Bar {
- fn x<'a>(&self) {} //~ ERROR this lifetime
+ fn x<'a>(&self) {}
}
// test for #489 (used lifetimes in bounds)
error: this lifetime isn't used in the function definition
--> $DIR/unused_lt.rs:16:14
|
-16 | fn unused_lt<'a>(x: u8) { //~ ERROR this lifetime
+16 | fn unused_lt<'a>(x: u8) {
| ^^
|
note: lint level defined here
error: this lifetime isn't used in the function definition
--> $DIR/unused_lt.rs:20:25
|
-20 | fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) { //~ ERROR this lifetime
+20 | fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) {
| ^^
error: this lifetime isn't used in the function definition
--> $DIR/unused_lt.rs:50:10
|
-50 | fn x<'a>(&self) {} //~ ERROR this lifetime
+50 | fn x<'a>(&self) {}
| ^^
error: aborting due to 3 previous errors
/// Test that we lint if we use a binding with a single leading underscore
fn prefix_underscore(_foo: u32) -> u32 {
- _foo + 1 //~ ERROR used binding `_foo` which is prefixed with an underscore
+ _foo + 1
}
/// Test that we lint if we use a `_`-variable defined outside within a macro expansion
fn in_macro(_foo: u32) {
println!("{}", _foo);
- //~^ ERROR used binding `_foo` which is prefixed with an underscore
+
assert_eq!(_foo, _foo);
- //~^ ERROR used binding `_foo` which is prefixed with an underscore
- //~| ERROR used binding `_foo` which is prefixed with an underscore
+
+
test_macro!() + 1;
}
/// Test that we lint the use of a struct field which is prefixed with an underscore
fn in_struct_field() {
let mut s = StructFieldTest { _underscore_field: 0 };
- s._underscore_field += 1; //~ Error used binding `_underscore_field` which is prefixed with an underscore
+ s._underscore_field += 1;
}
/// Test that we do not lint if the underscore is not a prefix
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
--> $DIR/used_underscore_binding.rs:17:5
|
-17 | _foo + 1 //~ ERROR used binding `_foo` which is prefixed with an underscore
+17 | _foo + 1
| ^^^^
|
note: lint level defined here
error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
--> $DIR/used_underscore_binding.rs:39:5
|
-39 | s._underscore_field += 1; //~ Error used binding `_underscore_field` which is prefixed with an underscore
+39 | s._underscore_field += 1;
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 5 previous errors
#![plugin(clippy)]
#![deny(useless_attribute)]
-#[allow(dead_code)] //~ ERROR useless lint attribute
-//~| HELP if you just forgot a `!`, use
-//~| SUGGESTION #![allow(dead_code)]
+#[allow(dead_code)]
+
+
extern crate clippy_lints;
// don't lint on unused_import for `use` items
error: useless lint attribute
--> $DIR/useless_attribute.rs:5:1
|
-5 | #[allow(dead_code)] //~ ERROR useless lint attribute
+5 | #[allow(dead_code)]
| ^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
3 | #![deny(useless_attribute)]
| ^^^^^^^^^^^^^^^^^
help: if you just forgot a `!`, use
- | #![allow(dead_code)] //~ ERROR useless lint attribute
+ | #![allow(dead_code)]
error: aborting due to previous error
fn main() {
on_slice(&vec![]);
- //~^ ERROR useless use of `vec!`
- //~| HELP you can use
- //~| SUGGESTION on_slice(&[])
+
+
+
on_slice(&[]);
on_slice(&vec![1, 2]);
- //~^ ERROR useless use of `vec!`
- //~| HELP you can use
- //~| SUGGESTION on_slice(&[1, 2])
+
+
+
on_slice(&[1, 2]);
on_slice(&vec ![1, 2]);
- //~^ ERROR useless use of `vec!`
- //~| HELP you can use
- //~| SUGGESTION on_slice(&[1, 2])
+
+
+
on_slice(&[1, 2]);
on_slice(&vec!(1, 2));
- //~^ ERROR useless use of `vec!`
- //~| HELP you can use
- //~| SUGGESTION on_slice(&[1, 2])
+
+
+
on_slice(&[1, 2]);
on_slice(&vec![1; 2]);
- //~^ ERROR useless use of `vec!`
- //~| HELP you can use
- //~| SUGGESTION on_slice(&[1; 2])
+
+
+
on_slice(&[1; 2]);
on_vec(&vec![]);
on_slice(&vec![2; line.length()]);
for a in vec![1, 2, 3] {
- //~^ ERROR useless use of `vec!`
- //~| HELP you can use
- //~| SUGGESTION for a in &[1, 2, 3] {
+
+
+
println!("{:?}", a);
}
fn main() {
let y = Some(true);
loop {
- //~^ERROR this loop could be written as a `while let` loop
- //~|HELP try
- //~|SUGGESTION while let Some(_x) = y {
+
+
+
if let Some(_x) = y {
let _v = 1;
} else {
break;
}
loop {
- //~^ERROR this loop could be written as a `while let` loop
- //~|HELP try
- //~|SUGGESTION while let Some(_x) = y {
+
+
+
match y {
Some(_x) => true,
None => break
};
}
loop {
- //~^ERROR this loop could be written as a `while let` loop
- //~|HELP try
- //~|SUGGESTION while let Some(x) = y {
+
+
+
let x = match y {
Some(x) => x,
None => break
let _str = "foo";
}
loop {
- //~^ERROR this loop could be written as a `while let` loop
- //~|HELP try
- //~|SUGGESTION while let Some(x) = y {
+
+
+
let x = match y {
Some(x) => x,
None => break,
// #675, this used to have a wrong suggestion
loop {
- //~^ERROR this loop could be written as a `while let` loop
- //~|HELP try
- //~|SUGGESTION while let Some(word) = "".split_whitespace().next() { .. }
+
+
+
let (e, l) = match "".split_whitespace().next() {
Some(word) => (word.is_empty(), word.len()),
None => break
let mut iter = 1..20;
while let Option::Some(x) = iter.next() {
- //~^ ERROR this loop could be written as a `for` loop
- //~| HELP try
- //~| SUGGESTION for x in iter {
+
+
+
println!("{}", x);
}
let mut iter = 1..20;
while let Some(x) = iter.next() {
- //~^ ERROR this loop could be written as a `for` loop
- //~| HELP try
- //~| SUGGESTION for x in iter {
+
+
+
println!("{}", x);
}
let mut iter = 1..20;
while let Some(_) = iter.next() {}
- //~^ ERROR this loop could be written as a `for` loop
- //~| HELP try
- //~| SUGGESTION for _ in iter {
+
+
+
let mut iter = 1..20;
while let None = iter.next() {} // this is fine (if nonsensical)
fn no_panic<T>(slice: &[T]) {
let mut iter = slice.iter();
loop {
- //~^ ERROR
- //~| HELP try
- //~| SUGGESTION while let Some(ele) = iter.next() { .. }
+
+
+
let _ = match iter.next() {
Some(ele) => ele,
None => break
};
- loop {} //~ERROR empty `loop {}` detected.
+ loop {}
}
}
|
25 | loop {
| _____^ starting here...
-26 | | //~^ERROR this loop could be written as a `while let` loop
-27 | | //~|HELP try
-28 | | //~|SUGGESTION while let Some(_x) = y {
+26 | |
+27 | |
+28 | |
29 | | match y {
30 | | Some(_x) => true,
31 | | None => break
|
83 | while let Option::Some(x) = iter.next() {
| _____^ starting here...
-84 | | //~^ ERROR this loop could be written as a `for` loop
-85 | | //~| HELP try
-86 | | //~| SUGGESTION for x in iter {
+84 | |
+85 | |
+86 | |
87 | | println!("{}", x);
88 | | }
| |_____^ ...ending here
|
91 | while let Some(x) = iter.next() {
| _____^ starting here...
-92 | | //~^ ERROR this loop could be written as a `for` loop
-93 | | //~| HELP try
-94 | | //~| SUGGESTION for x in iter {
+92 | |
+93 | |
+94 | |
95 | | println!("{}", x);
96 | | }
| |_____^ ...ending here
error: empty `loop {}` detected. You may want to either use `panic!()` or add `std::thread::sleep(..);` to the loop body.
--> $DIR/while_loop.rs:150:9
|
-150 | loop {} //~ERROR empty `loop {}` detected.
+150 | loop {}
| ^^^^^^^
|
note: lint level defined here
let t = &thingy;
match t.$idx { Foo::A(ref val) => { println!("42"); }, _ => {} }
- //~^ ERROR you seem to be trying to use match
- //~| HELP try this
- //~| SUGGESTION if let Foo::A(ref val) = t.$idx { println!("42"); }
+
+
+
}}
}
fn is_i32(self) {}
fn is_u32(&self) {}
fn to_i32(self) {}
- fn from_i32(self) {} //~ERROR: methods called `from_*` usually take no self
+ fn from_i32(self) {}
pub fn as_i64(self) {}
pub fn into_i64(self) {}
pub fn is_i64(self) {}
pub fn to_i64(self) {}
- pub fn from_i64(self) {} //~ERROR: methods called `from_*` usually take no self
+ pub fn from_i64(self) {}
// check whether the lint can be allowed at the function level
#[allow(wrong_self_convention)]
pub fn from_cake(self) {}
impl Bar {
- fn as_i32(self) {} //~ERROR: methods called `as_*` usually take self by reference
+ fn as_i32(self) {}
fn as_u32(&self) {}
- fn into_i32(&self) {} //~ERROR: methods called `into_*` usually take self by value
+ fn into_i32(&self) {}
fn into_u32(self) {}
- fn is_i32(self) {} //~ERROR: methods called `is_*` usually take self by reference
+ fn is_i32(self) {}
fn is_u32(&self) {}
- fn to_i32(self) {} //~ERROR: methods called `to_*` usually take self by reference
+ fn to_i32(self) {}
fn to_u32(&self) {}
- fn from_i32(self) {} //~ERROR: methods called `from_*` usually take no self
+ fn from_i32(self) {}
- pub fn as_i64(self) {} //~ERROR: methods called `as_*` usually take self by reference
- pub fn into_i64(&self) {} //~ERROR: methods called `into_*` usually take self by value
- pub fn is_i64(self) {} //~ERROR: methods called `is_*` usually take self by reference
- pub fn to_i64(self) {} //~ERROR: methods called `to_*` usually take self by reference
- pub fn from_i64(self) {} //~ERROR: methods called `from_*` usually take no self
+ pub fn as_i64(self) {}
+ pub fn into_i64(&self) {}
+ pub fn is_i64(self) {}
+ pub fn to_i64(self) {}
+ pub fn from_i64(self) {}
// test for false positives
fn as_(self) {}
error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:21:17
|
-21 | fn from_i32(self) {} //~ERROR: methods called `from_*` usually take no self
+21 | fn from_i32(self) {}
| ^^^^
|
note: lint level defined here
error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:27:21
|
-27 | pub fn from_i64(self) {} //~ERROR: methods called `from_*` usually take no self
+27 | pub fn from_i64(self) {}
| ^^^^
error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:38:15
|
-38 | fn as_i32(self) {} //~ERROR: methods called `as_*` usually take self by reference
+38 | fn as_i32(self) {}
| ^^^^
error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:40:17
|
-40 | fn into_i32(&self) {} //~ERROR: methods called `into_*` usually take self by value
+40 | fn into_i32(&self) {}
| ^^^^^
error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:42:15
|
-42 | fn is_i32(self) {} //~ERROR: methods called `is_*` usually take self by reference
+42 | fn is_i32(self) {}
| ^^^^
error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:44:15
|
-44 | fn to_i32(self) {} //~ERROR: methods called `to_*` usually take self by reference
+44 | fn to_i32(self) {}
| ^^^^
error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:46:17
|
-46 | fn from_i32(self) {} //~ERROR: methods called `from_*` usually take no self
+46 | fn from_i32(self) {}
| ^^^^
error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:48:19
|
-48 | pub fn as_i64(self) {} //~ERROR: methods called `as_*` usually take self by reference
+48 | pub fn as_i64(self) {}
| ^^^^
error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:49:21
|
-49 | pub fn into_i64(&self) {} //~ERROR: methods called `into_*` usually take self by value
+49 | pub fn into_i64(&self) {}
| ^^^^^
error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:50:19
|
-50 | pub fn is_i64(self) {} //~ERROR: methods called `is_*` usually take self by reference
+50 | pub fn is_i64(self) {}
| ^^^^
error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:51:19
|
-51 | pub fn to_i64(self) {} //~ERROR: methods called `to_*` usually take self by reference
+51 | pub fn to_i64(self) {}
| ^^^^
error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:52:21
|
-52 | pub fn from_i64(self) {} //~ERROR: methods called `from_*` usually take no self
+52 | pub fn from_i64(self) {}
| ^^^^
error: aborting due to 12 previous errors
#[allow(unused_variables)]
#[deny(zero_divided_by_zero)]
fn main() {
- let nan = 0.0 / 0.0; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
- //~^ equal expressions as operands to `/`
- let f64_nan = 0.0 / 0.0f64; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
- //~^ equal expressions as operands to `/`
- let other_f64_nan = 0.0f64 / 0.0; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
- //~^ equal expressions as operands to `/`
- let one_more_f64_nan = 0.0f64/0.0f64; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
- //~^ equal expressions as operands to `/`
+ let nan = 0.0 / 0.0;
+
+ let f64_nan = 0.0 / 0.0f64;
+
+ let other_f64_nan = 0.0f64 / 0.0;
+
+ let one_more_f64_nan = 0.0f64/0.0f64;
+
let zero = 0.0;
let other_zero = 0.0;
let other_nan = zero / other_zero; // fine - this lint doesn't propegate constants.
warning: equal expressions as operands to `/`
--> $DIR/zero_div_zero.rs:7:15
|
-7 | let nan = 0.0 / 0.0; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
+7 | let nan = 0.0 / 0.0;
| ^^^^^^^^^
|
= note: #[warn(eq_op)] on by default
error: constant division of 0.0 with 0.0 will always result in NaN
--> $DIR/zero_div_zero.rs:7:15
|
-7 | let nan = 0.0 / 0.0; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
+7 | let nan = 0.0 / 0.0;
| ^^^^^^^^^
|
note: lint level defined here
warning: equal expressions as operands to `/`
--> $DIR/zero_div_zero.rs:9:19
|
-9 | let f64_nan = 0.0 / 0.0f64; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
+9 | let f64_nan = 0.0 / 0.0f64;
| ^^^^^^^^^^^^
|
= note: #[warn(eq_op)] on by default
error: constant division of 0.0 with 0.0 will always result in NaN
--> $DIR/zero_div_zero.rs:9:19
|
-9 | let f64_nan = 0.0 / 0.0f64; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
+9 | let f64_nan = 0.0 / 0.0f64;
| ^^^^^^^^^^^^
|
= help: Consider using `std::f64::NAN` if you would like a constant representing NaN
warning: equal expressions as operands to `/`
--> $DIR/zero_div_zero.rs:11:25
|
-11 | let other_f64_nan = 0.0f64 / 0.0; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
+11 | let other_f64_nan = 0.0f64 / 0.0;
| ^^^^^^^^^^^^
|
= note: #[warn(eq_op)] on by default
error: constant division of 0.0 with 0.0 will always result in NaN
--> $DIR/zero_div_zero.rs:11:25
|
-11 | let other_f64_nan = 0.0f64 / 0.0; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
+11 | let other_f64_nan = 0.0f64 / 0.0;
| ^^^^^^^^^^^^
|
= help: Consider using `std::f64::NAN` if you would like a constant representing NaN
warning: equal expressions as operands to `/`
--> $DIR/zero_div_zero.rs:13:28
|
-13 | let one_more_f64_nan = 0.0f64/0.0f64; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
+13 | let one_more_f64_nan = 0.0f64/0.0f64;
| ^^^^^^^^^^^^^
|
= note: #[warn(eq_op)] on by default
error: constant division of 0.0 with 0.0 will always result in NaN
--> $DIR/zero_div_zero.rs:13:28
|
-13 | let one_more_f64_nan = 0.0f64/0.0f64; //~ERROR constant division of 0.0 with 0.0 will always result in NaN
+13 | let one_more_f64_nan = 0.0f64/0.0f64;
| ^^^^^^^^^^^^^
|
= help: Consider using `std::f64::NAN` if you would like a constant representing NaN