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

derive: reject unions as they require unsafe code #231

Merged
merged 2 commits into from
Nov 11, 2024

Conversation

Kijewski
Copy link
Collaborator

No description provided.

@@ -302,9 +302,17 @@

impl TemplateArgs {
pub(crate) fn new(ast: &syn::DeriveInput) -> Result<Self, CompileError> {
// FIXME: implement once <https://github.com/rust-lang/rfcs/pull/3715> is stable

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
@GuillaumeGomez
Copy link
Contributor

I'm not sure how difficult it would be to support union. Apart from adding unsafe when accessing its fields, is there anything else?

In the meantime, merging this. Thanks!

@GuillaumeGomez GuillaumeGomez merged commit d00e638 into rinja-rs:master Nov 11, 2024
36 checks passed
@Kijewski Kijewski deleted the pr-no-unions branch November 11, 2024 10:30
@Kijewski
Copy link
Collaborator Author

Adding unsafe would be all that is needed, AFAICT. I don't actually see a use case for this feature, though, so implementing it would be far down on my to do list. We cannot simply add this feature in a safe context, because accessing union members may allow accessing uninitialized memory, which can be bad.

Actually, looking at the RFC again, I am not sure if it would be useful to us. A proc_macro does not see the #[unsafe(derive(Template))] part of #[unsafe(derive(Template))] struct X, and we would have to add e.g. a #[unsafe(derive(UnionTemplate))]. Maybe I'll think about this further and comment in rust-lang/rfcs#3715.

@GuillaumeGomez
Copy link
Contributor

Sounds good to me. Not high priority for me either.

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