]> git.lizzy.rs Git - rust.git/blob - tests/ui/no_effect.rs
Auto merge of #3596 - xfix:remove-crate-from-paths, r=flip1995
[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 struct A(i32);
71 struct B {
72     field: i32,
73 }
74 struct C {
75     b: B,
76 }
77 struct D {
78     arr: [i32; 1],
79 }
80 const A_CONST: A = A(1);
81 const B: B = B { field: 1 };
82 const C: C = C { b: B { field: 1 } };
83 const D: D = D { arr: [1] };
84
85 fn main() {
86     let s = get_struct();
87     let s2 = get_struct();
88
89     0;
90     s2;
91     Unit;
92     Tuple(0);
93     Struct { field: 0 };
94     Struct { ..s };
95     Union { a: 0 };
96     Enum::Tuple(0);
97     Enum::Struct { field: 0 };
98     5 + 6;
99     *&42;
100     &6;
101     (5, 6, 7);
102     box 42;
103     ..;
104     5..;
105     ..5;
106     5..6;
107     5..=6;
108     [42, 55];
109     [42, 55][1];
110     (42, 55).1;
111     [42; 55];
112     [42; 55][13];
113     let mut x = 0;
114     || x += 5;
115     let s: String = "foo".into();
116     FooString { s: s };
117     A_CONST.0 = 2;
118     B.field = 2;
119     C.b.field = 2;
120     D.arr[0] = 2;
121
122     // Do not warn
123     get_number();
124     unsafe { unsafe_fn() };
125     DropUnit;
126     DropStruct { field: 0 };
127     DropTuple(0);
128     DropEnum::Tuple(0);
129     DropEnum::Struct { field: 0 };
130     let mut a_mut = A(1);
131     a_mut.0 = 2;
132     let mut b_mut = B { field: 1 };
133     b_mut.field = 2;
134     let mut c_mut = C { b: B { field: 1 } };
135     c_mut.b.field = 2;
136     let mut d_mut = D { arr: [1] };
137     d_mut.arr[0] = 2;
138 }