-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to make incorrect return type into error (#169)
This commit introduces a compile time error for incorrect return types. For example, the following will now fail to compile: ```rust #[swift_bridge::bridge] mod ffi { extern "Rust" { fn get_reference() -> SomeType; } } fn get_reference() -> &'static SomeType { &SomeType } ``` Before this commit the above example would compile and calling `get_reference` would cause undefined behavior.
- Loading branch information
1 parent
e5a0c89
commit e7aef34
Showing
10 changed files
with
98 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
crates/swift-bridge-macro/tests/ui/incorrect-return-type.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! # To Run | ||
//! cargo test -p swift-bridge-macro -- ui trybuild=incorrect-return-type.rs | ||
|
||
pub struct SomeType; | ||
|
||
#[swift_bridge::bridge] | ||
mod ffi { | ||
extern "Rust" { | ||
type SomeType; | ||
|
||
#[swift_bridge(rust_name = "some_function")] | ||
fn fn1() -> SomeType; | ||
#[swift_bridge(rust_name = "another_function")] | ||
fn fn2() -> SomeType; | ||
} | ||
} | ||
|
||
fn some_function() -> &'static SomeType { | ||
&SomeType | ||
} | ||
|
||
fn another_function() -> Option<SomeType> { | ||
None | ||
} | ||
|
||
fn main() {} |
23 changes: 23 additions & 0 deletions
23
crates/swift-bridge-macro/tests/ui/incorrect-return-type.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0308]: mismatched types | ||
--> tests/ui/incorrect-return-type.rs:6:1 | ||
| | ||
6 | #[swift_bridge::bridge] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| expected struct `SomeType`, found `&SomeType` | ||
| expected due to this | ||
| | ||
= note: this error originates in the attribute macro `swift_bridge::bridge` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0308]: mismatched types | ||
--> tests/ui/incorrect-return-type.rs:6:1 | ||
| | ||
6 | #[swift_bridge::bridge] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| expected struct `SomeType`, found enum `Option` | ||
| expected due to this | ||
| | ||
= note: expected struct `SomeType` | ||
found enum `Option<SomeType>` | ||
= note: this error originates in the attribute macro `swift_bridge::bridge` (in Nightly builds, run with -Z macro-backtrace for more info) |