Skip to content

Commit

Permalink
Test that externally-defined functions going safe -> unsafe are caugh…
Browse files Browse the repository at this point in the history
…t. (#1003)
  • Loading branch information
obi1kenobi authored Dec 6, 2024
1 parent c0c1cc0 commit a4937e1
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
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"),
},
],
}

0 comments on commit a4937e1

Please sign in to comment.