-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Generate default impl when converting #[derive(Debug)]
to manual impl
#9814
Conversation
crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
Outdated
Show resolved
Hide resolved
CI is currently failing on: thread 'tidy::files_are_tidy' panicked at '
TODO markers or todo! macros should not be committed to the master branch,
use FIXME instead
/home/runner/work/rust-analyzer/rust-analyzer/crates/ide_assists/src/tests/generated.rs
', crates/rust-analyzer/tests/slow-tests/tidy.rs:292:9 But looking at the code diff, the only change we've made to the file is removing a cc/ @Veykril. |
Heh, thats a fun one. So the generated tests still contain a I think you can just add the path of the |
Updated with feedback from review. Waiting on CI to pass now ✨ edit: yay, it passes! 🎉 - think it's good to merge now! |
✌️ yoshuawuyts can now approve this pull request. To approve and merge a pull request, simply reply with |
Can we avoid some of the |
I agree, minimizing unwraps where possible is a good choice. |
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Implemented all remaining feedback! bors r+ |
9825: Generate default impl when converting #[derive(Default)] to manual impl r=Veykril a=yoshuawuyts Similar to #9814, but for `#[derive(Default)]`. Thanks! ## Follow-up steps I've added the tests inside `handlers/replace_derive_with_manual_impl.rs` again, but I'm planning a follow-up PR to extract these to `utils/` so we can share them between assists - and maybe even add another assist just for the purpose of testing these impls (e.g. `generate_default_trait_body`). The step after _that_ is likely to fill out the remaining traits, so we can make it so whenever RA auto-completes a trait which also can be derived, we provide a default function body. Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
9830: Enable more assists to generate default trait body impls r=Veykril a=yoshuawuyts Enable more assists to benefit from trait body generation. Follow-up to #9825 and #9814. __edit:__ I'd like to move the existing tests to this new file too, but I'll do that in a follow-up PR. Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
This patch makes it so when you convert
#[derive(Debug)]
to a manual impl, a default body is provided that's equivalent to the original output of#[derive(Debug)]
. This should make it drastically easier to write customDebug
impls, especially when all you want to do is quickly omit a single field which is!Debug
.This is implemented for enums, record structs, tuple structs, empty structs - and it sets us up to implement variations on this in the future for other traits (like
PartialEq
andHash
).Thanks!
Codegen diff
This is the difference in codegen for record structs with this patch: