Skip to content
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

Import cargo fix directly in to Cargo #5723

Merged
merged 1 commit into from
Jul 17, 2018
Merged

Conversation

alexcrichton
Copy link
Member

This commit imports the cargo fix subcommand in rust-lang-nursery/rustfix
directly into Cargo as a subcommand. This should allow us to ease our
distribution story of cargo fix as we prepare for the upcoming 2018 edition
release.

It's been attempted here to make the code as idiomatic as possible for Cargo's
own codebase. Additionally all tests from cargo-fix were imported into Cargo's
test suite as well. After this lands and is published in nightly the cargo-fix
command in rust-lang-nursery/rustfix will likely be removed.

cc rust-lang/rust#52272

@rust-highfive
Copy link

r? @matklad

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

cc @killercup

@killercup
Copy link
Member

killercup commented Jul 14, 2018

Cool! Thanks for doing this, @alexcrichton!

I probably would've tried to carry over the commit messages using git-subtree but other than that it looks like you managed to make this fit quite well into cargo. Not sure how idiomatic this is in cargo, but maybe you can also split up the tests further? 1k lines is quite a lot to scroll through without grouping :)

(Also: Remind me to add support for message-format=json to cargo-fix.)

CI failures:

  • Mac/Windows: Git config?

    'repo.signature() failed with config value 'user.name' was not found; class=Config (7); code=NotFound (-3)'

  • Windows: Issues with placeholders and path separators in tests:
    1 - |[FIXING] bar/src/lib.rs (1 fix)|
      + |      Fixing bar\src\lib.rs (1 fix)|
    

@alexcrichton
Copy link
Member Author

Ah we've got pretty long tests in Cargo unfortunately, most of it's due to unnecessarily verbose test cases. We should definitely fix that at some point!

CI should be green now too!

@alexcrichton
Copy link
Member Author

r? @ehuss

@bors: delegate=ehuss

@bors
Copy link
Collaborator

bors commented Jul 16, 2018

✌️ @ehuss can now approve this pull request

Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

// not the best heuristic but matches what Cargo does today at least.
let mut fixes = FixedCrate::default();
if let Some(path) = filename {
if !Path::new(&path).is_absolute() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also sweeps up path dependencies. That might be surprising.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct! That's actually intentional though in the sense that if it's a path dependency you're probably working on it so we go ahead and fix it.

// Instead, punt upwards which will reexec rustc over the original code,
// displaying pretty versions of the diagnostics we just read out.
//
// TODO: this should be configurable by the CLI to sometimes proceed to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment no longer correct? This is the --broken-code option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, indeed!

@@ -120,9 +119,9 @@ impl ProjectBuilder {
}

pub fn new(name: &str, root: PathBuf) -> ProjectBuilder {
drop(name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just remove the name parameter if it's not used? It doesn't look like it affects too many call sites.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing!

@ehuss
Copy link
Contributor

ehuss commented Jul 16, 2018

cargo fix does not play well with running cargo check. For example, if your editor automatically runs cargo check, then cargo fix will do nothing because it thinks everything is "fresh". I'm inclined to just file an issue for this and see if it can be fixed after this merges?

This commit imports the `cargo fix` subcommand in rust-lang-nursery/rustfix
directly into Cargo as a subcommand. This should allow us to ease our
distribution story of `cargo fix` as we prepare for the upcoming 2018 edition
release.

It's been attempted here to make the code as idiomatic as possible for Cargo's
own codebase. Additionally all tests from cargo-fix were imported into Cargo's
test suite as well. After this lands and is published in nightly the `cargo-fix`
command in rust-lang-nursery/rustfix will likely be removed.

cc rust-lang/rust#52272
@alexcrichton
Copy link
Member Author

I'm inclined to just file an issue for this and see if it can be fixed after this merges?

Ah yeah there's a few issues on rust-lang-nursery/rustfix like this one which we should transfer over once merged

@ehuss
Copy link
Contributor

ehuss commented Jul 17, 2018

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 17, 2018

📌 Commit b02ba37 has been approved by ehuss

@bors
Copy link
Collaborator

bors commented Jul 17, 2018

⌛ Testing commit b02ba37 with merge 506eea7...

bors added a commit that referenced this pull request Jul 17, 2018
Import `cargo fix` directly in to Cargo

This commit imports the `cargo fix` subcommand in rust-lang-nursery/rustfix
directly into Cargo as a subcommand. This should allow us to ease our
distribution story of `cargo fix` as we prepare for the upcoming 2018 edition
release.

It's been attempted here to make the code as idiomatic as possible for Cargo's
own codebase. Additionally all tests from cargo-fix were imported into Cargo's
test suite as well. After this lands and is published in nightly the `cargo-fix`
command in rust-lang-nursery/rustfix will likely be removed.

cc rust-lang/rust#52272
@bors
Copy link
Collaborator

bors commented Jul 17, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: ehuss
Pushing 506eea7 to master...

@bors bors merged commit b02ba37 into rust-lang:master Jul 17, 2018
@killercup
Copy link
Member

🎉

@alexcrichton alexcrichton deleted the cargo-fix branch July 17, 2018 17:00
alexcrichton added a commit to alexcrichton/rustfix that referenced this pull request Jul 17, 2018
This has now moved upstream into Cargo itself at rust-lang/cargo#5723
@dwijnand
Copy link
Member

Ah we've got pretty long tests in Cargo unfortunately, most of it's due to unnecessarily verbose test cases. We should definitely fix that at some point!

That sounds like a nice E-easy piece of grunt work. If you were to flesh out your thoughts on how to do that I might be able to help. 😄

@alexcrichton
Copy link
Member Author

@dwijnand an excellent point! I've filled out the A-testing-cargo-itself tag on our issue tracker a bit, and anything tagged with E-help-wanted would be most appreciated to have some help to tackle!

@MoSal
Copy link
Contributor

MoSal commented Jul 20, 2018

I was wondering why a rustfix component wasn't added to rustup with clippy before finding this PR.

I think an announcement about this change should be made when the next nightly becomes available.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Sep 14, 2018
Version 1.29.0 (2018-09-13)
==========================

Compiler
--------
- [Bumped minimum LLVM version to 5.0.][51899]
- [Added `powerpc64le-unknown-linux-musl` target.][51619]
- [Added `aarch64-unknown-hermit` and `x86_64-unknown-hermit` targets.][52861]

Libraries
---------
- [`Once::call_once` now no longer requires `Once` to be `'static`.][52239]
- [`BuildHasherDefault` now implements `PartialEq` and `Eq`.][52402]
- [`Box<CStr>`, `Box<OsStr>`, and `Box<Path>` now implement `Clone`.][51912]
- [Implemented `PartialEq<&str>` for `OsString` and `PartialEq<OsString>`
  for `&str`.][51178]
- [`Cell<T>` now allows `T` to be unsized.][50494]
- [`SocketAddr` is now stable on Redox.][52656]

Stabilized APIs
---------------
- [`Arc::downcast`]
- [`Iterator::flatten`]
- [`Rc::downcast`]

Cargo
-----
- [Cargo can silently fix some bad lockfiles ][cargo/5831] You can use
  `--locked` to disable this behaviour.
- [`cargo-install` will now allow you to cross compile an install
  using `--target`][cargo/5614]
- [Added the `cargo-fix` subcommand to automatically move project code from
  2015 edition to 2018.][cargo/5723]

Misc
----
- [`rustdoc` now has the `--cap-lints` option which demotes all lints above
  the specified level to that level.][52354] For example `--cap-lints warn`
  will demote `deny` and `forbid` lints to `warn`.
- [`rustc` and `rustdoc` will now have the exit code of `1` if compilation
  fails, and `101` if there is a panic.][52197]
- [A preview of clippy has been made available through rustup.][51122]
  You can install the preview with `rustup component add clippy-preview`

Compatibility Notes
-------------------
- [`str::{slice_unchecked, slice_unchecked_mut}` are now deprecated.][51807]
  Use `str::get_unchecked(begin..end)` instead.
- [`std::env::home_dir` is now deprecated for its unintuitive behaviour.][51656]
  Consider using the `home_dir` function from
  https://crates.io/crates/dirs instead.
- [`rustc` will no longer silently ignore invalid data in target spec.][52330]

[52861]: rust-lang/rust#52861
[52656]: rust-lang/rust#52656
[52239]: rust-lang/rust#52239
[52330]: rust-lang/rust#52330
[52354]: rust-lang/rust#52354
[52402]: rust-lang/rust#52402
[52103]: rust-lang/rust#52103
[52197]: rust-lang/rust#52197
[51807]: rust-lang/rust#51807
[51899]: rust-lang/rust#51899
[51912]: rust-lang/rust#51912
[51511]: rust-lang/rust#51511
[51619]: rust-lang/rust#51619
[51656]: rust-lang/rust#51656
[51178]: rust-lang/rust#51178
[51122]: rust-lang/rust#51122
[50494]: rust-lang/rust#50494
[cargo/5614]: rust-lang/cargo#5614
[cargo/5723]: rust-lang/cargo#5723
[cargo/5831]: rust-lang/cargo#5831
[`Arc::downcast`]: https://doc.rust-lang.org/std/sync/struct.Arc.html#method.downcast
[`Iterator::flatten`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.flatten
[`Rc::downcast`]: https://doc.rust-lang.org/std/rc/struct.Rc.html#method.downcast
@ehuss ehuss added this to the 1.29.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants