Skip to content

Conversation

aleb
Copy link
Contributor

@aleb aleb commented Jul 11, 2025

Fixes #8614

@fliiiix
Copy link
Contributor

fliiiix commented Jul 21, 2025

@aardappel I just tested this (and it looks ok to me) and it would be great if Flatbuffers could also support the 2024 edition

@aardappel
Copy link
Collaborator

I don't know much about Rust, but would it not be possible to put unsafe inside these functions it is now wrapping instead?

@fliiiix
Copy link
Contributor

fliiiix commented Jul 25, 2025

I also do not have a lot experience in rust tbh. But from reading the error message in #8614 and the docs https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html it is now required to wrap the unsafe calls in a unsafe function see:

image

And this is what this MR does i guess

aleb added 4 commits July 25, 2025 16:08
The errors look like:

```
warning[E0133]: call to unsafe function `fbs::flatbuffers::emplace_scalar` is unsafe and requires unsafe block
warning[E0133]: call to unsafe function `fbs::flatbuffers::follow_cast_ref` is unsafe and requires unsafe block
warning[E0133]: call to unsafe function `fbs::flatbuffers::Follow::follow` is unsafe and requires unsafe block
warning[E0133]: call to unsafe function `fbs::flatbuffers::read_scalar_at` is unsafe and requires unsafe block
warning[E0133]: call to unsafe function `fbs::flatbuffers::root_unchecked` is unsafe and requires unsafe block
warning[E0133]: call to unsafe function `fbs::flatbuffers::size_prefixed_root_unchecked` is unsafe and requires unsafe block
warning[E0133]: call to unsafe function `fbs::flatbuffers::Table::<'a>::new` is unsafe and requires unsafe block
warning[E0133]: call to unsafe function `std::slice::from_raw_parts` is unsafe and requires unsafe block
```
Ran `goldens/generate_goldens.py`
Ran `scripts/generate_code.py`
@aardappel aardappel enabled auto-merge (squash) July 25, 2025 23:10
@aardappel
Copy link
Collaborator

Ok, thanks for the clarification!

There's unrelated changes in here to the .md files that in the future would be better in a separate PR.

Otherwise LGTM.

@aardappel aardappel merged commit 860d645 into google:master Jul 25, 2025
49 checks passed
@aleb
Copy link
Contributor Author

aleb commented Jul 29, 2025

I don't know much about Rust, but would it not be possible to put unsafe inside these functions it is now wrapping instead?

It depends on where we are comfortable to declare unsafe things as safe-enough. To me it looks ok at the moment.

Thanks for merging!

@aleb
Copy link
Contributor Author

aleb commented Jul 29, 2025

Hmm, looking again at the changes, I see the unsafe functions are used in generated unsafe functions, so making them "safe" would not make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ codegen Involving generating code from schema documentation Documentation rust
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Rust] Address lint unsafe_op_in_unsafe_fn since it is now warn by default in 2024 edition
3 participants