]> git.lizzy.rs Git - rust.git/blob - tests/ui/no_effect.rs
Auto merge of #3635 - matthiaskrgr:revert_random_state_3603, r=xfix
[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 #![feature(box_syntax)]
11 #![warn(clippy::no_effect)]
12 #![allow(dead_code)]
13 #![allow(path_statements)]
14 #![allow(clippy::deref_addrof)]
15 #![allow(clippy::redundant_field_names)]
16 #![feature(untagged_unions)]
17
18 struct Unit;
19 struct Tuple(i32);
20 struct Struct {
21     field: i32,
22 }
23 enum Enum {
24     Tuple(i32),
25     Struct { field: i32 },
26 }
27 struct DropUnit;
28 impl Drop for DropUnit {
29     fn drop(&mut self) {}
30 }
31 struct DropStruct {
32     field: i32,
33 }
34 impl Drop for DropStruct {
35     fn drop(&mut self) {}
36 }
37 struct DropTuple(i32);
38 impl Drop for DropTuple {
39     fn drop(&mut self) {}
40 }
41 enum DropEnum {
42     Tuple(i32),
43     Struct { field: i32 },
44 }
45 impl Drop for DropEnum {
46     fn drop(&mut self) {}
47 }
48 struct FooString {
49     s: String,
50 }
51 union Union {
52     a: u8,
53     b: f64,
54 }
55
56 fn get_number() -> i32 {
57     0
58 }
59 fn get_struct() -> Struct {
60     Struct { field: 0 }
61 }
62 fn get_drop_struct() -> DropStruct {
63     DropStruct { field: 0 }
64 }
65
66 unsafe fn unsafe_fn() -> i32 {
67     0
68 }
69
70 fn main() {
71     let s = get_struct();
72     let s2 = get_struct();
73
74     0;
75     s2;
76     Unit;
77     Tuple(0);
78     Struct { field: 0 };
79     Struct { ..s };
80     Union { a: 0 };
81     Enum::Tuple(0);
82     Enum::Struct { field: 0 };
83     5 + 6;
84     *&42;
85     &6;
86     (5, 6, 7);
87     box 42;
88     ..;
89     5..;
90     ..5;
91     5..6;
92     5..=6;
93     [42, 55];
94     [42, 55][1];
95     (42, 55).1;
96     [42; 55];
97     [42; 55][13];
98     let mut x = 0;
99     || x += 5;
100     let s: String = "foo".into();
101     FooString { s: s };
102
103     // Do not warn
104     get_number();
105     unsafe { unsafe_fn() };
106     DropUnit;
107     DropStruct { field: 0 };
108     DropTuple(0);
109     DropEnum::Tuple(0);
110     DropEnum::Struct { field: 0 };
111 }