Commit graph

5362 commits

Author SHA1 Message Date
bors 40f1f67ea6 Auto merge of #12590 - arlosi:cred-unsupported-error, r=epage
fix: add error for unsupported credential provider version

Cargo currently ignores the version in the `CredentialHello` message, and proceeds to use version `1` regardless of what the credential provider claims it can support.

This change does the following:
* Adds a new error if Cargo doesn't support any of the supported protocol versions offered by the provider.
* Kills the credential provider subprocess if it fails. This prevents it from hanging or printing spurious errors such as "broken pipe" when it's attempting to read the next JSON message.
* Adds a new test for an unsupported credential provider protocol.
2023-08-30 03:35:48 +00:00
Arlo Siemsen 39db61e26e fix: add error for unsupported credential provider version 2023-08-29 21:22:29 -05:00
Ed Page 58fb982f44 fix(help): Explain --explain
In working on #12578, I'm focusing on each help string to decide how it
should be handled and I noticed this.  It feels weird to explain
something in terms of another command's CLI, so I took `rustc --help`s
message and added `rustc` to clarify it.

Looking back, the flag was added in #2551 with the message we have
today.  Nothing seems to really be said about it.

In reflecting on this, I'm not 100% convinced and am open to other
opinions.
2023-08-29 15:21:02 -05:00
bors a873df5c39 Auto merge of #12594 - epage:help-redundant, r=weihanglo
fix(help): Remove redundant information from new/init

Auditing all of the `--help` in prep for #12578 and noticed that we list the VCS information twice, once on our end and once by clap.
2023-08-29 22:36:21 +00:00
Ed Page ad0a11349e fix(help): Remove redundant information from new/init
Auditing all of the `--help` in prep for #12578 and noticed that we list
the VCS information twice, once on our end and once by clap.
2023-08-29 16:28:49 -05:00
bors 96fe1c9e1a Auto merge of #12584 - epage:lints, r=arlosi
fix(lints): Fail when overriding inherited lints

### What does this PR try to resolve?

Overriding of inherited lints was reserved for the future but as pointed out in https://github.com/rust-lang/cargo/issues/12115#issuecomment-1695293006, we aren't failing on these when we should but silently ignoring the overrides.

This turns it into a hard error.

In fixing this, I had to add a `#[serde(expecting)]` attribute to maintain behavior on an error case (otherwise it would say "expecting struct WorkspaceLints").  Since this drew the error message to my attention, I also tweaked it to make it more specific.

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

Commits are broken down by the relevant tests and fixes to make the intended behavior changes obvious.
2023-08-29 20:10:34 +00:00
bors 333ca23bf8 Auto merge of #12575 - cardoso:missing_git_flag, r=arlosi
cargo install: suggest --git when package name is url

### What does this PR try to resolve?

Improve the error message when specifying a URL for a package name in `cargo install`.

Fixes #10485

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

Just cargo test and trying a common case like `cargo install https://github.com/rust-lang/cargo`

### Additional information

I found this PR after finishing this one: #10522
But it seems have a larger scope to refactor some of the related code.

Perhaps this one would be easier to merge and that one could focus on the refactor, otherwise sorry for the noise and feel free to close.
2023-08-29 19:03:00 +00:00
bors 0b29588c61 Auto merge of #12588 - arlosi:logout-is-stable, r=weihanglo
chore: remove unstable-options for logout

`cargo logout` is stable, and doesn't need `masquerade_as_nightly_cargo`
2023-08-29 18:17:10 +00:00
Arlo Siemsen bd4444fbdd chore: remove unstable-options for logout 2023-08-29 11:34:29 -05:00
Arlo Siemsen 0a5050c0d0 Improve logout message for asymmetric tokens 2023-08-29 11:28:02 -05:00
Ed Page 66f0b13d47 fix(update): Remove references to -p in help
Missed these in #12545
2023-08-29 08:49:14 -05:00
Ed Page 6568e2c466 fix(lints): Improve error message on bad data 2023-08-28 20:55:29 -05:00
Ed Page 1c578b1a99 fix(lints): Error when overriding workspace lints 2023-08-28 20:34:19 -05:00
Ed Page c63b51deeb test(lints): Show existing package/workspace mix behavior 2023-08-28 13:59:40 -05:00
Matheus Cardoso ecf05e4ff1
cargo install: suggest --git when package name is url 2023-08-27 23:04:21 -03:00
Ethan Brierley 1f80ffabd1 Improve resolver version mismatch warning
fixes: #12557
2023-08-27 21:11:20 +01:00
David Tolnay ece5269e97
Stabilize --keep-going 2023-08-26 13:14:39 -07:00
bors f797978283 Auto merge of #12553 - epage:version, r=weihanglo
refactor: Pull out cargo-add MSRV code for reuse

### What does this PR try to resolve?

#12078 added MSRV code in `cargo add`. Our assumption when writing it is that we'd need to generalize the code before reusing it in other places, like `cargo install`.  This PR focused purely on that refactor because I'm hopeful it will be useful for other work I'm doing.  Despite not having a user for this yet, I think the `cargo install` case is inevitable and I feel this does a bit to clean up MSRV related code by using a more specific type everywhere.

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

Each commit gradually progresses things along
2023-08-25 14:56:24 +00:00
Deadbeef 43dccc7535 apply suggestions 2023-08-25 01:43:29 +00:00
Deadbeef b2b34e4ca2 update tests 2023-08-25 01:43:29 +00:00
Ed Page 1701b4e3d8 fix(manifest): Improve rust-version error messages
Since we have tests for a couple of cases, I figured we could
improve the error messages for them.
2023-08-24 20:29:14 -05:00
bors b2c162c067 Auto merge of #12556 - epage:serde, r=arlosi
fix(toml): Improve parse errors

### What does this PR try to resolve?

When we adopted `toml_edit`, we got TOML syntax errors that showed the context for where the error occurred.  However, the work was not done to extend this to semantic errors reported by serde.

This updates `Cargo.toml` and `Cargo.lock` code to provide that context on semantic errors.  `config.toml` is not done because the schema is decentralized.

In theory, this will also improve performance because we aren't having to allocate a lot of intermediate data to then throw away for every `Cargo.toml` we read.

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

Check by commit to see this change gradually.
- The `package.cargo-features` change was made to drop out dependence on `toml::Table` so we could do the direct deserialization
2023-08-24 23:01:52 +00:00
bors 3b20907926 Auto merge of #12551 - arlosi:asymmetric-token, r=Eh2406
Create dedicated unstable flag for asymmetric-token

Asymmetric tokens are gated by `-Zcredential-process`. Since we're considering stabilizing that soon, this moves asymmetric token support to have its own unstable flag.

It was previously gated by `-Zregistry-auth`, and some of the docs were not updated when it moved.

r? `@Eh2406`
2023-08-24 22:07:16 +00:00
Ed Page 53dcd2f454 fix(manifest): Provide more context on sematic errors 2023-08-24 16:27:53 -05:00
Ed Page 8927ea99d1 refactor(manifest): Process the package.cargo-features error in serde 2023-08-24 16:27:45 -05:00
Ed Page 511c17c961 fix(lock): Render source for serde errors
Before, we'd render the source for TOML syntax errors but not semantic errors.
Now we render for both.

Originally I changed `parse_document` to returned `T: DeserializeOwned`
but that adds an extra "could not parse TOML" which is both redundant
and makes it sound like its a syntax issue.
2023-08-24 16:27:37 -05:00
Ed Page 5cac7aa8c6 fix(toml): Remove redundant error messages 2023-08-24 16:19:48 -05:00
Ed Page 423a334520 refactor: Parse, don't validate, rust_version
By using the `PartialVersion` type with serde, we get the context for
the error automatically.
2023-08-24 14:15:35 -05:00
Arlo Siemsen 8c13e9ae3f Create dedicated unstable flag for asymmetric-token 2023-08-24 00:12:50 -05:00
Ed Page 937932520b refactor(install): Move version parsing to the CLI 2023-08-23 16:22:31 -05:00
Ed Page 28b7c846af refactor(install): Shift crate argument parsing to clap 2023-08-23 15:25:05 -05:00
Ed Page dc3722254d fix(update): Improve error on bad argument order
This is inspired by `cargo install`
2023-08-23 14:44:13 -05:00
Ed Page 4bf1af0cd0 fix(update): Make -p more convenient by being positional
Generally, cargo avoids positional arguments.  Mostly for the commands
that might forward arguments to another command, like `cargo test`.
It also allows some flexibility in turning flags into options.

For `cargo add` and `cargo remove`, we decided to accept positionals
because the motivations didn't seem to apply as much (similar to `cargo
install`).

This applies the pattern to `cargo update` as well which is in the same
category of commands as `cargo add` and `cargo remove`.

As for `--help` formatting, I'm mixed on whether `[SPEC]...` should be at the top like
other positionals or should be relegated to "Package selection".  I went
with the latter mostly to make it easier to visualize the less common
choice.

Switching to a positional for `cargo update` (while keeping `-p` for
backwards compatibility) was referenced in #12425.
2023-08-23 11:57:36 -05:00
bors 0c2b370b35 Auto merge of #12560 - epage:msrv, r=🙈eh2406🙈
feat(resolver): **Very** preliminary MSRV resolver support

### What does this PR try to resolve?

A bare bones implementation of an MSRV resolver that is good enough for people running on nightly when they really need it but is not ready for general use.

Current limitations
- Does not honor `--ignore-version`
- Gives terrible error messages
- Nothing is done yet regarding `cargo install`
- Doesn't inform the user when choosing non-latest

These will be  noted in #9930 on merge.

Implementation wise, this is yet another hack (sorry `@Eh2406).`  Our expectation to get this GA is to refactor the resolver to make the cargo/resolver boundary look a little more like the cargo/pubgrub boundary so we can better control policy without any of these hacks which will also make having all of the policy we need for this easier to maintain.

This is a part of #9930

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

Per commit
2023-08-28 21:11:20 +00:00
bors 97e73c75c7 Auto merge of #12574 - dtolnay-contrib:untagged, r=epage
Improve deserialization errors of untagged enums

### What does this PR try to resolve?

```toml
# .cargo/config.toml

[http]
ssl-version.min = false
```

**Before:**

```console
$ cargo check
error: data did not match any variant of untagged enum SslVersionConfig
```

**After:**

```console
$ cargo check
error: error in /path/to/.cargo/config.toml: could not load config key `http.ssl-version`

Caused by:
  error in /path/to/.cargo/config.toml: `http.ssl-version.min` expected a string, but found a boolean
```

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

The first commit adds tests showing the pre-existing error messages — mostly just _"data did not match any variant of untagged enum T"_ with no location information. The second commit replaces all `#[derive(Deserialize)] #[serde(untagged)]` with Deserialize impls based on https://docs.rs/serde-untagged/0.1, showing the effect on the error messages.

Tested with `cargo test`, and by handwriting some bad .cargo/config.toml files and looking at the error produced by `rust-lang/cargo/target/release/cargo check`.
2023-08-28 15:06:20 +00:00
bors bfa04bb32b Auto merge of #12535 - hi-rustin:rustin-patch-linker, r=weihanglo
Add support for `target.'cfg(..)'.linker`
2023-08-28 06:14:25 +00:00
hi-rustin 7cbc858b71 Add some tests 2023-08-28 09:29:17 +08:00
hi-rustin 55f0163fb2 Add support for target.'cfg(..)'.linker 2023-08-28 09:28:22 +08:00
David Tolnay 3871aecf3e
Improve deserialization errors of untagged enums 2023-08-27 16:27:08 -07:00
David Tolnay 58d042516e
Fill in more configuration deserialization and manifest deserialization tests 2023-08-27 16:14:29 -07:00
Ed Page 4abd05ea44 test(resolver): Enable msrv-policy
This was kept separate to show that the prior commit didn't change
anything for stable users.
2023-08-25 14:19:22 -05:00
Ed Page 4820624ce7 feat(resolver): Respect MSRV 2023-08-25 10:42:26 -05:00
Ed Page 10196aaee3 test(resolver): Demonstrate existing behavior 2023-08-25 09:59:16 -05:00
bors 2cc50bc0b6 Auto merge of #12515 - arlosi:high-pri-last, r=weihanglo
config: merge lists in precedence order

When merging configuration lists, the current order does not match the expected precedence. This makes merged lists follow precedence order, with higher precedence items merged later in lists.

When a list in configuration exists in multiple places, Cargo merges the lists together. The ordering of this merging is unexpected and does not follow the precedence rules that non-list configuration uses.

The current merging order appears to be:
* project-specific `config.toml`
* global `config.toml`
* command-line (`--config`)
* environment variable (`CARGO_*`)

This PR changes the order to follow the precedence rules with higher precedence configuration merging later in the lists.
* global `config.toml`
* project-specific `config.toml`
* environment variable (`CARGO_*`)
* command-line (`--config`)

This aligns with config such as `build.rustflags` where later flags take precedence over earlier ones.

Since `--config` is relatively new, it's unlikely to cause too much breakage by making it come after environment variables.

Switching global and project-specific ordering is more likely to cause breakage, since it's been around longer (reported as an issue in #8128). Projects relying on global configuration flags (in `$CARGO_HOME\config.toml` or in `.cargo/config.toml` further from the project) being merged first in lists will be broken.

For most uses of merged lists (such as `build.rustflags`), if the flags do not conflict with each other, there will be no impact.

Fixes #12506
Fixes #8128
2023-08-22 22:43:08 +00:00
Weihang Lo 77da514529
test: move --keep-going suggestion match tests to UI tests
We don't want to overly match to suggestion help from clap.
2023-08-22 19:21:09 +01:00
Weihang Lo 4d0958587b
refactor(arg): use UnknownArgumentValueParser to suggest arg for unknown args 2023-08-22 17:24:40 +01:00
Arlo Siemsen 6d7531a163 Add error message for when no credential providers are available 2023-08-18 16:15:30 -05:00
bors 37a0514c75 Auto merge of #12499 - arlosi:cred-args, r=Eh2406
login: allow passing additional args to provider

As part of moving asymmetric token support to a credential provider in #12334, support for passing `--key-subject` to `cargo login` was removed.

This change allows passing additional arguments to credential providers when running `cargo login`. For example:
`cargo login -- --key-subject foo`.

The asymmetric token provider (`cargo:paseto`) is updated to take advantage of this and re-enables setting `--key-subject` from `cargo login`.

r? `@Eh2406`

cc #8933
2023-08-17 19:10:24 +00:00
bors 7b61184ad1 Auto merge of #12498 - Kobzol:run-verbose-print-env, r=arlosi
Print environment variables for `cargo run` in extra verbose mode
2023-08-17 05:32:16 +00:00
Arlo Siemsen 687ace1ddc Merge higher precedence config lists later
When merging configuration lists, the current order does not match
the expected precedence. This makes merged lists follow precedence
order, with higher precedence items merged later in lists.
2023-08-16 11:21:38 -05:00