-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Provide rustfix to upgrade code to Rust 2018 automatically #49247
Comments
State of rustfix as of 2018-03-21The rustfix available in killercup/rustfix is pretty bare-bones: It currently is a simple interactive CLI tool that executes cargo (or clippy) and presents the user a choice of "which suggestion to apply"/"skip" for each compiler diagnostic message that include one or more suggestions. Its test suite works well and exercises some suggestions from rustc as well as clippy. The library itself has some known shortcomings that some of clippy's suggestions show. E.g. problems with applying multiple suggestions changes per suggestions multiple times per file confuses its simplistic "replace line/column ranges" approach. I propose to only focus on the lints related to the 2018 edition and their suggestions for now (which seem to live in the epoch_2018 for the most part -- cf. #48796). The rustfix library can probably reuse parts of the compiler internals to use the canonical representation of the messages instead of custom structs to deserialize them, and the CLI tool should be rewritten to be non-interactive for now. |
My initial suggestion for the user experience of
|
Next stepsI'll meet with @Manishearth and @oli-obk at the All Hands next week to discuss this, and try to get implementation going. One explicit goal will be to create mentor-able issues. |
BTW, should we nab the |
@nikomatsakis good idea! Let me write a crate that does this but… as a crate :) Update: This should do for now |
@killercup I'd be happy to help with this once you get some issues up after next weeks allhands. |
@mgattozzi Great! This will be a big help, rustfix is one of the items that needs a bunch of work but everyone is too busy to work on it. For now, looking into https://github.com/killercup/rustfix/issues/57 may be helpful. |
Overall I think there's huge potential for fixture tests in rustc, both as a way to test suggestions and to test rustfix. The way I envision it is that if any compile-fail or UI test foo.rs is accompanied by a foo.rs.fixed file, it's an indication that we must run rustfix on it, and the fixed source should match the .fixed file. Additionally, the fixed file should not emit any of the warning entries that had suggestions. Once the framework for this exists I can see lots of easy bugs popping out. |
Tracked in #45516 |
@killercup some thoughts I might have on the initial suggestion. It may actually be pretty cool if we basically just say "run This I think would lend itself great to things like:
I think punting edition flags and such to Cargo and/or the crate may make
Internally this could all be architected as an elaborate wrapper around (the ui here is likely to be fixed over time) I think something along these lines though is likely to be the quickest and most robust path forward, but I'm curious what you think as well! |
comment moved to rust-lang/rustfix#64 (comment) |
A lot happend last week thanks to @alexcrichton doing a ton of stuff! I think we have most of the critical features implemented in the CLI tool, and I've opened rust-lang/rustfix#95 which adds the "edition mode" (currently depends on edition lints becoming available). @mgattozzi, still want to and have time to help out? We have opened some good issues to polish the tooling, and have also left a good number of TODO comments in the code waiting to be picked up :) |
I believe this is largely done so I'm going to close this |
Rustfix is a CLI tool that parses the compiler's suggestions and applies them to the source files. It is the official tool to migrate from Rust 2015 to 2018.
This issue is to track the development of the CLI tool. Other ways to interact with the compiler suggestions include "reading them and changing code manually" as well as "using RLS and clicking on lightbulb icons in VSCode".
What needs to be done
cargo fix
command rustfix#66The text was updated successfully, but these errors were encountered: