Uh oh!
There was an error while loading. Please reload this page.
Use declarative macro for #[derive(TryFromU32)] - #145495
Conversation
rustbot
commented
Aug 16, 2025
rustbot
commented
Aug 16, 2025
Some changes occurred in coverage instrumentation. cc @Zalathar |
This comment has been minimized.
This comment has been minimized.
a1f545b to
0bb8a0eComparejieyouxu
commented
Aug 16, 2025
r? @Zalathar |
Zalathar
commented
Aug 16, 2025
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 |
hanna-kruppe
commented
Aug 16, 2025
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 |
Zalathar
commented
Aug 17, 2025
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. |
fee1-dead
commented
Aug 17, 2025
cool, #145208 is a thing. Marking this as blocked until that one lands. |
0bb8a0e to
06498d7Compare
This comment has been minimized.
This comment has been minimized.
#[derive(TryFromU32)]#[derive(TryFromU32)]06498d7 to
d429ed2Comparefee1-dead
commented
Oct 2, 2025
@rustbot ready |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Zalathar
commented
Oct 3, 2025
I have some style nits, but otherwise LGTM. |
bors
commented
Oct 5, 2025
☔ The latest upstream changes (presumably #147384) made this pull request unmergeable. Please resolve the merge conflicts. |
d429ed2 to
696b6acComparerustbot
commented
Oct 6, 2025
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
fee1-dead
commented
Oct 6, 2025
@rustbot ready |
Zalathar
commented
Oct 7, 2025
Thanks. @bors r+ rollup |
bors
commented
Oct 7, 2025
…x, r=Zalathar Use declarative macro for `#[derive(TryFromU32)]` cc `@Zalathar`
Rollup of 7 pull requests Successful merges: - #145495 (Use declarative macro for `#[derive(TryFromU32)]`) - #147165 (test: Subtract code_offset from width for ui_testing) - #147354 (Fix wrong span for hightlight for duplicated diff lines) - #147395 (Improve diagnostics: update note and add help message) - #147396 (Fluent tidy improvements) - #147407 (Update books) - #147413 (don't panic on extern with just multiple quotes in the name) r? `@ghost` `@rustbot` modify labels: rollup
Uh oh!
There was an error while loading. Please reload this page.
Rollup merge of #145495 - fee1-dead-contrib:push-tynlnktvrmrx, r=Zalathar Use declarative macro for `#[derive(TryFromU32)]` cc ``@Zalathar``
Rollup of 7 pull requests Successful merges: - rust-lang/rust#145495 (Use declarative macro for `#[derive(TryFromU32)]`) - rust-lang/rust#147165 (test: Subtract code_offset from width for ui_testing) - rust-lang/rust#147354 (Fix wrong span for hightlight for duplicated diff lines) - rust-lang/rust#147395 (Improve diagnostics: update note and add help message) - rust-lang/rust#147396 (Fluent tidy improvements) - rust-lang/rust#147407 (Update books) - rust-lang/rust#147413 (don't panic on extern with just multiple quotes in the name) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 7 pull requests Successful merges: - rust-lang/rust#145495 (Use declarative macro for `#[derive(TryFromU32)]`) - rust-lang/rust#147165 (test: Subtract code_offset from width for ui_testing) - rust-lang/rust#147354 (Fix wrong span for hightlight for duplicated diff lines) - rust-lang/rust#147395 (Improve diagnostics: update note and add help message) - rust-lang/rust#147396 (Fluent tidy improvements) - rust-lang/rust#147407 (Update books) - rust-lang/rust#147413 (don't panic on extern with just multiple quotes in the name) r? `@ghost` `@rustbot` modify labels: rollup
cc @Zalathar