-
Notifications
You must be signed in to change notification settings - Fork 1
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
Automatic migration of breaking library updates #30
Comments
Thank you very much for the user story. Including suggestions with an applicability is definitely part of my goals. Using it to migrate libraries was something I haven't thought about so far. It makes a lot of sense to use it for that as well, like rustc already does for editions. Awesome input! I'm currently actively working on this project, but it'll still take time until this can be accomplished and then tested on a use case like this. Best of luck and let's hope that we can make this automatic migration happen some day! |
Looking at Its edition migration works the same way I imagined dependency migration to work: run Perhaps |
rustfix is build on top of rustc's error reporting. The current architecture is intended to support different drivers, like rustc and maybe/hopefully rust-analyzer one day. If we report the lints over rustc, rustfix could handle them immediately. Clippy does the same. The dream is to later run |
After seeing how easy it is to run a rustc wrapper using rustc_driver, I spent the day coding up a custom binary that migrates serenity closure-style builders: https://github.com/kangalioo/serenity_migration (not 100% working yet) I learned many complexities and idiosyncrasies of rustc's private API. In the long term, rust-linting should probably evolve so that serenity_migration could have been written using rust-linting, which should make the code much more straightforward. |
That's a good solution for now, and welcome to rustc's internals. They're not always the intuitive. Just a small warning, since I'm currently working on that part of marker. Rustc's api is instable, and your crate is bound to a specific nightly. |
I did something similar for SNAFU where I ran the compiler as a whole (via |
Lint explanation
In poise, we recently pushed a release that renames a few common functions and struct fields. Applying those changes is an annoying and mechanical task for users that could have been automated well:
.user_data_setup()
->.setup()
api_function(ctx.discord())
->api_function(ctx)
other_function(ctx.discord())
->other_function(ctx.serenity_context())
listener: |event| {}
->event_handler: |event| {}
In serenity, there's a huge breaking release (0.12) coming up that reworks all instances of the builder pattern from this (example):
to
We're all kinda afraid of pushing out this release because of how much churn it will cause. It would be great to have a way of automatically migrating users' code.
Example code
See above
Notes
This issue is technically not about linting but about code rewriting. However, Rust's code rewriting infrastructure,
cargo fix
, is based on lints. Here's how I'd imagine serenity to use custom lints to aid in migration:Publish a
serenity-migration
crate which lints all instances of the builder pattern and suggests the rewritten form. The user would run these lints while still on the old serenity version 0.11 (otherwise, the code would fail to parse/type-check). Now the code has been rewritten for serenity 0.12. Finally, the user bumps the serenity crate version to 0.12.The text was updated successfully, but these errors were encountered: