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

fix: #[no_mangle] error in Rust 2024 Edition #2447

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

martinmose
Copy link
Contributor

@martinmose martinmose commented Feb 21, 2025

Hey,

I know, I know - Rust 2024 just dropped, and I’m not trying to rush anything. But after upgrading to the Rust 2024 edition, I ran into the following build error:

error: unsafe attribute used without unsafe
  --> /Users/martinmose/project/target/debug/build/project_shared-0c37e55cf0c6dc4f/out/project_shared.uniffi.rs:96:3
   |
96 | #[no_mangle]
   |   ^^^^^^^^^ usage of unsafe attribute
   |
help: wrap the attribute in `unsafe(...)`
   |
96 | #[unsafe(no_mangle)]
   |   +++++++         +

I found this Unsafe Attributes

This seems like a simple fix - just wrapping #[no_mangle] in #[unsafe(...)]. But maybe there is something I’m unaware of?

It looks like it fixes my upgraded Rust project at least 😅

@martinmose martinmose requested a review from a team as a code owner February 21, 2025 13:53
@martinmose martinmose requested review from gruberb and removed request for a team February 21, 2025 13:53
@bendk
Copy link
Contributor

bendk commented Feb 21, 2025

Looks like this doesn't work on older editions though, based on the CI.

Maybe we could add an #[allow] to prevent the error? If not, I guess we'd need some sort of config option where you specify which edition you're targetting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants