Skip to content

Commit 6172415

Browse files
authored
Add function_abi_now_unwind lint and fix function_abi_no_longer_unwind. (#1061)
The `function_abi_no_longer_unwind` lint had false-positives since it failed to connect the baseline and current functions by their import paths.
1 parent f55dc22 commit 6172415

File tree

7 files changed

+112
-2
lines changed

7 files changed

+112
-2
lines changed

src/lints/function_abi_no_longer_unwind.ron

+12-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ SemverQuery(
1616
name @output
1717
1818
new_abi_: abi {
19-
name @tag
19+
name @tag(name: "abi")
2020
raw_name @output
2121
unwind @filter(op: "!=", value: ["$true"])
2222
}
2323
24+
importable_path {
25+
path @output @tag
26+
public_api @filter(op: "=", value: ["$true"])
27+
}
28+
2429
span_: span @optional {
2530
filename @output
2631
begin_line @output
@@ -34,10 +39,15 @@ SemverQuery(
3439
visibility_limit @filter(op: "=", value: ["$public"])
3540
3641
abi_: abi {
37-
name @filter(op: "=", value: ["%name"])
42+
name @filter(op: "=", value: ["%abi"])
3843
raw_name @output
3944
unwind @filter(op: "=", value: ["$true"])
4045
}
46+
47+
importable_path {
48+
path @filter(op: "=", value: ["%path"])
49+
public_api @filter(op: "=", value: ["$true"])
50+
}
4151
}
4252
}
4353
}

src/lints/function_abi_now_unwind.ron

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
SemverQuery(
2+
id: "function_abi_now_unwind",
3+
human_readable_name: "function abi is now unwind-capable",
4+
description: "A pub fn changed from an non-unwind ABI to the same-named ABI with unwind ability. This change might not be compatible with callers of this function, since they may not expect unwinding to happen here.",
5+
required_update: Major,
6+
lint_level: Deny,
7+
reference_link: Some("https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html"),
8+
query: r#"
9+
{
10+
CrateDiff {
11+
current {
12+
item {
13+
... on Function {
14+
visibility_limit @filter(op: "=", value: ["$public"])
15+
16+
name @output
17+
18+
new_abi_: abi {
19+
name @tag(name: "abi")
20+
raw_name @output
21+
unwind @filter(op: "=", value: ["$true"])
22+
}
23+
24+
importable_path {
25+
path @output @tag
26+
public_api @filter(op: "=", value: ["$true"])
27+
}
28+
29+
span_: span @optional {
30+
filename @output
31+
begin_line @output
32+
}
33+
}
34+
}
35+
}
36+
baseline {
37+
item {
38+
... on Function {
39+
visibility_limit @filter(op: "=", value: ["$public"])
40+
41+
abi_: abi {
42+
name @filter(op: "=", value: ["%abi"])
43+
raw_name @output
44+
unwind @filter(op: "!=", value: ["$true"])
45+
}
46+
47+
importable_path {
48+
path @filter(op: "=", value: ["%path"])
49+
public_api @filter(op: "=", value: ["$true"])
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}"#,
56+
arguments: {
57+
"public": "public",
58+
"true": true,
59+
},
60+
error_message: "A pub fn changed from a non-unwind ABI to the same-named ABI with unwind ability. This change might not be compatible with callers of this function, since they may not expect unwinding to happen here.",
61+
per_result_error_template: Some("{{join \"::\" path}} changed ABI from {{abi_raw_name}} to {{new_abi_raw_name}} in {{span_filename}}:{{span_begin_line}}"),
62+
)

src/query.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ add_lints!(
11521152
feature_missing,
11531153
feature_not_enabled_by_default,
11541154
function_abi_no_longer_unwind,
1155+
function_abi_now_unwind,
11551156
function_changed_abi,
11561157
function_const_removed,
11571158
function_export_name_changed,
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
pub extern "C" fn unwind_function_becomes_non_unwind() {}
2+
3+
pub extern "C-unwind" fn non_unwind_function_becomes_unwind() {}
4+
5+
pub extern "C" fn non_unwind_function_unchanged() {}
6+
7+
pub extern "C-unwind" fn unwind_function_unchanged() {}
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
pub extern "C-unwind" fn unwind_function_becomes_non_unwind() {}
2+
3+
pub extern "C" fn non_unwind_function_becomes_unwind() {}
4+
5+
pub extern "C" fn non_unwind_function_unchanged() {}
6+
7+
pub extern "C-unwind" fn unwind_function_unchanged() {}

test_outputs/query_execution/function_abi_no_longer_unwind.snap

+5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
---
22
source: src/query.rs
33
expression: "&query_execution_results"
4+
snapshot_kind: text
45
---
56
{
67
"./test_crates/function_abi_no_longer_unwind/": [
78
{
89
"abi_raw_name": String("C-unwind"),
910
"name": String("unwind_function_becomes_non_unwind"),
1011
"new_abi_raw_name": String("C"),
12+
"path": List([
13+
String("function_abi_no_longer_unwind"),
14+
String("unwind_function_becomes_non_unwind"),
15+
]),
1116
"span_begin_line": Uint64(1),
1217
"span_filename": String("src/lib.rs"),
1318
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
source: src/query.rs
3+
expression: "&query_execution_results"
4+
snapshot_kind: text
5+
---
6+
{
7+
"./test_crates/function_abi_no_longer_unwind/": [
8+
{
9+
"abi_raw_name": String("C"),
10+
"name": String("non_unwind_function_becomes_unwind"),
11+
"new_abi_raw_name": String("C-unwind"),
12+
"path": List([
13+
String("function_abi_no_longer_unwind"),
14+
String("non_unwind_function_becomes_unwind"),
15+
]),
16+
"span_begin_line": Uint64(3),
17+
"span_filename": String("src/lib.rs"),
18+
},
19+
],
20+
}

0 commit comments

Comments
 (0)