62 Commits

Author SHA1 Message Date
Ed Page
878caf7447 docs: Surround identifiers in backticks
This was mostly done by clippy via `clippy::doc_markdown`.
I then reviewed it to fix words that shouldn't have it or where `--fix`
put the backtick in the wrong location.
2024-11-15 09:33:23 -06:00
Ed Page
49d8696823 style: Workaround clippy 2024-11-08 13:58:51 -06:00
Alexander Saites
7d6889b5d9 replace special-case duplicate handling with error 2024-11-04 18:24:36 -07:00
bors
3dedb85a25 Auto merge of #14747 - saites:rustfix-transactional, r=weihanglo
Add transactional semantics to `rustfix`

### What does this PR try to resolve?

This PR adds transactional semantics to `rustfix::Data`, enabling `rustfix::CodeFix` to apply `Suggestion`s as atomic units and rollback partially-applied changes when they conflict with existing ones. The basic approach and goals are discussed [in a comment on issue 14699](https://github.com/rust-lang/cargo/issues/14699#issuecomment-2427501232). In that comment, I proposed a solution which extended the existing `State` enumeration, but described an alternative that simplifies the overall tracking of incoming changes; this PR implements the latter.

### How should we test and review this PR?

I've added an additional test and updated the existing ones. The tests in `parse_and_replace` already cover this case, particularly thanks to https://github.com/rust-lang/cargo/pull/14765 added by `@weihanglo.` It's still a good idea to experiment with `cargo clippy --fix` on repos that match the cases described in these open issues.

### Additional information

Fixes #14699
Fixes rust-lang/rust-clippy/issues/13549
2024-11-02 21:45:48 +00:00
Alexander Saites
f73b1d8c74 add transactional semantics to rustfix 2024-11-02 13:01:21 -07:00
Weihang Lo
8aec0a40f5
test(rustfix): switch to a simpler case for dedup-suggestions
This case also emits an insert-only suggestions (span start == end),
and doesn't rely on any lint behavior.

See also

* https://github.com/rust-lang/cargo/pull/13728
* https://github.com/rust-lang/cargo/issues/13027
2024-10-31 22:05:24 -04:00
Weihang Lo
c9102e54bb
refactor(rustfix): only compute snippets when needed 2024-10-20 20:42:22 -04:00
Weihang Lo
f483dc0b95
refactor(rustfix): simplify debug print for Span 2024-10-20 20:42:22 -04:00
Weihang Lo
6ac20fd1be
refactor(rustfix): remove unnecessary indentations 2024-10-20 20:42:22 -04:00
Weihang Lo
446e3f05ba
chore(rustfix): bump to 0.8.8 2024-10-20 20:42:22 -04:00
Ed Page
5c87c14f9a docs: Declare support level for each crate in our Charter / docs
This is to bring us into conformance with the [Rust crate ownership
policy](https://forge.rust-lang.org/policies/crate-ownership.html).

Items of note
- `cargo-credential-1password` is declared as Experimental as it is
  intended for the community but I was unsure if we wanted to commit to
  full support for it.  In my mind, the ideal thing to do would be to
  expatriate this to 1password.
- `home` is declared as Internal despite its wide use within the
  ecosystem.
- `cargo-credential` is declared as Intentional as its an API intended
  for the wider ecosystem and I didn't see a reason to declare it
  experimental.
- `cargo-platform`, `cargo-util-schemas`, and `crates-io` are declared
  as Intentional as they are both used internally and intended for
  others to use for logic that integrates with cargo/registries.
  I wondered about these being Experimental or Internal instead.
2024-09-26 12:43:09 -05:00
Ed Page
d199f2e97c chore: Bump versions 2024-09-26 12:43:09 -05:00
Mo
af04e54235
Apply suggestions from code review
Inline variables in `format!`

Co-authored-by: Weihang Lo <weihanglo@users.noreply.github.com>
2024-08-09 15:42:02 +02:00
mo8it
3ccb17c399 Use with_context with format! 2024-08-09 14:20:18 +02:00
Ed Page
fa5853a397 chore: Bump rustfix 2024-07-25 10:31:21 -05:00
Ed Page
2a104dcb31 chore: Move rustfix's similar dep to workspace 2024-07-25 10:30:40 -05:00
Ed Page
8debb544e4 chore: Update dependencies
I just published all of my packages using Cargo 1.80 and wanted to see
the effect of the enumerating targets during publish (#13849).
2024-07-25 10:04:10 -05:00
Alex Macleod
5a15397611 Add CodeFix::apply_solution and impl Clone 2024-06-19 19:06:36 +00:00
Weihang Lo
a47766149f
test(rustfix): bless multiple-solutions.nightly.rs 2024-05-09 09:30:25 -04:00
Weihang Lo
26bcf58bfe
test(rustfix): run some tests only on nightly 2024-05-09 09:30:25 -04:00
Weihang Lo
95edc06e5b
fix(rustfix): dont apply same suggestion twice
This assumes that if any of the machine applicable fixes in
a diagnostic suggestion is a duplicate, we should see the
entire suggestion as a duplicate.
2024-04-10 11:54:33 -04:00
Weihang Lo
5b05a3bb5a
test(rustfix): demonstrate duplicate suggestions 2024-04-10 11:53:37 -04:00
renovate[bot]
bfbdfa7a17 chore(deps): update compatible 2024-04-02 15:23:20 -05:00
Eric Huss
daa884169c Fix redundant imports. 2024-02-20 09:57:03 -08:00
Ed Page
c6c1df4758 chore: Make N-2 the default MSRV
We likely don't want to release these packages every 6 months just for
an MSRV bump.
By moving the MSRV out of the package, `cargo bump-check` will ignore
the MSRV bump.

Inspired by #13266
2024-01-18 15:30:41 -06:00
renovate[bot]
03beda3a6e chore(deps): update msrv 2024-01-08 22:17:07 +00:00
Eric Huss
e7eaa51909 cargo fix: Call rustc fewer times.
This changes `cargo fix` so that it keeps track of the output so that it
doesn't need to run the final "show the output" step.
2024-01-02 15:03:06 -08:00
renovate[bot]
4deb34bd0b
chore(deps): update compatible 2024-01-02 10:21:24 +00:00
Eric Huss
3d3e1b3668 Handle Windows newlines.
Suggestions that come from rustc that are multi-line only use LF line
endings. But if the file is checked out on windows with CRLF
line-endings, then you end up with a mix of line endings that don't
match the "fixed.rs" file.

Tracking this at https://github.com/rust-lang/rust/issues/119482.
2023-12-31 16:20:41 -08:00
Eric Huss
a21997f0cc rustfix: Support inserting new lines.
If rustfix received a suggestion which inserts new lines without
replacing existing lines, it would ignore the suggestion. This is
because `parse_snippet` would immediately return if the `lines` to
replace was empty.

The solution here is to just drop the code which messes with the
original text line. `cargo fix` (and compiletest) currently do not use
this. This was originally added back in the days when rustfix supported
an interactive UI which showed color highlighting of what it looks like
with the replacement. My feeling is that when we add something like this
back in, I would prefer to instead use a real diff library and display
instead of trying to do various text manipulation for display. This
particular code has generally been buggy, and has been a problem several
times.

The included test fails without this fix because the changes do not
apply, and the code cannot compile.
2023-12-31 10:18:22 -08:00
Eric Huss
029fe2bafc Add a primitive way to add new tests to parse_and_replace.
This adds an environment variable to make it easier to add new tests.
2023-12-31 09:58:37 -08:00
Eric Huss
c54fa88ea4 Cleanup rustfix parse_and_replace test.
This is just some minor code cleanup for the parse_and_replace test,
there should not be any functional differences.
2023-12-31 09:56:20 -08:00
Weihang Lo
ad2c45bde9
refactor: clean up package metadata
Like PR 12352 but for homepage and repository

Versions for

* `cargo-credential-1password`
* `cargo-util-schemas`
* `home`

are bumped along with the change.
2023-12-18 16:09:03 -05:00
bors
9c1316ff3f Auto merge of #13181 - hi-rustin:rustin-patch-rename-files, r=weihanglo
chore(rustfix): rename Readme.md to README.md
2023-12-18 15:04:01 +00:00
hi-rustin
0b6c229e9d chore(rustfix): remove useless clippy rules
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-18 20:17:05 +08:00
hi-rustin
b8e2f75881 chore(rustfix): fix a typo
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-18 20:10:28 +08:00
hi-rustin
efdaf4bbc6 chore(rustfix): rename Changelog.md to CHANGELOG.md
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-18 20:05:52 +08:00
hi-rustin
88993a3bbe chore(rustfix): rename Readme.md to README.md
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-18 20:04:50 +08:00
renovate[bot]
ab6adab01b
chore(deps): update compatible 2023-12-01 17:33:18 +00:00
Weihang Lo
21274da65b
chore: bump rustfix to 0.7.0 2023-11-27 10:50:10 -05:00
Weihang Lo
ed347ce4dc
refactor: use custom error instead of anyhow 2023-11-27 10:50:10 -05:00
bors
3920bd5ea5 Auto merge of #13047 - tompscanlan:rustfix-ignored-tests, r=weihanglo
review and remove ignored tests in rustfix

### What does this PR try to resolve?
review ignored tests in rustfix crate per #13034.

### How should we test and review this PR?
CI testing

### Additional information

* Removed unproductive test in `parse_and_replace`
* un-ignore proptests, and reduce runtime from ~2s to ~<.25s
2023-11-26 17:14:11 +00:00
Tom Scanlan
b179cd175a
review and remove ignored tests in rustfix
* reduce time in proptest
* delete edition dir
* remove refs to fixmode::EDITION
2023-11-26 09:29:18 -05:00
bors
35ed69cb1b Auto merge of #13048 - weihanglo:rustfix-doc, r=epage
docs: add doc comments for rustfix
2023-11-25 23:45:45 +00:00
Weihang Lo
358b7ae76d
docs(rustfix): add more doc comments 2023-11-25 17:48:21 -05:00
Weihang Lo
27b7c6c203
docs(rustfix): comments for diagnostic JSON output
Most doc comments are copied from rust-lang/rust repo.

The doc for each item is hand-written as there is no comment in the
original place.
2023-11-25 13:09:39 -05:00
Tom Scanlan
e9e22e5c2f try running on windows 2023-11-23 18:34:56 -05:00
Eric Huss
47c7ff0f96 Deduplicate the similar dependency. 2023-11-21 10:18:15 -08:00
Eric Huss
70f56e9004 Add a general introduction to the rustfix library docs. 2023-11-21 10:10:22 -08:00
Eric Huss
f99a494c31 Remove copyright headers in tests.
These were all removed a while ago in https://github.com/rust-lang/rust/pull/57108
2023-11-19 08:20:21 -08:00