]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/no_effect.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / no_effect.rs
index bee3aeb6f7f2b8ea6c3fefb5ea26e9a5b875ebec..8431f00e445c5eb37d3c1b17b57ffd4599c6c8c5 100644 (file)
@@ -7,12 +7,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-
-
-
 #![feature(box_syntax)]
-
-
 #![warn(clippy::no_effect)]
 #![allow(dead_code)]
 #![allow(path_statements)]
@@ -23,7 +18,7 @@
 struct Unit;
 struct Tuple(i32);
 struct Struct {
-    field: i32
+    field: i32,
 }
 enum Enum {
     Tuple(i32),
@@ -34,7 +29,7 @@ impl Drop for DropUnit {
     fn drop(&mut self) {}
 }
 struct DropStruct {
-    field: i32
+    field: i32,
 }
 impl Drop for DropStruct {
     fn drop(&mut self) {}
@@ -58,11 +53,34 @@ union Union {
     b: f64,
 }
 
-fn get_number() -> i32 { 0 }
-fn get_struct() -> Struct { Struct { field: 0 } }
-fn get_drop_struct() -> DropStruct { DropStruct { field: 0 } }
+fn get_number() -> i32 {
+    0
+}
+fn get_struct() -> Struct {
+    Struct { field: 0 }
+}
+fn get_drop_struct() -> DropStruct {
+    DropStruct { field: 0 }
+}
+
+unsafe fn unsafe_fn() -> i32 {
+    0
+}
 
-unsafe fn unsafe_fn() -> i32 { 0 }
+struct A(i32);
+struct B {
+    field: i32,
+}
+struct C {
+    b: B,
+}
+struct D {
+    arr: [i32; 1],
+}
+const A_CONST: A = A(1);
+const B: B = B { field: 1 };
+const C: C = C { b: B { field: 1 } };
+const D: D = D { arr: [1] };
 
 fn main() {
     let s = get_struct();
@@ -96,6 +114,10 @@ fn main() {
     || x += 5;
     let s: String = "foo".into();
     FooString { s: s };
+    A_CONST.0 = 2;
+    B.field = 2;
+    C.b.field = 2;
+    D.arr[0] = 2;
 
     // Do not warn
     get_number();
@@ -105,4 +127,12 @@ fn main() {
     DropTuple(0);
     DropEnum::Tuple(0);
     DropEnum::Struct { field: 0 };
+    let mut a_mut = A(1);
+    a_mut.0 = 2;
+    let mut b_mut = B { field: 1 };
+    b_mut.field = 2;
+    let mut c_mut = C { b: B { field: 1 } };
+    c_mut.b.field = 2;
+    let mut d_mut = D { arr: [1] };
+    d_mut.arr[0] = 2;
 }