rust-clippy/tests/compile-fail/no_effect.rs

122 lines
4.1 KiB
Rust
Raw Normal View History

#![feature(plugin, box_syntax, inclusive_range_syntax)]
2015-10-28 16:50:00 +00:00
#![plugin(clippy)]
#![deny(no_effect, unnecessary_operation)]
2015-10-28 16:50:00 +00:00
#![allow(dead_code)]
#![allow(path_statements)]
#![feature(untagged_unions)]
2015-10-28 16:50:00 +00:00
struct Unit;
struct Tuple(i32);
struct Struct {
field: i32
}
enum Enum {
2016-02-01 11:51:33 +00:00
Tuple(i32),
Struct { field: i32 },
2015-10-28 16:50:00 +00:00
}
2016-08-28 17:43:55 +00:00
union Union {
a: u8,
b: f64,
}
2015-10-28 16:50:00 +00:00
fn get_number() -> i32 { 0 }
fn get_struct() -> Struct { Struct { field: 0 } }
2016-05-25 16:51:35 +00:00
unsafe fn unsafe_fn() -> i32 { 0 }
2015-10-28 16:50:00 +00:00
fn main() {
let s = get_struct();
2016-02-11 12:50:41 +00:00
let s2 = get_struct();
2015-10-28 16:50:00 +00:00
0; //~ERROR statement with no effect
2016-02-11 12:50:41 +00:00
s2; //~ERROR statement with no effect
2015-10-28 16:50:00 +00:00
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
2016-02-01 11:51:33 +00:00
Enum::Tuple(0); //~ERROR statement with no effect
Enum::Struct { field: 0 }; //~ERROR statement with no effect
2016-02-11 12:50:41 +00:00
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
2016-02-11 12:50:41 +00:00
[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
let mut x = 0;
|| x += 5; //~ERROR statement with no effect
2015-10-28 16:50:00 +00:00
// Do not warn
get_number();
2016-05-25 16:51:35 +00:00
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
2016-06-05 16:07:12 +00:00
//~|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
2016-06-05 16:07:12 +00:00
//~|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;
2016-05-25 16:51:35 +00:00
{get_number()}; //~ERROR statement can be reduced
//~^HELP replace it with
//~|SUGGESTION get_number();
2015-10-28 16:50:00 +00:00
}