diff --git a/src/lints/function_abi_no_longer_unwind.ron b/src/lints/function_abi_no_longer_unwind.ron new file mode 100644 index 00000000..2e699cb6 --- /dev/null +++ b/src/lints/function_abi_no_longer_unwind.ron @@ -0,0 +1,51 @@ +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. 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#" + { + 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: "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}}"), +) diff --git a/src/query.rs b/src/query.rs index ff59aef6..f08045ac 100644 --- a/src/query.rs +++ b/src/query.rs @@ -476,6 +476,7 @@ macro_rules! add_lints { } add_lints!( + function_abi_no_longer_unwind, pub_module_level_const_now_doc_hidden, enum_struct_variant_field_now_doc_hidden, enum_tuple_variant_field_now_doc_hidden, diff --git a/test_crates/function_abi_no_longer_unwind/new/Cargo.toml b/test_crates/function_abi_no_longer_unwind/new/Cargo.toml new file mode 100644 index 00000000..0cfe78f0 --- /dev/null +++ b/test_crates/function_abi_no_longer_unwind/new/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "function_abi_no_longer_unwind" +version = "0.1.0" +edition = "2021" + +[dependencies] 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/function_abi_no_longer_unwind/old/Cargo.toml b/test_crates/function_abi_no_longer_unwind/old/Cargo.toml new file mode 100644 index 00000000..0cfe78f0 --- /dev/null +++ b/test_crates/function_abi_no_longer_unwind/old/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "function_abi_no_longer_unwind" +version = "0.1.0" +edition = "2021" + +[dependencies] 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_outputs/function_abi_no_longer_unwind.output.ron b/test_outputs/function_abi_no_longer_unwind.output.ron new file mode 100644 index 00000000..d3774dd0 --- /dev/null +++ b/test_outputs/function_abi_no_longer_unwind.output.ron @@ -0,0 +1,11 @@ +{ + "./test_crates/function_abi_no_longer_unwind/": [ + { + "abi_raw_name": String("C-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"), + }, + ], +}