cargo-edit icon indicating copy to clipboard operation
cargo-edit copied to clipboard

Idea: run migration scripts on cargo upgrade

Open ordian opened this issue 5 years ago • 3 comments

This may be out of scope of cargo-edit, but my writing this down not to forget it. The idea is that when library authors make a breaking change, they also write a script e.g. in ra_ssr that does the migration for your code wherever possible.

Then cargo-upgrade would pull these migration scripts (assuming some convention for a standard location) and run them. Imagine a world where even a major upgrade e.g. from tokio 0.2 to tokio 0.3 can be done with a single cargo upgrade :)

ordian avatar Jul 07 '20 08:07 ordian

This shouldn't be a separate script, just an attribute on a function. See prior art:

https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-deprecated/replace-with.html

https://hackernoon.com/how-kotlins-deprecated-relieves-pain-of-colossal-refactoring-8577545aaed

matklad avatar Jul 08 '20 21:07 matklad

@matklad thanks for the reply. If I understand correctly, an attribute is only capable of replacing invocation of one function with a code snippet, whereas scripts are more flexible and allow you to specify e.g. if you pass this parameter then use that instead or if you're calling this function inside of that function, here is a migration script for you. But to be fair, this is all speculative ATM.

ordian avatar Jul 09 '20 08:07 ordian

Yup, attrs are indeed restricted, but my gut feeling is that they should cover 80 of automatable migrations.

matklad avatar Jul 09 '20 08:07 matklad