Skip to content

derive: reject unions as they require unsafe code #231

Merged
GuillaumeGomez merged 2 commits intoaskama-rs:masterfrom
Kijewski:pr-no-unions
Nov 11, 2024
Merged

derive: reject unions as they require unsafe code #231
GuillaumeGomez merged 2 commits intoaskama-rs:masterfrom
Kijewski:pr-no-unions

Conversation

@Kijewski
Copy link
Copy Markdown
Member

No description provided.


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

Suspicious comment
@GuillaumeGomez
Copy link
Copy Markdown
Collaborator

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 askama-rs:master Nov 11, 2024
@Kijewski Kijewski deleted the pr-no-unions branch November 11, 2024 10:30
@Kijewski
Copy link
Copy Markdown
Member 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
Copy Markdown
Collaborator

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.

3 participants