about summary refs log tree commit diff
path: root/tests/ui/numbered_fields.fixed
diff options
context:
space:
mode:
authorflip1995 <philipp.krones@embecosm.com>2021-12-30 14:04:13 +0100
committerflip1995 <philipp.krones@embecosm.com>2021-12-30 14:17:53 +0100
commite45842e3602e806345b3355ed0955e604daef49c (patch)
treedb4d1481f0b49bae4bdeedea435b5cfc0ceb6e38 /tests/ui/numbered_fields.fixed
parent01217f6f4c752700754e8e66eb02d763c4c55c72 (diff)
parentc1cd64b9c6b29ed2a577fc174a50c76267a966e2 (diff)
downloadrust-e45842e3602e806345b3355ed0955e604daef49c.tar.gz
rust-e45842e3602e806345b3355ed0955e604daef49c.zip
Merge remote-tracking branch 'upstream/master' into rustup
Diffstat (limited to 'tests/ui/numbered_fields.fixed')
-rw-r--r--tests/ui/numbered_fields.fixed33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/ui/numbered_fields.fixed b/tests/ui/numbered_fields.fixed
new file mode 100644
index 00000000000..1da97e96879
--- /dev/null
+++ b/tests/ui/numbered_fields.fixed
@@ -0,0 +1,33 @@
+//run-rustfix
+#![warn(clippy::init_numbered_fields)]
+
+#[derive(Default)]
+struct TupleStruct(u32, u32, u8);
+
+// This shouldn't lint because it's in a macro
+macro_rules! tuple_struct_init {
+    () => {
+        TupleStruct { 0: 0, 1: 1, 2: 2 }
+    };
+}
+
+fn main() {
+    let tuple_struct = TupleStruct::default();
+
+    // This should lint
+    let _ = TupleStruct(1u32, 42, 23u8);
+
+    // This should also lint and order the fields correctly
+    let _ = TupleStruct(1u32, 3u32, 2u8);
+
+    // Ok because of default initializer
+    let _ = TupleStruct { 0: 42, ..tuple_struct };
+
+    let _ = TupleStruct {
+        1: 23,
+        ..TupleStruct::default()
+    };
+
+    // Ok because it's in macro
+    let _ = tuple_struct_init!();
+}