-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathenum_repr_int_changed.ron
66 lines (60 loc) · 2.76 KB
/
enum_repr_int_changed.ron
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
SemverQuery(
id: "enum_repr_int_changed",
human_readable_name: "enum repr(u*)/repr(i*) changed",
description: "The repr(u*) or repr(i*) attribute on an enum was changed to another integer type. This can cause its memory representation to change, breaking FFI use cases.",
required_update: Major,
// TODO: Change the reference link to point to the cargo semver reference
// once it has a section on repr(u*)/repr(i*).
reference_link: Some("https://doc.rust-lang.org/nomicon/other-reprs.html#repru-repri"),
query: r#"
{
CrateDiff {
baseline {
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @tag @output
attribute {
attr_value: value @filter(op: "regex", value: ["$repr_regex"])
@tag @output(name: "old_attr")
}
path {
path @tag @output
}
}
}
}
current {
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
path {
path @filter(op: "=", value: ["%path"])
}
# Check that there exists an attribute that:
# - looks like repr(i*) or repr(u*)
# - but is not the same repr(i*) or repr(u*) that we had before.
# This is the breaking change.
attribute @fold @transform(op: "count") @filter(op: ">", value: ["$zero"]) {
value @filter(op: "regex", value: ["$repr_regex"])
@filter(op: "!=", value: ["%attr_value"])
@output(name: "new_attr")
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"repr_regex": "#\\[repr\\([ui]\\d+|size\\)\\]",
"zero": 0,
},
error_message: "The repr(u*) or repr(i*) attribute on an enum was changed to another integer type. This can cause its memory representation to change, breaking FFI use cases.",
per_result_error_template: Some("enum {{name}} {{old_attr}} -> {{new_attr.0}} in {{span_filename}}:{{span_begin_line}}"),
)