15029 Commits

Author SHA1 Message Date
Weihang Lo
463622ad81
lint: fix errors for self-named module files 2023-09-14 13:43:48 +08:00
Weihang Lo
aef3bd22d3
lint: fix errors for rust 2018 idioms 2023-09-14 13:43:48 +08:00
Weihang Lo
85a3e9ace0
lint: move module-level doc comment to top 2023-09-14 13:43:47 +08:00
Weihang Lo
437942ee7e
lint: use eprintln for human-facing outputs 2023-09-14 13:43:47 +08:00
Weihang Lo
f9d82a1703
lint: remove unused dbg! 2023-09-14 13:43:47 +08:00
Weihang Lo
4cc9208b25
lint: follow convention no capitcal letter in first word 2023-09-14 13:43:47 +08:00
bors
80932be2e6 Auto merge of #12667 - Eh2406:clippy, r=weihanglo
Clippy

### What does this PR try to resolve?

A few more small anti-patterns from our code base. Each in their own commit, found by turning on a clippy warning and manually reviewing the changes. Most of the changes are from switching to `let-else`.

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

Internal refactoring and tests still pass.

### Additional information

I know we don't like "fix clippy" PR's. Sorry.

On the other hand having reviewed for these lints, I wouldn't mind turning them to warn. 🤷
2023-09-14 04:47:59 +00:00
bors
8d43632ab8 Auto merge of #12659 - Eh2406:Prerelease_candidates, r=epage
Prerelease candidates error message

### What does this PR try to resolve?

Error messages reporting on versions that do not match the request incorrectly ignore pre-release versions. This is because the version requirement `"*"` cannot match prerelease versions. #12315

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

Sorry for the large amount of white space changes, fmt got to fmt. 🤷‍♂️

The process was:
- Revise commit from #12316 (thanks to `@loloicci)` that change the requirement from `"*"` to `Any`
- Move the handling of our special "did you mean to specify a pre-release" code and update tests
- some small re-factoring

### Additional information

The old "did you mean to specify a pre-release" #7191 check only occurred when version requirement does not match any versions and you depended on a package that did not have any non-prerelease versions. Making it rarely useful.
The new one will appear any time your version requirement does not match any versions and the package does have pre-release versions. Which may be too common.
I'm open to suggestions for better heuristic.

It's also not clear that the new message make sense in the case of patched versions.
2023-09-14 01:40:33 +00:00
Jacob Finkelman
afe5333d86 Remove most clone where clippy::clone_on_copy 2023-09-13 20:41:45 +00:00
Jacob Finkelman
97bf02bef3 Use Rc insted of Arc when clippy::arc_with_non_send_sync 2023-09-13 20:24:49 +00:00
Jacob Finkelman
0a6f67109c remove as_ref where clippy::useless_asref 2023-09-13 20:19:57 +00:00
Jacob Finkelman
0ed01489d8 remove ref where needless_borrowed_reference 2023-09-13 20:14:06 +00:00
Jacob Finkelman
84456a0a7e use copied where clippy::map_clone 2023-09-13 20:00:37 +00:00
Jacob Finkelman
4b84887848 use let else where clippy::manual_let_else 2023-09-13 19:54:23 +00:00
bors
bc26ac0a1a Auto merge of #12666 - hi-rustin:rustin-patch-typos, r=epage
Fix typos: `informations` -> `information`

We do not use information in the plural form.
2023-09-13 14:19:44 +00:00
hi-rustin
fabe8a54c5 Fix typos: informations -> information 2023-09-13 22:04:43 +08:00
bors
8c3d4f6f80 Auto merge of #12665 - weihanglo:update-globset, r=ehuss
chore: update globset to 0.4.13
2023-09-13 13:32:26 +00:00
Weihang Lo
8a404ea711
chore: update globset to 0.4.13 2023-09-13 16:16:09 +08:00
bors
00bf8b0251 Auto merge of #12655 - epage:style, r=weihanglo
refactor: Consolidate clap/shell styles

### What does this PR try to resolve?

This is a follow up to #12578 to reduce duplication of terminal styling.

This still leaves styling in `color_print::cstr!`.

This is also prep for copy/pasting into `clap-cargo` for others to use.  Another step might be to extract `cargo::util::style` into its own crate.

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

We have no styling tests so this can only be verified by inspection or running the commands

### Additional information

I chose `anstyle` for expressing these as its an API designed specifically for stable style definitions to put in public APIs.
2023-09-13 02:42:24 +00:00
Jacob Finkelman
50f1455a64 Small nits 2023-09-12 16:12:14 +00:00
Jacob Finkelman
dcde7eb316 move pre-release specific error message 2023-09-12 16:06:29 +00:00
loloicci
7880215265 fix error message trying patch non-existing package with prerelease version 2023-09-12 15:57:29 +00:00
loloicci
c29c25be2e test error message trying patch non-existing package with prerelease version 2023-09-12 15:57:22 +00:00
bors
7541cc7afd Auto merge of #12657 - Eh2406:fixme, r=epage
libgit2 fixed upstream

### What does this PR try to resolve?

This "FIXME" points to https://github.com/libgit2/libgit2/issues/2514 witch has bean fixed for... 8 years. So maybe it is no longer needed.

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

By adding panic messages I was able to demonstrate that there were tests hitting this code path. Then I removed the "FIXME" and had the test still pass.
2023-09-12 01:00:48 +00:00
Jacob Finkelman
205fd1a765 libgit2 fixed upstream 2023-09-11 19:25:45 +00:00
bors
bef47cbc87 Auto merge of #12643 - Eh2406:IndexSummaryEnum, r=epage
Index summary enum

### What does this PR try to resolve?

This is a tiny incremental part of allowing registries to return richer information about summaries that are not available for resolution. Eventually this should lead to better error messages, but for now it's just an internal re-factor. Discussion of the overall approach is at https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/better.20error.20messages.20for.20filtered.20versions.2E

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

Internal re-factor and tests still pass.
2023-09-11 17:22:48 +00:00
Jacob Finkelman
5c8cf8dc16 Small clarifications 2023-09-11 16:29:04 +00:00
Jacob Finkelman
7f6bef522e handle offline one layer higher 2023-09-11 16:19:15 +00:00
Jacob Finkelman
231e4f315b Even fewer temporary needless strings 2023-09-11 16:19:15 +00:00
Jacob Finkelman
366e871778 use the hash method not a copy paste of its code 2023-09-11 16:19:15 +00:00
Jacob Finkelman
423bf0588d Make IndexSummary an enum 2023-09-11 16:19:15 +00:00
Ed Page
385dfb6298 test(registry): Show current too-new schema error
This reproduces the problem in #10623.
2023-09-11 16:19:15 +00:00
Ed Page
293b71a961 test(registry): Provide more room from tests conflicting with reality 2023-09-11 16:19:15 +00:00
Ed Page
51e1058379 refactor(shell): Centralize Shell styling
This is a very rough pass at naming the styles with a focus on getting
something in and keeping the colors the same.
2023-09-11 09:51:09 -05:00
Ed Page
2d5354adc9 refactor(cli): Extract CLI style definitions 2023-09-11 09:32:13 -05:00
bors
c2d26f32d3 Auto merge of #12578 - epage:help, r=weihanglo
feat(help): Add styling to help output

### What does this PR try to resolve?

Try to make `--help` output easier to parse by using terminal styling

Screenshots:

![Screenshot from 2023-09-06 09-57-11](https://github.com/rust-lang/cargo/assets/60961/61069af4-ef05-40ad-9240-fedea44d4c71)

![Screenshot from 2023-09-06 09-57-21](https://github.com/rust-lang/cargo/assets/60961/d2e69024-42aa-47c0-ad0f-24e43551b8db)

![Screenshot from 2023-09-06 09-57-36](https://github.com/rust-lang/cargo/assets/60961/e3d895e2-745f-48c6-9e84-d6fb67198d6d)

*(`nargo` is my shell script wrapping `cargo run --manifest-path cargo/Cargo.toml`)*

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

At this time, the only styling snapshotting library I know of is a pain to use, so testing this requires manually running the commands which I did.  Screenshots are included for easier evaluation of the general idea.

Snapshotting of the plain text output ensures we don't have accidental formatting regressions from this change since the formatting isn't as obvious from looking at the code.

### Additional information

Traditionally, cargo has disabled clap's styled output.  My assumed
reason is that cargo mixes custom help output with auto-generated and
you couldn't previously make it all styled.
Clap 4.2 allowed users to pass in strings styled using ANSI escape
codes, allowing us to pass in styled text that matches clap, unblocking this.  In clap
4.4.1, clap gained the ability for the user to override the style.

In this PR, I decided to use the new 4.4.1 feature to style clap's
output to match the rest of cargo's output.  Alternatively, we could use
a more subdue style that clap uses by default.

I used the `color-print` crate to allow something almost html-like for styling `&static str`.  Alternatively, we could directly embed the ANSI escape codes harder to get write, harder to inspect), or we could do the styling at runtime and enable the `string` feature in clap.

I decided to *not* style `Arg::help` messages because
- It might be distracting to have the descriptions lit up like a
  christmas tree
- It is a lot more work

The one exception I made was for `--list` since it is for a
psuedo-command (`...`) and I wanted to intentionally draw attention to
it.

#12593 made styling of `cargo -h` cleaner imo.
#12592 and #12594 were improvements I noticed while doing this.
2023-09-11 06:25:47 +00:00
bors
2fc85d15a5 Auto merge of #12648 - epage:lint, r=weihanglo
feat: Stabilize lints

Fixes #12115
2023-09-09 01:49:46 +00:00
bors
8bd32310f5 Auto merge of #12631 - Eh2406:strip_prefix, r=epage
Ues strip_prefix for cleaner code

### What does this PR try to resolve?

In https://github.com/rust-lang/cargo/pull/12629#pullrequestreview-1614154046 Ed pointed out how much cleaner the code can be using `strip_prefix`, so I found a bunch more places where we should be using it.

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

Internal refactor and test still pass.
2023-09-08 20:05:02 +00:00
Jacob Finkelman
2b2838302f bump cargo-platform 2023-09-08 19:16:42 +00:00
Jacob Finkelman
eb188831da
add a missing is:
Co-authored-by: Eric Huss <eric@huss.org>
2023-09-08 15:14:10 -04:00
Ed Page
e539380512 feat: Stabilize lints
Fixes #12115
2023-09-08 10:44:00 -05:00
bors
45181313df Auto merge of #12644 - arlosi:cred-no-env, r=weihanglo
fix: don't print _TOKEN suggestion when not applicable

### What does this PR try to resolve?
When a registry token cannot be found, or a token is invalid, cargo displays an error recommending either `cargo login` or the appropriate environment variable.

For example:
```
error: no token found for `alternative`, please run `cargo login --registry alternative`
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
```

With `-Z credential-process`, if `cargo:token` is not in `registry.global-credential-providers` or `registries.<NAME>.credential-provider` the suggested environment variable will not work.

Fixes #12642 by not including the `_TOKEN` environment variable if `cargo:token` is not enabled as a credential provider.

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

Two tests `not_found` and `all_not_found` cover this case by having a registry-specific and global credential providers respectively that return `not-found`.

Other tests that emit this error are not affected, since they still have the `cargo:token` provider available.
2023-09-08 06:24:42 +00:00
Arlo Siemsen
803fd6909c fix: don't print _TOKEN suggestion when not applicable
Cargo should not suggest the _TOKEN environment variable
when the cargo:token provider isn't available
2023-09-07 21:14:50 -05:00
bors
5c77b5da08 Auto merge of #12641 - arlosi:bump-1password, r=epage
Bump cargo-credential-1password to v0.4.0

`cargo-credential` updated to version `0.4.0` in #12622. This updates `cargo-credential-1password` to `0.4.0` as well so it can be published to crates.io.
2023-09-07 21:02:26 +00:00
Arlo Siemsen
f020b00bdd Bump cargo-credential-1password to v0.4.0 2023-09-07 13:52:15 -05:00
Jacob Finkelman
44666f7377 Ues strip_prefix for cleaner code 2023-09-07 17:57:28 +00:00
bors
24840d9b6d Auto merge of #12527 - weihanglo:refactor-source-trait, r=epage
refactor: put `Source` trait under `cargo::sources`
2023-09-07 14:44:30 +00:00
Weihang Lo
e575448574
refactor: flatten module path of SourceId 2023-09-07 21:06:35 +08:00
Weihang Lo
b6c4e47cc0
refactor: put Source trait under cargo::sources 2023-09-07 21:06:34 +08:00
bors
8230b46402 Auto merge of #12637 - ehuss:clean-doc-p, r=weihanglo
Error out if `cargo clean --doc` is mixed with `-p`.

This changes `cargo clean --doc -p foo` to generate an error instead of ignoring the `-p` flag. There is still an outstanding issue https://github.com/rust-lang/cargo/issues/8790 tracking this. It *should* support `-p`, but until it is supported, I think cargo should tell you that the flag is ignored. This is also in preparation for some code changes in #12634 which needs to handle any combination of various different clean flags.
2023-09-07 09:43:39 +00:00