rust/tests/ui/no_effect.rs

103 lines
1.6 KiB
Rust
Raw Normal View History

#![feature(box_syntax)]
#![warn(clippy::no_effect)]
2015-10-28 11:50:00 -05:00
#![allow(dead_code)]
#![allow(path_statements)]
2018-07-28 10:34:52 -05:00
#![allow(clippy::deref_addrof)]
#![allow(clippy::redundant_field_names)]
#![feature(untagged_unions)]
2015-10-28 11:50:00 -05:00
struct Unit;
struct Tuple(i32);
struct Struct {
2018-12-09 16:26:16 -06:00
field: i32,
2015-10-28 11:50:00 -05:00
}
enum Enum {
2016-02-01 05:51:33 -06:00
Tuple(i32),
Struct { field: i32 },
2015-10-28 11:50:00 -05:00
}
struct DropUnit;
impl Drop for DropUnit {
fn drop(&mut self) {}
}
struct DropStruct {
2018-12-09 16:26:16 -06:00
field: i32,
}
impl Drop for DropStruct {
fn drop(&mut self) {}
}
struct DropTuple(i32);
impl Drop for DropTuple {
fn drop(&mut self) {}
}
enum DropEnum {
Tuple(i32),
Struct { field: i32 },
}
impl Drop for DropEnum {
fn drop(&mut self) {}
}
struct FooString {
s: String,
}
2016-08-28 12:43:55 -05:00
union Union {
a: u8,
b: f64,
}
2018-12-09 16:26:16 -06:00
fn get_number() -> i32 {
0
}
fn get_struct() -> Struct {
Struct { field: 0 }
}
fn get_drop_struct() -> DropStruct {
DropStruct { field: 0 }
}
2015-10-28 11:50:00 -05:00
2018-12-09 16:26:16 -06:00
unsafe fn unsafe_fn() -> i32 {
0
}
2016-05-25 11:51:35 -05:00
2015-10-28 11:50:00 -05:00
fn main() {
let s = get_struct();
2016-02-11 06:50:41 -06:00
let s2 = get_struct();
2015-10-28 11:50:00 -05:00
2017-02-08 07:58:07 -06:00
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;
2017-09-28 12:40:19 -05:00
5..=6;
2017-02-08 07:58:07 -06:00
[42, 55];
[42, 55][1];
(42, 55).1;
[42; 55];
[42; 55][13];
2016-02-11 06:50:41 -06:00
let mut x = 0;
2017-02-08 07:58:07 -06:00
|| x += 5;
let s: String = "foo".into();
FooString { s: s };
2015-10-28 11:50:00 -05:00
// Do not warn
get_number();
2016-05-25 11:51:35 -05:00
unsafe { unsafe_fn() };
DropUnit;
DropStruct { field: 0 };
DropTuple(0);
DropEnum::Tuple(0);
DropEnum::Struct { field: 0 };
2015-10-28 11:50:00 -05:00
}