]> git.lizzy.rs Git - rust.git/blob - tests/ui/no_effect.rs
Stabilize tool lints
[rust.git] / tests / ui / no_effect.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10
11
12
13 #![feature(box_syntax)]
14
15
16 #![warn(clippy::no_effect, clippy::unnecessary_operation)]
17 #![allow(dead_code)]
18 #![allow(path_statements)]
19 #![allow(clippy::deref_addrof)]
20 #![allow(clippy::redundant_field_names)]
21 #![feature(untagged_unions)]
22
23 struct Unit;
24 struct Tuple(i32);
25 struct Struct {
26     field: i32
27 }
28 enum Enum {
29     Tuple(i32),
30     Struct { field: i32 },
31 }
32 struct DropUnit;
33 impl Drop for DropUnit {
34     fn drop(&mut self) {}
35 }
36 struct DropStruct {
37     field: i32
38 }
39 impl Drop for DropStruct {
40     fn drop(&mut self) {}
41 }
42 struct DropTuple(i32);
43 impl Drop for DropTuple {
44     fn drop(&mut self) {}
45 }
46 enum DropEnum {
47     Tuple(i32),
48     Struct { field: i32 },
49 }
50 impl Drop for DropEnum {
51     fn drop(&mut self) {}
52 }
53 struct FooString {
54     s: String,
55 }
56 union Union {
57     a: u8,
58     b: f64,
59 }
60
61 fn get_number() -> i32 { 0 }
62 fn get_struct() -> Struct { Struct { field: 0 } }
63 fn get_drop_struct() -> DropStruct { DropStruct { field: 0 } }
64
65 unsafe fn unsafe_fn() -> i32 { 0 }
66
67 fn main() {
68     let s = get_struct();
69     let s2 = get_struct();
70
71     0;
72     s2;
73     Unit;
74     Tuple(0);
75     Struct { field: 0 };
76     Struct { ..s };
77     Union { a: 0 };
78     Enum::Tuple(0);
79     Enum::Struct { field: 0 };
80     5 + 6;
81     *&42;
82     &6;
83     (5, 6, 7);
84     box 42;
85     ..;
86     5..;
87     ..5;
88     5..6;
89     5..=6;
90     [42, 55];
91     [42, 55][1];
92     (42, 55).1;
93     [42; 55];
94     [42; 55][13];
95     let mut x = 0;
96     || x += 5;
97     let s: String = "foo".into();
98     FooString { s: s };
99
100     // Do not warn
101     get_number();
102     unsafe { unsafe_fn() };
103     DropUnit;
104     DropStruct { field: 0 };
105     DropTuple(0);
106     DropEnum::Tuple(0);
107     DropEnum::Struct { field: 0 };
108
109     Tuple(get_number());
110     Struct { field: get_number() };
111     Struct { ..get_struct() };
112     Enum::Tuple(get_number());
113     Enum::Struct { field: get_number() };
114     5 + get_number();
115     *&get_number();
116     &get_number();
117     (5, 6, get_number());
118     box get_number();
119     get_number()..;
120     ..get_number();
121     5..get_number();
122     [42, get_number()];
123     [42, 55][get_number() as usize];
124     (42, get_number()).1;
125     [get_number(); 55];
126     [42; 55][get_number() as usize];
127     {get_number()};
128     FooString { s: String::from("blah"), };
129
130     // Do not warn
131     DropTuple(get_number());
132     DropStruct { field: get_number() };
133     DropStruct { field: get_number() };
134     DropStruct { ..get_drop_struct() };
135     DropEnum::Tuple(get_number());
136     DropEnum::Struct { field: get_number() };
137 }