Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that externally-defined functions going safe -> unsafe are caught. #1003

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test_crates/safe_vs_unsafe_extern_fn/new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "safe_vs_unsafe_extern_fn"
version = "0.1.0"
edition = "2021"

[dependencies]
29 changes: 29 additions & 0 deletions test_crates/safe_vs_unsafe_extern_fn/new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![feature(unsafe_extern_blocks)] // Remove after our lowest tested Rust version is 1.82+.

unsafe extern "C" {
pub fn originally_legacy_now_unsafe_extern_and_implicit_unsafe();

pub unsafe fn originally_legacy_now_unsafe_extern_and_explicit_unsafe();

pub safe fn originally_legacy_now_unsafe_extern_and_safe();
}

unsafe extern "C" {
pub fn originally_explicit_now_implicit_unsafe();

pub unsafe fn originally_implicit_now_explicit_unsafe();

pub fn originally_safe_now_implicit_unsafe();

pub unsafe fn originally_safe_now_explicit_unsafe();
}

// This is the "legacy" way of specifying `extern`.
extern "C" {
pub fn originally_implicit_unsafe_now_legacy();

pub fn originally_explicit_unsafe_now_legacy();

// This is a breaking change!
pub fn originally_safe_now_legacy();
}
7 changes: 7 additions & 0 deletions test_crates/safe_vs_unsafe_extern_fn/old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "safe_vs_unsafe_extern_fn"
version = "0.1.0"
edition = "2021"

[dependencies]
27 changes: 27 additions & 0 deletions test_crates/safe_vs_unsafe_extern_fn/old/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![feature(unsafe_extern_blocks)] // Remove after our lowest tested Rust version is 1.82+.

extern "C" {
pub fn originally_legacy_now_unsafe_extern_and_implicit_unsafe();

pub fn originally_legacy_now_unsafe_extern_and_explicit_unsafe();

pub fn originally_legacy_now_unsafe_extern_and_safe();
}

unsafe extern "C" {
pub unsafe fn originally_explicit_now_implicit_unsafe();

pub fn originally_implicit_now_explicit_unsafe();

pub safe fn originally_safe_now_implicit_unsafe();

pub safe fn originally_safe_now_explicit_unsafe();
}

unsafe extern "C" {
pub fn originally_implicit_unsafe_now_legacy();

pub unsafe fn originally_explicit_unsafe_now_legacy();

pub safe fn originally_safe_now_legacy();
}
32 changes: 32 additions & 0 deletions test_outputs/query_execution/function_unsafe_added.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,36 @@ expression: "&query_execution_results"
"visibility_limit": String("public"),
},
],
"./test_crates/safe_vs_unsafe_extern_fn/": [
{
"name": String("originally_safe_now_implicit_unsafe"),
"path": List([
String("safe_vs_unsafe_extern_fn"),
String("originally_safe_now_implicit_unsafe"),
]),
"span_begin_line": Uint64(16),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("originally_safe_now_explicit_unsafe"),
"path": List([
String("safe_vs_unsafe_extern_fn"),
String("originally_safe_now_explicit_unsafe"),
]),
"span_begin_line": Uint64(18),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("originally_safe_now_legacy"),
"path": List([
String("safe_vs_unsafe_extern_fn"),
String("originally_safe_now_legacy"),
]),
"span_begin_line": Uint64(28),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
],
}
Loading