1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
SemverQuery(
id: "repr_c_enum_struct_variant_fields_reordered",
human_readable_name: "struct variant fields reordered in repr(C) enum",
description: "A struct variant in a public repr(C) enum had its fields reordered, changing its memory layout.",
required_update: Major,
lint_level: Warn,
reference_link: Some("https://doc.rust-lang.org/reference/type-layout.html#reprc-enums-with-fields"),
query: r#"
{
CrateDiff {
baseline {
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
attribute {
content {
base @filter(op: "=", value: ["$repr"])
argument {
base @filter(op: "=", value: ["$c"])
}
}
}
importable_path {
path @tag @output
public_api @filter(op: "=", value: ["$true"])
}
variant {
... on StructVariant {
variant_name: name @output @tag
public_api_eligible @filter(op: "=", value: ["$true"])
field {
field_name: name @output @tag
public_api_eligible @filter(op: "=", value: ["$true"])
position @output @tag
}
}
}
}
}
}
current {
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @output
attribute {
content {
base @filter(op: "=", value: ["$repr"])
argument {
base @filter(op: "=", value: ["$c"])
}
}
}
importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
variant {
... on StructVariant {
name @filter(op: "=", value: ["%variant_name"])
public_api_eligible @filter(op: "=", value: ["$true"])
field {
name @filter(op: "=", value: ["%field_name"])
public_api_eligible @filter(op: "=", value: ["$true"])
position @filter(op: "!=", value: ["%position"]) @output(name: "new_position")
span_: span @optional {
filename @output
begin_line @output
end_line @output
}
}
}
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"repr": "repr",
"c": "C",
"true": true,
},
error_message: "A struct variant in a public repr(C) enum had its fields reordered. This can change the enum's memory layout, possibly breaking FFI use cases that depend on field position and order.",
per_result_error_template: Some("{{name}}::{{variant_name}}.{{field_name}} moved from position {{position}} to {{new_position}}, in {{span_filename}}:{{span_begin_line}}"),
)