-
Notifications
You must be signed in to change notification settings - Fork 13.7k
remove #[derive(TryFromU32)]
#145495
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
base: master
Are you sure you want to change the base?
remove #[derive(TryFromU32)]
#145495
Conversation
Some changes occurred in coverage instrumentation. cc @Zalathar |
This comment has been minimized.
This comment has been minimized.
seems like it could just be replaced with a declarative macro
a1f545b
to
0bb8a0e
Compare
r? @Zalathar |
Is there some reason to do this? I don’t understand the motivation for wanting to make these enums considerably harder to maintain. |
procedural macros hurt build times because it feeds tokens to a parser for each procedural macro called for each type. There's no point in using a procedural macro for something this trivial. There are alternatives to this, if you don't like maintaining two lists (is that really hard? just two lists, and you get compiler errors if one doesn't match the other). One is to wrap the whole thing in the declarative macro, doable but I don't like how it looks. The other is to use the upcoming On the other hand, one additional procedural macro in |
I've written and used macros like this before and as I've kept working on and around the types they're applied to, I've noticed various small papercuts that make it mildly more annoying to work with than I have less hands-on experience with attribute macros but they also have some papercuts (e.g., rust-analyzer problems like rust-lang/rust-analyzer#19944). They're also conceptually the wrong tool here: derive is exactly for adding impls, attr macros are the bigger gun for when you need to transform and re-emit the input tokens. I'd suggest waiting for #145208 to be merged and reach beta, then it can stay a derive with the same use-site ergonomics as always. This is a perfect use case for it, and this change doesn't seem particularly time critical. There shouldn't be any build time benefits since cg_llvm still depends on |
Normally I'm very much in favour of removing needlessly-complex macros from rustc; we have far too many of them already. The fact that I was willing to add a proc-macro (with tests!) in this case should indicate how strongly I believe that it really is justified. Not having to redundantly list all variants of an FFI enum is a really big deal, as is being able to easily add When #145208 is available in stage0, I think it might we worth trying to use that instead. But I don't see any benefit in removing the existing derive at this time. It meaningfully increases the difficulty of maintaining FFI bindings to LLVM, in exchange for shuffling macro complexity around without actually decreasing it. |
cool, #145208 is a thing. Marking this as blocked until that one lands. |
seems like it could just be replaced with a declarative macro
cc @Zalathar