From 1e791ac0abc67cbae8cb9816a93b8af0c2a12e0d Mon Sep 17 00:00:00 2001 From: qstommyshu Date: Sat, 9 Mar 2024 10:25:49 -0500 Subject: [PATCH 1/7] add unwind_function_missing lint --- src/lints/unwind_function_missing.ron | 51 +++++++++++++++++++ src/query.rs | 1 + .../unwind_function_missing/new/Cargo.toml | 7 +++ .../unwind_function_missing/new/src/lib.rs | 1 + .../unwind_function_missing/old/Cargo.toml | 7 +++ .../unwind_function_missing/old/src/lib.rs | 1 + .../unwind_function_missing.output.ron | 12 +++++ 7 files changed, 80 insertions(+) create mode 100644 src/lints/unwind_function_missing.ron create mode 100644 test_crates/unwind_function_missing/new/Cargo.toml create mode 100644 test_crates/unwind_function_missing/new/src/lib.rs create mode 100644 test_crates/unwind_function_missing/old/Cargo.toml create mode 100644 test_crates/unwind_function_missing/old/src/lib.rs create mode 100644 test_outputs/unwind_function_missing.output.ron diff --git a/src/lints/unwind_function_missing.ron b/src/lints/unwind_function_missing.ron new file mode 100644 index 00000000..50c53d0e --- /dev/null +++ b/src/lints/unwind_function_missing.ron @@ -0,0 +1,51 @@ +SemverQuery( + id: "unwind_function_missing", + human_readable_name: "unwind function missing", + description: "pub fn changed from an unwind-capable ABI to the same-named ABI without unwind: \"C-unwind\" to \"C\"", + required_update: Major, + reference_link: None, + query: r#" + { + CrateDiff { + baseline { + item { + ... on Function { + visibility_limit @filter(op: "=", value: ["$public"]) + + abi_: abi { + name @tag + raw_name @output + unwind @filter(op: "=", value: ["$true"]) + } + } + } + } + current { + item { + ... on Function { + visibility_limit @filter(op: "=", value: ["$public"]) + + name @output + + new_abi_: abi { + name @filter(op: "=", value: ["%name"]) + raw_name @output + unwind @filter(op: "!=", value: ["$true"]) + } + + span_: span @optional { + filename @output + begin_line @output + } + } + } + } + } + }"#, + arguments: { + "public": "public", + "true": true, + }, + error_message: "An unwind-capable ABI changed to same-named ABI without unwind", + per_result_error_template: Some("pub fn {{name}} changed ABI from {{abi_raw_name}} to {{new_abi_raw_name}} in {{span_filename}}:{{span_begin_line}}"), +) \ No newline at end of file diff --git a/src/query.rs b/src/query.rs index 5a6b8267..7dacde90 100644 --- a/src/query.rs +++ b/src/query.rs @@ -534,4 +534,5 @@ add_lints!( repr_packed_removed, exported_function_changed_abi, union_now_doc_hidden, + unwind_function_missing, ); diff --git a/test_crates/unwind_function_missing/new/Cargo.toml b/test_crates/unwind_function_missing/new/Cargo.toml new file mode 100644 index 00000000..a451d2a0 --- /dev/null +++ b/test_crates/unwind_function_missing/new/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "unwind_function_missing" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/unwind_function_missing/new/src/lib.rs b/test_crates/unwind_function_missing/new/src/lib.rs new file mode 100644 index 00000000..ccab0e5b --- /dev/null +++ b/test_crates/unwind_function_missing/new/src/lib.rs @@ -0,0 +1 @@ +pub extern "C" fn unwind_function_becomes_without_unwind() -> () {} \ No newline at end of file diff --git a/test_crates/unwind_function_missing/old/Cargo.toml b/test_crates/unwind_function_missing/old/Cargo.toml new file mode 100644 index 00000000..a451d2a0 --- /dev/null +++ b/test_crates/unwind_function_missing/old/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "unwind_function_missing" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/unwind_function_missing/old/src/lib.rs b/test_crates/unwind_function_missing/old/src/lib.rs new file mode 100644 index 00000000..b23dc014 --- /dev/null +++ b/test_crates/unwind_function_missing/old/src/lib.rs @@ -0,0 +1 @@ +pub extern "C-unwind" fn unwind_function_becomes_without_unwind() -> () {} \ No newline at end of file diff --git a/test_outputs/unwind_function_missing.output.ron b/test_outputs/unwind_function_missing.output.ron new file mode 100644 index 00000000..7a857191 --- /dev/null +++ b/test_outputs/unwind_function_missing.output.ron @@ -0,0 +1,12 @@ +{ + "./test_crates/unwind_function_missing/": [ + { + "abi_raw_name": String("C-unwind"), + "name": String("unwind_function_becomes_without_unwind"), + "new_abi_raw_name": String("C"), + "span_begin_line": Uint64(1), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + ], +} \ No newline at end of file From a483787539f06be6e07d8086801ae806775e8df2 Mon Sep 17 00:00:00 2001 From: qstommyshu Date: Sat, 9 Mar 2024 10:32:59 -0500 Subject: [PATCH 2/7] fix unwind_function_missing lint output --- test_outputs/unwind_function_missing.output.ron | 1 - 1 file changed, 1 deletion(-) diff --git a/test_outputs/unwind_function_missing.output.ron b/test_outputs/unwind_function_missing.output.ron index 7a857191..02c6f73b 100644 --- a/test_outputs/unwind_function_missing.output.ron +++ b/test_outputs/unwind_function_missing.output.ron @@ -6,7 +6,6 @@ "new_abi_raw_name": String("C"), "span_begin_line": Uint64(1), "span_filename": String("src/lib.rs"), - "visibility_limit": String("public"), }, ], } \ No newline at end of file From f5908052c49e9f700a0bd115fe4989acf928c952 Mon Sep 17 00:00:00 2001 From: Tommy shu <56746466+qstommyshu@users.noreply.github.com> Date: Mon, 11 Mar 2024 08:45:20 -0400 Subject: [PATCH 3/7] Update src/lints/unwind_function_missing.ron add trailing newline to unwind_function_missing.ron Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> --- src/lints/unwind_function_missing.ron | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lints/unwind_function_missing.ron b/src/lints/unwind_function_missing.ron index 50c53d0e..4bf28e32 100644 --- a/src/lints/unwind_function_missing.ron +++ b/src/lints/unwind_function_missing.ron @@ -48,4 +48,4 @@ SemverQuery( }, error_message: "An unwind-capable ABI changed to same-named ABI without unwind", per_result_error_template: Some("pub fn {{name}} changed ABI from {{abi_raw_name}} to {{new_abi_raw_name}} in {{span_filename}}:{{span_begin_line}}"), -) \ No newline at end of file +) From dfffe7f2c00a2937335e2d3650bba38dcbc885f2 Mon Sep 17 00:00:00 2001 From: Tommy shu <56746466+qstommyshu@users.noreply.github.com> Date: Mon, 11 Mar 2024 08:48:22 -0400 Subject: [PATCH 4/7] Omit function return type as it returns a unit Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> --- test_crates/unwind_function_missing/new/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_crates/unwind_function_missing/new/src/lib.rs b/test_crates/unwind_function_missing/new/src/lib.rs index ccab0e5b..3431f0a5 100644 --- a/test_crates/unwind_function_missing/new/src/lib.rs +++ b/test_crates/unwind_function_missing/new/src/lib.rs @@ -1 +1 @@ -pub extern "C" fn unwind_function_becomes_without_unwind() -> () {} \ No newline at end of file +pub extern "C" fn unwind_function_becomes_without_unwind() {} \ No newline at end of file From d0c2614b8b97d43ed9911813a6cb4937d3bdf195 Mon Sep 17 00:00:00 2001 From: qstommyshu Date: Mon, 11 Mar 2024 11:31:16 -0400 Subject: [PATCH 5/7] add reference link for C-unwind ABI --- src/lints/unwind_function_missing.ron | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lints/unwind_function_missing.ron b/src/lints/unwind_function_missing.ron index 4bf28e32..c3e1ac94 100644 --- a/src/lints/unwind_function_missing.ron +++ b/src/lints/unwind_function_missing.ron @@ -3,7 +3,7 @@ SemverQuery( human_readable_name: "unwind function missing", description: "pub fn changed from an unwind-capable ABI to the same-named ABI without unwind: \"C-unwind\" to \"C\"", required_update: Major, - reference_link: None, + reference_link: Some("https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html"), query: r#" { CrateDiff { From 61ab58c8634a721f4f24f4c1089728178c5c2e46 Mon Sep 17 00:00:00 2001 From: qstommyshu Date: Mon, 11 Mar 2024 12:26:51 -0400 Subject: [PATCH 6/7] change lint name to function_abi_no_longer_unwind --- ...tion_missing.ron => function_abi_no_longer_unwind.ron} | 8 ++++---- src/query.rs | 2 +- .../new/Cargo.toml | 2 +- test_crates/function_abi_no_longer_unwind/new/src/lib.rs | 1 + .../old/Cargo.toml | 2 +- test_crates/function_abi_no_longer_unwind/old/src/lib.rs | 1 + test_crates/unwind_function_missing/new/src/lib.rs | 1 - test_crates/unwind_function_missing/old/src/lib.rs | 1 - ...utput.ron => function_abi_no_longer_unwind.output.ron} | 6 +++--- 9 files changed, 12 insertions(+), 12 deletions(-) rename src/lints/{unwind_function_missing.ron => function_abi_no_longer_unwind.ron} (83%) rename test_crates/{unwind_function_missing => function_abi_no_longer_unwind}/new/Cargo.toml (66%) create mode 100644 test_crates/function_abi_no_longer_unwind/new/src/lib.rs rename test_crates/{unwind_function_missing => function_abi_no_longer_unwind}/old/Cargo.toml (66%) create mode 100644 test_crates/function_abi_no_longer_unwind/old/src/lib.rs delete mode 100644 test_crates/unwind_function_missing/new/src/lib.rs delete mode 100644 test_crates/unwind_function_missing/old/src/lib.rs rename test_outputs/{unwind_function_missing.output.ron => function_abi_no_longer_unwind.output.ron} (63%) diff --git a/src/lints/unwind_function_missing.ron b/src/lints/function_abi_no_longer_unwind.ron similarity index 83% rename from src/lints/unwind_function_missing.ron rename to src/lints/function_abi_no_longer_unwind.ron index c3e1ac94..831c2733 100644 --- a/src/lints/unwind_function_missing.ron +++ b/src/lints/function_abi_no_longer_unwind.ron @@ -1,7 +1,7 @@ SemverQuery( - id: "unwind_function_missing", - human_readable_name: "unwind function missing", - description: "pub fn changed from an unwind-capable ABI to the same-named ABI without unwind: \"C-unwind\" to \"C\"", + id: "function_abi_no_longer_unwind", + human_readable_name: "function abi no longer unwind", + description: "A pub fn changed from an unwind-capable ABI to the same-named ABI without unwind", required_update: Major, reference_link: Some("https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html"), query: r#" @@ -46,6 +46,6 @@ SemverQuery( "public": "public", "true": true, }, - error_message: "An unwind-capable ABI changed to same-named ABI without unwind", + error_message: "A pub fn changed from an unwind-capable ABI to the same-named ABI without unwind", per_result_error_template: Some("pub fn {{name}} changed ABI from {{abi_raw_name}} to {{new_abi_raw_name}} in {{span_filename}}:{{span_begin_line}}"), ) diff --git a/src/query.rs b/src/query.rs index 7dacde90..5c308e9a 100644 --- a/src/query.rs +++ b/src/query.rs @@ -469,6 +469,7 @@ macro_rules! add_lints { } add_lints!( + function_abi_no_longer_unwind, enum_struct_variant_field_now_doc_hidden, enum_tuple_variant_field_now_doc_hidden, trait_method_now_doc_hidden, @@ -534,5 +535,4 @@ add_lints!( repr_packed_removed, exported_function_changed_abi, union_now_doc_hidden, - unwind_function_missing, ); diff --git a/test_crates/unwind_function_missing/new/Cargo.toml b/test_crates/function_abi_no_longer_unwind/new/Cargo.toml similarity index 66% rename from test_crates/unwind_function_missing/new/Cargo.toml rename to test_crates/function_abi_no_longer_unwind/new/Cargo.toml index a451d2a0..0cfe78f0 100644 --- a/test_crates/unwind_function_missing/new/Cargo.toml +++ b/test_crates/function_abi_no_longer_unwind/new/Cargo.toml @@ -1,6 +1,6 @@ [package] publish = false -name = "unwind_function_missing" +name = "function_abi_no_longer_unwind" version = "0.1.0" edition = "2021" diff --git a/test_crates/function_abi_no_longer_unwind/new/src/lib.rs b/test_crates/function_abi_no_longer_unwind/new/src/lib.rs new file mode 100644 index 00000000..88f0a4f6 --- /dev/null +++ b/test_crates/function_abi_no_longer_unwind/new/src/lib.rs @@ -0,0 +1 @@ +pub extern "C" fn unwind_function_becomes_non_unwind() {} diff --git a/test_crates/unwind_function_missing/old/Cargo.toml b/test_crates/function_abi_no_longer_unwind/old/Cargo.toml similarity index 66% rename from test_crates/unwind_function_missing/old/Cargo.toml rename to test_crates/function_abi_no_longer_unwind/old/Cargo.toml index a451d2a0..0cfe78f0 100644 --- a/test_crates/unwind_function_missing/old/Cargo.toml +++ b/test_crates/function_abi_no_longer_unwind/old/Cargo.toml @@ -1,6 +1,6 @@ [package] publish = false -name = "unwind_function_missing" +name = "function_abi_no_longer_unwind" version = "0.1.0" edition = "2021" diff --git a/test_crates/function_abi_no_longer_unwind/old/src/lib.rs b/test_crates/function_abi_no_longer_unwind/old/src/lib.rs new file mode 100644 index 00000000..3921c503 --- /dev/null +++ b/test_crates/function_abi_no_longer_unwind/old/src/lib.rs @@ -0,0 +1 @@ +pub extern "C-unwind" fn unwind_function_becomes_non_unwind() {} diff --git a/test_crates/unwind_function_missing/new/src/lib.rs b/test_crates/unwind_function_missing/new/src/lib.rs deleted file mode 100644 index 3431f0a5..00000000 --- a/test_crates/unwind_function_missing/new/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub extern "C" fn unwind_function_becomes_without_unwind() {} \ No newline at end of file diff --git a/test_crates/unwind_function_missing/old/src/lib.rs b/test_crates/unwind_function_missing/old/src/lib.rs deleted file mode 100644 index b23dc014..00000000 --- a/test_crates/unwind_function_missing/old/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub extern "C-unwind" fn unwind_function_becomes_without_unwind() -> () {} \ No newline at end of file diff --git a/test_outputs/unwind_function_missing.output.ron b/test_outputs/function_abi_no_longer_unwind.output.ron similarity index 63% rename from test_outputs/unwind_function_missing.output.ron rename to test_outputs/function_abi_no_longer_unwind.output.ron index 02c6f73b..d3774dd0 100644 --- a/test_outputs/unwind_function_missing.output.ron +++ b/test_outputs/function_abi_no_longer_unwind.output.ron @@ -1,11 +1,11 @@ { - "./test_crates/unwind_function_missing/": [ + "./test_crates/function_abi_no_longer_unwind/": [ { "abi_raw_name": String("C-unwind"), - "name": String("unwind_function_becomes_without_unwind"), + "name": String("unwind_function_becomes_non_unwind"), "new_abi_raw_name": String("C"), "span_begin_line": Uint64(1), "span_filename": String("src/lib.rs"), }, ], -} \ No newline at end of file +} From 35d9443a0161797f557a160a4d7b6f28a3349f0e Mon Sep 17 00:00:00 2001 From: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> Date: Mon, 11 Mar 2024 13:20:09 -0400 Subject: [PATCH 7/7] Extend description of why this is a breaking change. --- src/lints/function_abi_no_longer_unwind.ron | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lints/function_abi_no_longer_unwind.ron b/src/lints/function_abi_no_longer_unwind.ron index 831c2733..2e699cb6 100644 --- a/src/lints/function_abi_no_longer_unwind.ron +++ b/src/lints/function_abi_no_longer_unwind.ron @@ -1,7 +1,7 @@ SemverQuery( id: "function_abi_no_longer_unwind", human_readable_name: "function abi no longer unwind", - description: "A pub fn changed from an unwind-capable ABI to the same-named ABI without unwind", + description: "A pub fn changed from an unwind-capable ABI to the same-named ABI without unwind. If that function causes an unwind (e.g. by panicking), its behavior is now undefined.", required_update: Major, reference_link: Some("https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html"), query: r#" @@ -46,6 +46,6 @@ SemverQuery( "public": "public", "true": true, }, - error_message: "A pub fn changed from an unwind-capable ABI to the same-named ABI without unwind", + error_message: "A pub fn changed from an unwind-capable ABI to the same-named ABI without unwind. If that function causes an unwind (e.g. by panicking), its behavior is now undefined.", per_result_error_template: Some("pub fn {{name}} changed ABI from {{abi_raw_name}} to {{new_abi_raw_name}} in {{span_filename}}:{{span_begin_line}}"), )