2018-12-09 22:26:16 +00:00
|
|
|
#![allow(
|
|
|
|
unused_variables,
|
|
|
|
unused_assignments,
|
|
|
|
clippy::similar_names,
|
|
|
|
clippy::blacklisted_name
|
|
|
|
)]
|
2018-07-28 15:34:52 +00:00
|
|
|
#![warn(clippy::useless_let_if_seq)]
|
2016-03-30 17:53:43 +00:00
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
fn f() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
fn g(x: i32) -> i32 {
|
|
|
|
x + 1
|
|
|
|
}
|
2016-06-05 19:38:15 +00:00
|
|
|
|
|
|
|
fn issue985() -> i32 {
|
|
|
|
let mut x = 42;
|
|
|
|
if f() {
|
|
|
|
x = g(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
x
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue985_alt() -> i32 {
|
|
|
|
let mut x = 42;
|
|
|
|
if f() {
|
|
|
|
f();
|
|
|
|
} else {
|
|
|
|
x = g(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
x
|
|
|
|
}
|
2016-03-30 17:53:43 +00:00
|
|
|
|
2020-09-24 12:49:22 +00:00
|
|
|
#[allow(clippy::manual_strip)]
|
2016-06-03 17:35:39 +00:00
|
|
|
fn issue975() -> String {
|
|
|
|
let mut udn = "dummy".to_string();
|
|
|
|
if udn.starts_with("uuid:") {
|
|
|
|
udn = String::from(&udn[5..]);
|
|
|
|
}
|
|
|
|
udn
|
|
|
|
}
|
|
|
|
|
2016-03-30 17:53:43 +00:00
|
|
|
fn early_return() -> u8 {
|
|
|
|
// FIXME: we could extend the lint to include such cases:
|
|
|
|
let foo;
|
|
|
|
|
|
|
|
if f() {
|
|
|
|
return 42;
|
|
|
|
} else {
|
|
|
|
foo = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
foo
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
early_return();
|
2016-06-03 17:35:39 +00:00
|
|
|
issue975();
|
2016-06-05 19:38:15 +00:00
|
|
|
issue985();
|
|
|
|
issue985_alt();
|
2016-03-30 17:53:43 +00:00
|
|
|
|
|
|
|
let mut foo = 0;
|
|
|
|
if f() {
|
|
|
|
foo = 42;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut bar = 0;
|
|
|
|
if f() {
|
|
|
|
f();
|
|
|
|
bar = 42;
|
2018-12-09 22:26:16 +00:00
|
|
|
} else {
|
2016-03-30 17:53:43 +00:00
|
|
|
f();
|
|
|
|
}
|
|
|
|
|
|
|
|
let quz;
|
|
|
|
if f() {
|
|
|
|
quz = 42;
|
|
|
|
} else {
|
|
|
|
quz = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// `toto` is used several times
|
|
|
|
let mut toto;
|
|
|
|
if f() {
|
|
|
|
toto = 42;
|
|
|
|
} else {
|
|
|
|
for i in &[1, 2] {
|
|
|
|
toto = *i;
|
|
|
|
}
|
|
|
|
|
|
|
|
toto = 2;
|
|
|
|
}
|
|
|
|
|
2016-06-08 22:22:59 +00:00
|
|
|
// found in libcore, the inner if is not a statement but the block's expr
|
|
|
|
let mut ch = b'x';
|
|
|
|
if f() {
|
|
|
|
ch = b'*';
|
|
|
|
if f() {
|
|
|
|
ch = b'?';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-30 17:53:43 +00:00
|
|
|
// baz needs to be mut
|
|
|
|
let mut baz = 0;
|
|
|
|
if f() {
|
|
|
|
baz = 42;
|
|
|
|
}
|
|
|
|
|
|
|
|
baz = 1337;
|
2019-04-26 02:07:01 +00:00
|
|
|
|
|
|
|
// issue 3043 - types with interior mutability should not trigger this lint
|
|
|
|
use std::cell::Cell;
|
|
|
|
let mut val = Cell::new(1);
|
|
|
|
if true {
|
|
|
|
val = Cell::new(2);
|
|
|
|
}
|
|
|
|
println!("{}", val.get());
|
2016-03-30 17:53:43 +00:00
|
|
|
}
|