8000 BREAKING: Use `#[non_exhaustive]` on structs? · Issue #1867 · dtolnay/syn · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

BREAKING: Use #[non_exhaustive] on structs? #1867

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

Closed
madsmtm opened this issue May 19, 2025 · 4 comments
Closed

BREAKING: Use #[non_exhaustive] on structs? #1867

madsmtm opened this issue May 19, 2025 · 4 comments

Comments

@madsmtm
Copy link
madsmtm commented May 19, 2025

In v3.x, it might make sense to use #[non_exhaustive] on syn's structs. As long as some kind of fn new or impl Default is provided, users would still be able to construct structs manually, while still allowing the language to evolve further.

I'm not entirely sure yet which structs should have this attribute, but I think it should basically be "all, unless a good argument is given as to why not". As an example, Abi probably shouldn't be, since it's basically a small helper struct. But ItemStruct definitely should (imagine the language wanted add unsafe struct Foo {} or extern "C" struct Foo {}).

This would have avoided the issues in #1851.

@dtolnay
Copy link
Owner
dtolnay commented May 20, 2025

I prefer not to make this change. With rust-lang/lang-team#143, non_exhaustive is too disruptive on being able to conveniently construct syntax trees.

@dtolnay dtolnay closed this as completed May 20, 2025
@jhpratt
Copy link
jhpratt commented May 20, 2025

@dtolnay Perhaps it would be more feasible to use the pre-attribute hack of having a __non_exhaustive field? The type could even be inaccessible, effectively preventing manual construction.

@dtolnay
Copy link
Owner
dtolnay commented May 20, 2025

That alternative has all of the same downsides.

@jhpratt
Copy link
jhpratt commented May 20, 2025

Ah, I see. You want to be able to do it but the attribute prevents it. I interpreted it the other way around.

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

No branches or pull requests

3 participants
0