Skip to content

Make derive(ULE) check for public fields #1691

@sffc

Description

@sffc

Consider the following struct, which exists in ICU4X:

pub struct Region(TinyAsciiStr<REGION_NUM_LENGTH>);

To make this into a ULE, it is tempting to simply apply #[derive(ULE)]. However, this is unsafe, because it enables the creation of Region instances that are not valid region subtags.

This footgun is shared with #[derive(Deserialize)], as we discuss at length in #1290.

To fix this, I propose that we:

  1. By default, require that fields are pub when #[derive(ULE)] is applied
  2. Allow a user to opt out of this behavior with something like #[zerovec::allow_private(reason = "...")]

@Manishearth

Metadata

Metadata

Assignees

Labels

C-zerovecComponent: Yoke, ZeroVec, DataBakeS-smallSize: One afternoon (small bug fix or enhancement)T-bugType: Bad behavior, security, privacy

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions