Commit graph

5674 commits

Author SHA1 Message Date
bors 4aee12c1f8 Auto merge of #12625 - weihanglo:rfc3127, r=epage
feat: implement RFC 3127 `-Ztrim-paths`
2023-10-31 02:23:00 +00:00
Weihang Lo 63cef2c4fc
feat(trim-paths): rustc invocation integration 2023-10-30 16:38:56 -04:00
Weihang Lo 557fc4fd3e
test(trim-paths): verify current behavior with -Ztrim-paths 2023-10-30 16:38:55 -04:00
Weihang Lo 08c5e35f60
test(trim-paths): parsing in mainfest and config 2023-10-30 16:38:55 -04:00
Weihang Lo 4d29af1d81
feat(trim-paths): parsing in mainfest and config 2023-10-30 16:38:55 -04:00
bors 04621e2e0f Auto merge of #12779 - calavera:workspace_adds_implicit_members, r=epage
Add new packages to [workspace.members] automatically

### What does this PR try to resolve?

If a new package is created in a workspace, this change adds the package's path to the workspace's members list automatically.

It doesn't add the package to the list if the path is in the workspace's exclude list, or if the members list doesn't exist already. I noticed that a `cargo_new` test broke if I create the members list when it doesn't exist. This is because the workspace's manifest can be used for package templating. I think it's better to not break that use case.

Fixes #6378

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

I've included tests in the `cargo_new` suite.
2023-10-29 03:02:08 +00:00
David Calavera 1a8bfdf0cf Update workspace manifest with new members.
When a user runs `cargo new` or `cargo init` within a workspace, Cargo will automatically add the new package to the members list in the workspace if necessary. The heuristic to add the new package is as follows:

- If there is no `members` list in the workspace yet, a new `members` list is created.
- If there is an `exclude` statement, Cargo checks if the new package should be excluded. If it doesn't match the `exclude` list, the package is added to the `members` list.
- If there is a glob expression in the `members` list that matches the new package, the package is not added to the `members` list.
- If the existent `members` list is sorted, Cargo tries to preserve the ordering when it adds the new package.

This change doesn't try to format the resulting `members` list in any way, leaving the formatting decissions to the user.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2023-10-28 07:42:23 -07:00
Ed Page acc52f362b refactor(toml): Decouple parsing from interning system
To have a separate manifest API (#12801), we can't rely on interning
because it might be used in longer-lifetime applications.

I consulted https://github.com/rosetta-rs/string-rosetta-rs when
deciding on what string type to use for performance.

Originally, I hoped to entirely replacing string interning.  For that, I
was looking at `arcstr` as it had a fast equality operator.  However,
that is only helpful so long as the two strings we are comparing came
from the original source.  Unsure how likely that is to happen (and
daunted by converting all of the `Copy`s into `Clone`s), I decided to
scale back.

Concerned about all of the small allocations when parsing a manifest, I
assumed I'd need a string type with small-string optimizations, like
`hipstr`, `compact_str`, `flexstr`, and `ecow`.
The first three give us more wiggle room and `hipstr` was the fastest of
them, so I went with that.

I then double checked macro benchmarks, and realized `hipstr` made no
difference and switched to `String` to keep things simple / with lower
dependencies.

When doing this, I had created a type alias (`TomlStr`) for the string
type so I could more easily swap it out if needed
(and not have to always write out a lifetime).
With just using `String`, I went ahead and dropped that.

I had problems getting the cargo benchmarks running, so I did a quick
and dirty benchmark that is end-to-end, covering fresh builds, clean
builds, and resolution.  I ran these against a fresh clone of cargo's
code base.
```console
$ ../dump/cargo-12801-bench.rs run
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/cargo -Zscript -Zmsrv-policy ../dump/cargo-12801-bench.rs run`
warning: `package.edition` is unspecified, defaulting to `2021`
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/epage/.cargo/target/0a/7f4c1ab500f045/debug/cargo-12801-bench run`
$ hyperfine "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     119.3 ms ±   3.2 ms    [User: 98.6 ms, System: 20.3 ms]
  Range (min … max):   115.6 ms … 124.3 ms    24 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     119.4 ms ±   2.4 ms    [User: 98.0 ms, System: 21.1 ms]
  Range (min … max):   115.7 ms … 123.6 ms    24 runs

Summary
  ../cargo-old check ran
    1.00 ± 0.03 times faster than ../cargo-new check
$ hyperfine --prepare "cargo clean" "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     20.249 s ±  0.392 s    [User: 157.719 s, System: 22.771 s]
  Range (min … max):   19.605 s … 21.123 s    10 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     20.123 s ±  0.212 s    [User: 156.156 s, System: 22.325 s]
  Range (min … max):   19.764 s … 20.420 s    10 runs

Summary
  ../cargo-new check ran
    1.01 ± 0.02 times faster than ../cargo-old check
$ hyperfine --prepare "cargo clean && rm -f Cargo.lock" "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     21.105 s ±  0.465 s    [User: 156.482 s, System: 22.799 s]
  Range (min … max):   20.156 s … 22.010 s    10 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     21.358 s ±  0.538 s    [User: 156.187 s, System: 22.979 s]
  Range (min … max):   20.703 s … 22.462 s    10 runs

Summary
  ../cargo-old check ran
    1.01 ± 0.03 times faster than ../cargo-new check
```
2023-10-27 12:09:44 -05:00
Ed Page 293f2250d6 feat(doc): Print the generated docs links
I've wanted something like this myself.  I dislike using `--open`
because I tend to move up to re-run my `cargo doc` run but then have to
edit it to remove `--open`.
Also makes it annoying when opening docs when `cargo doc` is wrapped by
a tool like `make`.

This was previously attempted in #5592:
- Unlike the request in #5562, this aligns with #5592 in always printing
  rather than using a flag as this seems generally useful
- Unlike #5592, this prints as an alternative to "Opening" to keep
  things light
- Unlike #5592, this prints afterwards as the link is only valid then

Fixes #5562
2023-10-19 10:51:56 -05:00
bors 307486ed18 Auto merge of #12786 - epage:version, r=weihanglo
feat(toml): Allow version-less manifests

### What does this PR try to resolve?

Expected behavior with this PR:
- `package.version` defaults to `0.0.0`
- `package.publish` is defaulted to `version.is_some()`

This also updates "cargo script" to rely on this new behavior.

My motivation is to find ways to close the gap between "cargo script" and `Cargo.toml`.  With "cargo script", we want to allow people to only write however much of a manifest is directly needed for the work they are doing (which includes having no manifest).  Each difference between "cargo script" and `Cargo.toml` is a cost we have to pay in our documentation and a hurdle in a users understanding of what is happening.

There has been other interest in this which I also find of interest (from #9829):
- Lower boilerplate, whether for [cargo xtasks](https://github.com/matklad/cargo-xtask), nested packages (rust-lang/rfcs#3452), etc
- Unmet expectations from users because this field is primarily targeted at registry operations when they want it for their marketing version (#6583).
- Make "unpublished" packages stand out

This then unblocks unifying `package.publish` by making the field's default based on the presence of a version as inspired by the proposal in #9829.  Without this change, we were trading one form of boilerplate (`version = "0.0.0"`) for another (`publish = false`).

Fixes #9829
Fixes #12690
Fixes #6153

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

The initial commit has test cases I thought would be relevant for this change and you can see how each commit affects those or existing test cases.  Would definitely be interested in hearing of other troubling cases to test

Implementation wise, I made `MaybeWorkspaceVersion` deserializer trim spaces so I could more easily handle the field being an `Option`.  This is in its own commit.

### Additional information

Alternatives considered
- Making the default version "stand out more" with it being something like `0.0.0+HEAD`.  The extra noise didn't seem worth it and people would contend over what the metadata field *should be*
- Make the default version the lowest version possible (`0.0.0-0`?).  Unsure if this will ever really matter especially since you can't publish
- Defer defaulting `package.publish` and instead error
  - Further unifying more fields made this too compelling for me :)
- Put this behind `-Zscript` and make it a part of rust-lang/rfcs#3502
  - Having an affect outside of that RFC, I wanted to make sure this got the attention it deserved rather than getting lost in the noise of a large RFC.
- Don't just default the version but make packages versionless
  - I extended the concept of versionless to `PackageId`'s internals and saw no observable difference
  - I then started to examine the idea of version being optional everywhere (via `PackageId`s API) and ... things got messy especially when starting to look at the resolver.  This would have also added a lot of error checks / asserts for "the version must be set here".  Overall, the gains seemed questionable and the cost high, so I held off.
2023-10-27 16:09:12 +00:00
Urgau e396904b25 Add feature gate test for check-cfg config, build script and override 2023-10-27 17:10:49 +02:00
bors fcc3786d73 Auto merge of #12868 - hi-rustin:rustin-patch-install, r=weihanglo
Remove duplicate binaries during install
2023-10-27 01:28:20 +00:00
hi-rustin 731ae05ae3 Dedup the same version binaries
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-27 09:16:18 +08:00
hi-rustin 397f446dcd Add test for installing the same binary twice
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-27 09:16:12 +08:00
bors f5418fcfeb Auto merge of #12766 - shnaramn:WarnAboutNameCase, r=epage
Warn about crate name's format when creating new crate

### What does this PR try to resolve?
Warns about a crate's name during creation (`crate new ...`) if it doesn't follow the preferred snake_case format.

Fixes #2708

The warning message uses the language mentioned in [RFC 430](https://github.com/rust-lang/rfcs/blob/master/text/0430-finalizing-naming-conventions.md#general-naming-conventions).

### How should we test and review this PR?
Verified existing tests succeeded with updates.  Added new tests to verify fix.

### Additional information
The link to [API naming guidelines](https://rust-lang.github.io/api-guidelines/naming.html) was not used since it still stays `unclear` for naming convention for crates.
2023-10-23 17:17:58 +00:00
Jacob Finkelman 6644828028 add test 2023-10-19 18:44:42 +00:00
bors b227fe137a Auto merge of #12857 - epage:unstable, r=weihanglo
fix(cli): Provide next steps for bad -Z flag

In #5546, they suggested we have a list of them but that would be hard to keep up and works well enough to just always mention it.

Fixes #5546
2023-10-19 16:34:17 +00:00
bors c26943919a Auto merge of #12837 - epage:remove, r=weihanglo
fix(remove): Preserve feature comments

### What does this PR try to resolve?

We've been having a hard time balancing leaving the feature list in a good looking start and preserving formatting.  With our new formatting policy (#12836), we can just choose to preserve formatting instead.

Fixes #11743

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

The first commit copies an existing test.  The second is where the fun begins, customizing the test for some weird cases.  The follow up commits do the slow walk for improving it.

We ended up preserving some line-trailing comments because they come after the comma and toml_edit treats that as part of the prefix of the next item.  Tracking removal of that was going to require us to determine if the newline existed in the suffix or in the next item's prefix and edit accordingly and I decided to skip that to keep this initial implementation simpler.

### Additional information
2023-10-19 15:36:20 +00:00
Ed Page 51aeeb01ff fix(cli): Provide next steps for bad -Z flag
In #5546, they suggested we have a list of them but that would be hard
to keep up and works well enough to just always mention it.

Fixes #5546
2023-10-19 09:29:05 -05:00
bors 141667875e Auto merge of #12841 - epage:help, r=weihanglo
fix(help):Clarify install's positional

### What does this PR try to resolve?

- That a version is accepted
- That you are selecting from the source a package which led to part of
  the confusion in #4830

I wonder if we should rename our `CRATE` value names to `PKG`/`PACKAGE`

While doing this, I decided to fix the inconsistency in how we handle value names in help.

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

### Additional information
2023-10-18 17:45:08 +00:00
bors 16629e6a5a Auto merge of #12845 - Urgau:check-cfg-adjust-for-rustc, r=epage
Adjust `-Zcheck-cfg` for new rustc syntax and behavior

https://github.com/rust-lang/rust/pull/111072 introduced a new syntax for `rustc` `--check-cfg` argument. This PR adjust cargo `-Zcheck-cfg` for new that new syntax and behavior.

This PR removes all the `-Zcheck-cfg` options (`features`, `names`, `values`, `output`), as they don't make much sense now since with the new `rustc` behavior: `features`, `names` and `values` are all combine together and the `output` option was only here because the other were.

Now the new behavior from cargo is to always pass one `--check-cfg` argument to rustc for the `feature`s which implicitly enables well known names and values.
2023-10-18 16:29:03 +00:00
bors 67271fd7a9 Auto merge of #12806 - epage:replace, r=Eh2406
fix(replace): Partial-version spec support

### What does this PR try to resolve?

#12614 changed package ID specs to allow fields in the version number to be optional.  This earliest branch with this change is `rust-1.74.0` (beta).  While `@Eh2406` was investigating version metadata issues in #12772, problems with the partial version change were found
- `replace`s that specify version metadata were ignored **(fixed with this PR)**
  - This also extends out to any other place a PackageIDSpec may show up, like `cargo check -p <name>`@<spec>``
  - We explicitly kept the same semantics of version requirements that pre-releases require opt-in.  If nothing else, this gives us more room to change semantics in the future if we ever fix the semantics for pre-release.
- `replace`s that don't specify version metadata when the `Cargo.lock` contained a version metadata, it would previously be ignored (with a warning) but now match **(unchanged with this PR)**
  - When the version metadata in `Cargo.lock` differed from the overriding `Cargo.toml`, cargo would panic **(now an error in this PR)**

With this PR, we are acknowledging that we changed behavior in taking ignored replaces (because of differences with version metadata) and applying them.  Seeing as version metadata is relatively rare, replaces are relatively rare, and differences in it for registries is unsupported, the impact seems very small.

The questions before us are
- Do we revert #12614 in `master` and `rust-1.74.0` or merge this PR into `master`
- If we merge this PR into `master`, do we cherry-pick this into `rust-1.74.0` or revert #12614, giving ourselves more time to find problems

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

The initial commit adds tests that pass as of #12614.  Prior to #12614, these tests would have warned that the `replace` was unused and failed because `bar::bar` didn't exist.  Each commit then changes the behavior (or not) and updates the corresponding test.

### Additional information
2023-10-18 15:42:23 +00:00
Urgau 4b93690c9d Adjust -Zcheck-cfg for new rustc syntax and behavior
This commit removes all the -Zcheck-cfg options (features, names,
values, output), as they don't make much sense now since features, names
and values are all combine together for upstream rustc and the output
option was only here because the other were.

Now the new behavior from cargo is to always pass one `--check-cfg`
argument to rustc for the `feature`s which implicitly enables well known
names and values.
2023-10-18 15:10:25 +02:00
bors a275529de2 Auto merge of #12829 - Nilstrieb:verbosebuildrs, r=weihanglo
Print environment variables for build script executions with `-vv`

### What does this PR try to resolve?

When debugging complicated builds (I was trying to figure out how  `cargo-miri` cross-compiles compiler_builtins without needing a C cross compiler), it's useful to see all the environment variables passed to the build script.

This is also consistent with other commands.

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

I tested it locally by creating a small crate with an empty `build.rs` and building it. Additionally, a test is included.
2023-10-18 02:52:14 +00:00
bors 709ac17f62 Auto merge of #12840 - epage:suggest, r=hi-rustin
fix(cli): Suggest cargo-search on bad commands

This is a low-tech solution alternative to the options proposed in #4682
- Search `[[bin]]`s within all packages in the registry (which aren't tracked atm), suggesting to `cargo install` what is found
- Check if `cargo-<cmd>` is in the registry, suggesting `cargo install if it is

By suggesting `cargo search`, we are giving them a tool so they can verify if the package is what they want (a `cargo info` would help as a next step).

Is is needed?
- New users might not know of `cargo search` but they can search on crates.io
- New users might not be aware of the `cargo-<cmd>` naming pattern

Seems like this can still offer some benefit.

Fixes #4682
2023-10-18 01:51:13 +00:00
Ed Page 5f0596941f fix(help): Clarify install's positional
- That a version is accepted
- That you are selecting from the source a package which led to part of
  the confusion in #4830

I wonder if we should rename our `CRATE` value names to `PKG`/`PACKAGE`
2023-10-17 16:48:15 -05:00
Ed Page 99f917a67e fix(help): Consistently use SCREAMING_CASE for value names
- We have some positional value names that are SCREAMING_CASE and some
  that aren't
- All of the value names for our flags are already SCREAMING_CASE
2023-10-17 16:47:44 -05:00
Ed Page ec3ed20d2a fix(cli): Suggest cargo-search on bad commands
This is a low-tech solution alternative to the options proposed in #4682
- Search `[[bin]]`s within all packages in the registry (which aren't
  tracked atm), suggesting to `cargo install` what is found
- Check if `cargo-<cmd>` is in the registry, suggesting `cargo install
  if it is

By suggesting `cargo search`, we are giving them a tool so they can
verify if the package is what they want (a `cargo info` would help as a
next step).

Is is needed?
- New users might not know of `cargo search` but they can search on
  crates.io
- New users might not be aware of the `cargo-<cmd>` naming pattern

Seems like this can still offer some benefit

Fixes #4682
2023-10-17 14:46:30 -05:00
Ed Page 02dd917511 fix(add): Add back in some auto-formatting
This moves the auto-format to the correct place so it takes effect.
2023-10-17 12:48:45 -05:00
Ed Page 99e4847d78 fix(add): Stop auto-formatting content
Huh, overlooked the cargo side when I fixed this in killercup/cargo-edit#725

Fixes #10850
2023-10-17 12:48:08 -05:00
Ed Page 716ae6238f test(add): Check table formatting issues 2023-10-17 12:23:45 -05:00
Ed Page 6281109e5b fix(remove): Carry comments across removes 2023-10-17 11:56:54 -05:00
Ed Page 5374e8aa70 fix(remove): Leave formatting to the user
Fixes #11743
2023-10-17 11:51:45 -05:00
Ed Page b17a73df1d test(remove): Extend the formatting tested 2023-10-17 11:49:26 -05:00
Ed Page 253a944aca test(remove): Add a more extensive formatting test 2023-10-17 10:49:33 -05:00
Ed Page 1e34066360 test(replace): Clarify name for remaining new test 2023-10-17 10:09:45 -05:00
Ed Page 7502318a85 fix(replace): Error, rather than assert, on version mismatch 2023-10-17 10:09:45 -05:00
Ed Page 0ec3274326 fix(spec): Ensure PackageIdSpec respects version 'build' field 2023-10-17 10:09:41 -05:00
David Calavera 8849d25218 Update rm help to be specific about the section.
Signed-off-by: David Calavera <david.calavera@gmail.com>
2023-10-17 11:53:57 +02:00
Shankar Mathiah Nanjundan 901018c3db Fixes #2708
Warns about not using snake_case or kebab-case format when creating new packages with `cargo new` command.
2023-10-16 23:39:19 -07:00
Ed Page ae068fbf4c test(replace): Show behavior post-#12614
PR #12614
- Changed ignored replaces to not-ignored
- Has bugs in matching replaces
2023-10-16 11:09:27 -05:00
Nilstrieb d4044c9d01 Print environment variables for build script executions with -vv
This is consistent with other commands.
2023-10-15 19:50:11 +02:00
bors fadb3b1c60 Auto merge of #12822 - hi-rustin:rustin-patch-version, r=weihanglo
Add test for `-V` short argument

Just found it when I randomly jumped into this file :(
2023-10-14 15:46:11 +00:00
hi-rustin 267ae195e3 Add test for -V short argument
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-14 23:16:11 +08:00
Alex Crichton 756fc4084e Support public dependency configuration with workspace deps
This commit updates the processing of `workspace = true` dependencies in
the `[dependencies]` section to process the `public` field. Previously
this field was ignored and didn't get plumbed through as configured.
2023-10-13 00:32:05 -07:00
hi-rustin 497e1ee307 Better suggestion for unsupported -path flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-12 19:24:42 +08:00
hi-rustin 95d79094e0 Add test for unsupported --path flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-12 09:01:34 +08:00
bors 71de58d5cf Auto merge of #12799 - marchiore:warn_add_package_name, r=epage
feat: add package name and version to warning messages

### What does this PR try to resolve?

Hi, this PR Fixes #8018, where i add the package name and version on warning messages.
As this is my first contribution to the project, if anything is not in compliance in the PR let me know and I will be happy to correct it.
2023-10-11 19:59:57 +00:00
Matheus Z Marchiore 380719da35 feat: add package name and version to warning messages 2023-10-11 16:52:30 -03:00
Ed Page bfb5d1db0e fix(toml): Default package.publish based on presence of package.version
Before the default was hardcoded to `true`.  The problem was that means
that to remove the `package.version` boilerplate, you had to add
`package.publish = false` boilerplate.

To make the errors easier to understand in this situation, I err on the
side of encouraging people to put `publish = true` in their manifests.

By making this change, we also unblock "cargo script" /
`Cargo.toml` unifying the handling of `package.publish`.
2023-10-11 13:17:03 -05:00
Ed Page 1923b5b862 feat(toml): Allow versionless packages
This defaults the version to `0.0.0` for most of cargo.

It is an error to lack a version and have a package publishable.
That means you have to add `publish = false`.
2023-10-11 13:13:44 -05:00
bors 90fb62fc65 Auto merge of #12796 - dtolnay-contrib:switching, r=epage
Do not call it "Downgrading" when difference is only build metadata

### What does this PR try to resolve?

When a `cargo update --precise` changes a dependency between 2 versions which differ only in build metadata, Cargo prints a log referring to it as "Updating" or "Downgrading" the dependency, depending on a comparison between the build metadatas.

This is usually not meaningful, given that build metadata is often stuff like git commit hashes, which are not meaningfully ordered.

```console
    Updating crates.io index
 Downgrading foo v0.0.1+43ef4fe -> v0.0.1+2c65d16
    Updating bar v0.0.2+bc17664 -> v0.0.2+c144a98
```

~~This PR changes to the word "Switching" when the version major, minor, patch, and pre-release value are not being changed.~~
This PR uses the word "Updating" when the version major, minor, patch, and pre-release value are unchanged, regardless of whether the build metadata is going up or down.

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

- `cargo test`
- `cargo build --release`
- `/path/to/cargo/target/release/cargo add tonic_datastore_v1`
- `/path/to/cargo/target/release/cargo update -p tonic_datastore_v1 --precise 0.1.0+3562b6cb3`
- `/path/to/cargo/target/release/cargo update -p tonic_datastore_v1 --precise 0.1.0+ee9e8e4e6`

Before:
<img src="https://github.com/rust-lang/cargo/assets/1940490/93e377e7-928e-4cec-aff6-451166ef7c81" width="500">

~~After:~~
<img src="https://github.com/rust-lang/cargo/assets/1940490/bb71459e-469a-4e09-bb8a-4083f34bce79" width="500">

After:
<img src="https://github.com/rust-lang/cargo/assets/1940490/8804e2fe-d0de-4c9e-b463-a5742daf9446" width="500">
2023-10-11 14:21:44 +00:00
hi-rustin b514ca5e24 Add unsupported short flag suggestion for --exclude flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:41:05 +08:00
hi-rustin 718b69ce19 Add test for unsupported short exclude flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:39:13 +08:00
hi-rustin 819a836e9a Add unsupported short flag suggestion for --target flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:16:26 +08:00
hi-rustin 2f90430110 Add test for unsupported short target triple flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:13:55 +08:00
Weihang Lo a263a7dc31
test(build): generalize test assertion for non-rustup env 2023-10-10 17:52:46 -04:00
bors 8ba1c316ee Auto merge of #12798 - epage:msrv-install, r=ehuss
fix(install): Suggest an alternative version on MSRV failure

### What does this PR try to resolve?

Moves users from a bad error message, suggesting `--locked` which won't do anything, to suggesting a version of a package to use instead.

The side benefit is errors get reported sooner
- Before downloading the `.crate`
- When installing multiple packages, before building the first

This comes at the cost of an extra `rustc` invocation.

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

Per-commit this builds it up, from tests to the final design.

### Additional information

This is also written in a way to align fairly well with how we'd likely implement #10903.
This improved error message will still be useful after that issue is resolved when the MSRV compatible version is outside of the version req.
2023-10-10 20:03:41 +00:00
Michael Howell f0d3cdf191 rustdoc: remove the word "Version" from test cases
Needed for https://github.com/rust-lang/rust/pull/115948 to merge.
2023-10-10 11:19:57 -07:00
bors c97c906b79 Auto merge of #12788 - hi-rustin:rustin-patch-short-Z, r=epage
Add unsupported lowercase `-z` flag suggestion for `-Z` flag
2023-10-10 01:33:31 +00:00
Ed Page 9b32be7f89 fix(install): Suggest an alternative version on MSRV failure
The next step would be to also automatically install an MSRV compatible
version if compatible with the version req (#10903).
This improved error message will still be useful if the MSRV compatible
version is outside of the version req.

I did this as the first step
- Helps people now, not needing to wait on `-Zmsrv-policy` to be stabilized
- Has fewer questions on how it should be done (or if it should be)
2023-10-09 20:22:54 -05:00
Ed Page 2976e2ac66 fix(install): Don't suggest --locked for MSRV when its root package
This will also report the error without having to download the `.crate`
first.

If installing multiple packages, this will also report it immediately,
rather than waiting for the other packages to be installed first.

This also offers us more flexibility in the error we report,
like suggesting more appropriate fixes.
2023-10-09 16:31:30 -05:00
David Tolnay 985e1eeef5
Do not call it "Downgrading" when difference is only build metadata 2023-10-09 13:53:47 -07:00
Ed Page 699b30a5f4 test(install): Verify existing top-level MSRV behavior 2023-10-09 15:48:53 -05:00
David Tolnay 4d1bf29a2c
Add test of update with version that differ only in build metadata 2023-10-09 10:36:46 -07:00
Eric Huss fd6185193a Rewrite the cache locker to use functions instead of macros. 2023-10-08 14:16:51 -07:00
Eric Huss b4982adfd9 Add a new package cache locking system.
This introduces a new `CacheLocker` which manages locks on the package
cache. Instead of either being "locked" or "not locked", the new locker
supports multiple modes:

- Shared lock: Cargo can read from the package sources, along with any
  other cargos reading at the same time.
- Download exclusive lock: Only one cargo can perform downloads.
  Download locks do not interfere with Shared locks, since it is
  expected that downloading does not modify existing files (only adds
  new ones).
- Mutate exclusive lock: Only one cargo can have this lock, and it also
  prevents shared locks. This is so that the cargo can modify the
  package cache (such as deleting files) without breaking concurrent
  processes.
2023-10-08 14:16:51 -07:00
Eric Huss b37c8f35c0 Add ConfigBuilder::root
This adds the `root` method to set the root directory to be able to
override paths::root().
2023-10-08 14:16:51 -07:00
hi-rustin f9719dcf4e add unsupported lowercase flag suggestion for -Z flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-08 08:36:49 +08:00
hi-rustin 0108d5b0dc Add test for unsupported short unstable feature flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-08 08:36:09 +08:00
Ed Page 5c9a126911 test(toml): Verify existing version-less behavior 2023-10-06 12:21:07 -05:00
bors fc790e7b2d Auto merge of #12781 - dvdhrm:pr/target-typo, r=epage
cargo/targets: fix error-message typo

Fix typo: "with with" -> "with"
2023-10-06 13:59:27 +00:00
David Rheinsberg 4aa1a95714 cargo/targets: fix error-message typo
Fix typo: "with with" -> "with"
2023-10-06 15:08:48 +02:00
hi-rustin 2400e42652 add unsupported short suggestion for --config flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-06 16:27:31 +08:00
hi-rustin 914119940b Add test for unsupported short config flag 2023-10-06 16:16:35 +08:00
Scott Schafer b2b3cfa524
feat: Add Edition2024 2023-10-04 13:11:52 -06:00
hi-rustin 7bd0f81257 Add unsupported short suggestion for --out-dir flag 2023-10-04 13:15:09 +08:00
hi-rustin f67b58f93f Add test for unsupported short out dir flag 2023-10-04 12:41:19 +08:00
bors 9a94183771 Auto merge of #12744 - tompscanlan:atomic-write, r=epage
fix bug: corruption when cargo killed while writing

### What does this PR try to resolve?

fix  #11386, superseding #12362

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

Added unit test showing basic equivalency to existing `write(path, content)`. Full test suite should exercise write.
Added tests for cargo add and remove. These are timing tests, so take a bit of time to run. 5-10s each.  They may not fail every time, but do so regularly.  Making the change to these two writes seems to prevent me from failing these tests at all.

### Additional information

This uses tempfile::persist which was an existing dependency. atomicwrites crate, an alternative option for this fix, indicates `tempfile::persist` is the same thing.  Since we already use tempfile as a dep, I stuck with that.
2023-10-02 13:34:00 +00:00
bors 1f94bf2db8 Auto merge of #12763 - ehuss:custom_bin_target-windows-gnu, r=weihanglo
Disable custom_target::custom_bin_target on windows-gnu

The `custom_target::custom_bin_target` test has been crashing frequently in CI on the x86_64-pc-windows-gnu target since the last LLVM 17 update. This disables the test to reduce the disruption in CI. The issue is being tracked in https://github.com/rust-lang/rust/issues/115985.
2023-10-02 04:12:23 +00:00
Eric Huss 704a5d32b5 Disable custom_target::custom_bin_target on windows-gnu 2023-10-01 19:14:46 -07:00
Tom Scanlan aee8c75410
bug: corruption when killed while writing 2023-10-01 08:29:24 -04:00
bors e3acdd321f Auto merge of #12723 - hi-rustin:rustin-patch-silent, r=weihanglo
Add better suggestion for the unsupported silent flag
2023-09-28 07:06:25 +00:00
hi-rustin 44d955b15d Fix test on windows 2023-09-28 10:10:19 +08:00
hi-rustin 5d8009a189 Better suggestion for unsupported silent flag 2023-09-28 09:25:17 +08:00
bors 25dc3bdc5d Auto merge of #12681 - epage:frontmatter, r=Muscraft
feat(embedded): Hack in code fence support

### What does this PR try to resolve?

This is to allow us to get feedback on the design proposed
[on zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Embedding.20cargo.20manifests.20in.20rust.20source/near/391427092)
to verify we want to make an RFC for this syntax.

````rust
#!/usr/bin/env cargo
```cargo
[dependencies]
clap = { version = "4.2", features = ["derive"] }
```

use clap::Parser;

#[derive(Parser, Debug)]
#[clap(version)]
struct Args {
    #[clap(short, long, help = "Path to config")]
    config: Option<std::path::PathBuf>,
}

fn main() {
    let args = Args::parse();
    println!("{:?}", args);
}
````

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

The tests were updated in a separate commit to ensure there was no regression while then migrating to the new syntax to make sure it worked.

This involves some future work
- Removing doc comment support
- Getting the syntax approved and implemented
- Migrating to rustc support for the syntax

#12207 was updated to record these items so we don't lose track of them
2023-09-26 15:35:38 +00:00
bors 0b6cc3c75f Auto merge of #12732 - tompscanlan:12576-registry-error-msg, r=epage
more specific registry index not found msg

### What does this PR try to resolve?

covers #12576

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

test covers exact text, so a review and passing tests.
2023-09-25 17:41:03 +00:00
Tom Scanlan 3393fdc528
more specific registry index not found msg 2023-09-24 15:43:18 -04:00
Eric Huss ebea09d8f4 Fix spurious errors with networking tests. 2023-09-22 13:37:26 -07:00
hi-rustin 61648f583e Add test for unsupported silent flag 2023-09-22 10:50:23 +08:00
Weihang Lo a30d9fde98
test: verify source replacement displays registry key 2023-09-21 12:53:24 +08:00
bors 5bf83d8146 Auto merge of #12693 - hi-rustin:rustin-patch-unsupported-flags, r=epage
Better suggestion for unsupported mode in build command
2023-09-21 02:40:07 +00:00
hi-rustin 97656fbf87 Correct the helper name and the tip message 2023-09-21 10:12:03 +08:00
hi-rustin 817c2cbbb5 Better suggestion for unsupported mode in install command 2023-09-20 11:31:36 +08:00
hi-rustin 7644a4bd96 Add test for using unsupported mode in install command 2023-09-20 11:27:56 +08:00
hi-rustin ed86337492 Better suggestion for unsupported mode in build command 2023-09-20 11:24:44 +08:00
hi-rustin f262297e9a Add test for using unsupported mode in build command 2023-09-20 11:23:01 +08:00
Eric Huss c2047345bd Don't display paths with cargo clean --dry-run without --verbose
The paths themselves aren't particularly interesting.
2023-09-19 18:24:45 -07:00
Eric Huss f61d42d5ef Add a warning to cargo clean --dry-run
This makes it more consistent with other `--dry-run` commands, and
makes it clearer to the user that cargo did not do anything.
2023-09-19 18:24:45 -07:00
Eric Huss ebee726d8f Separately track files and directories removed.
The previous status line was a little awkward in the way it combined
both counts. I don't think showing the directories is particularly
interesting, so they are only displayed when no files are deleted.
2023-09-19 18:24:37 -07:00
Eric Huss 495ed7ebe2 Add a summary to cargo clean.
This adds a summary at the end when `cargo clean` finishes that displays
how many files and bytes were removed.
2023-09-19 18:16:40 -07:00
Eric Huss 45c5394703 Add a --dry-run option to cargo clean.
This adds a `--dry-run` option to have `cargo clean` display what it
would delete without actually deleting it.
2023-09-19 18:14:47 -07:00
bors f9335babbc Auto merge of #12707 - epage:spell, r=ehuss
chore: Fix typos

This is a repeat of #11561
2023-09-19 22:07:03 +00:00
Ed Page e4e10f2393 chore: Fix typos
This is a repeat of #11561
2023-09-19 15:28:48 -05:00
Angelo Ross 72dccecb19
Display only feature list or summarized on cargo add 2023-09-19 13:14:44 -03:00
Ed Page a365a69130 test(embedded): Migrate to new syntax 2023-09-18 14:47:56 -05:00
Ethan Brierley 9831e83fb2 generalise suggestion on abiguous spec
Fixes #12433
2023-09-18 16:34:17 +01:00
bors 695416e8d8 Auto merge of #12660 - epage:dry, r=weihanglo
feat(cli): Add '-n' to dry-run

This came from #12638 and my many small frustrations from wanting to use `-n` and not being able to.

We do not have any existing `-n` flags for this to be confused with.

I would wager that `-n` is such an entrenched short flag in build tools that it would not make sense for us to use it with any other flag.

For a survey of where `-n` is used as a short, see https://www.gnu.org/prep/standards/html_node/Option-Table.html#Option-Table
2023-09-18 02:53:19 +00:00
bors 7149418ed3 Auto merge of #12649 - arlosi:cred-stable, r=weihanglo
feat: stabilize credential-process and registry-auth

Stabilization PR for `registry-auth` and `credential-process`.

Tracking approval of this stabilization is done in the via the FCP in [#8933](https://github.com/rust-lang/cargo/issues/8933#issuecomment-1711990123). This PR is here to help reviewers of the FCP.

* Stabilizes `registry-auth` and `credential-process`
* Makes authenticated registries require a credential provider
* Adds stable documentation for credential providers and authenticated registries

Closes #8933
Closes #10474
2023-09-18 01:17:44 +00:00
bors 41cef471d0 Auto merge of #12677 - weihanglo:registry-or-index, r=hi-rustin
refactor: use `RegistryOrIndex` enum to replace two booleans
2023-09-17 15:19:48 +00:00
Arlo Siemsen d345ca212f feat: stabilize credential-process and registry-auth 2023-09-16 22:40:45 -05:00
Weihang Lo e883054c59
test: verify publish failed with --index and the only implicit allowed registry
The message is misleading and shouldn't proceed when `--index` presents.
2023-09-16 00:48:41 +08:00
Weihang Lo e57ce13da8
refactor: --registry always conflicts with --index
Move the validation upfront to clap
2023-09-15 22:33:27 +08:00
Weihang Lo 1f172e4b76
refactor: extract registry and index arg for reuse 2023-09-15 18:30:28 +08:00
Arlo Siemsen 8f18f2bdc8 fix: emit a warning when a credential provider alias shadows a built-in provider 2023-09-14 14:33:59 -05:00
bors 5c84ce06f0 Auto merge of #12662 - Angelin01:limit-cargo-add-feature-print, r=weihanglo
Limit cargo add feature print
2023-09-14 13:19:16 +00:00
Angelo Ross 9928689d2c
Limit features printed during cargo add 2023-09-14 08:36:44 -03:00
Ed Page 82f9bd330e feat(spec): Allow partial versions when unambigious
This was proposed in #12425 to help improve usability of the existing
`cargo update` when dealing with the added workflows.
2023-09-13 22:00:00 -06:00
Ed Page 9008647ae2 test(clean): Verify spec version parsing 2023-09-13 21:59:28 -06:00
Ed Page 396298200d test(profile): Verify spec version parsing 2023-09-13 21:59:28 -06:00
Angelo Ross 3a40df85d6
Showcase output with too many features 2023-09-13 11:58:48 -03:00
Ed Page 033e06a1cc feat(cli): Add '-n' to dry-run
This came from #12638 and my many small frustrations from wanting to use
`-n` and not being able to.

We do not have any existing `-n` flags for this to be confused with.

I would wager that `-n` is such an entrenched short flag in build tools that it would
not make sense for us to use it with any other flag.

For a survey of where `-n` is used as a short, see
https://www.gnu.org/prep/standards/html_node/Option-Table.html#Option-Table
2023-09-12 13:42:00 -05: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
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
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 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
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
Jacob Finkelman 44666f7377 Ues strip_prefix for cleaner code 2023-09-07 17:57:28 +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
Eric Huss f49b038a3f Error out if cargo clean --doc is mixed with -p.
Currently the `-p` is ignored. This should help with any confusion
about the interaction of different flags.
https://github.com/rust-lang/cargo/issues/8790 is tracking to fix this.
2023-09-06 21:42:38 -07:00
bors d9a4cf1938 Auto merge of #12626 - arlosi:cred-error-both, r=weihanglo
fix: improve warning for both token & credential-provider

Cargo issues a warning when both a `credential-provider` and a `token` are configured for a registry.

This change removes the warning if the `credential-provider` is `cargo:token` since that *will* use the token. The warning message text is also tweaked to include the name of the `credential-provider` that's overriding the token.
2023-09-06 18:02:59 +00:00
Arlo Siemsen 3f004c613c fix: improve error for token & provider 2023-09-06 10:10:02 -05:00
hi-rustin 63ccc35642 Add skip gc glob profile test 2023-09-06 12:51:39 +08:00
bors d14c85f4e6 Auto merge of #12602 - epage:resolver, r=Eh2406
fix(resolver): Make resolver behavior independent of package order

This address one of the problems mentioned in #12599

The intent behind the `path_pkg` check is to make sure we update
workspace members in the lockfile if their version number changed.
In this case, we don't need to recursively walk, because the change
doesn't affect dependencies.  However, we also shouldn't *prevent*
recursive walks which is what we are doing today, both for packages
marked to keep and for packages that have been "poisoned".  So we fix
this by moving that call after all recursive adds are complete so as to
not interfere with them.

This should not affect `Cargo.lock` at rest, so no upgrade compatibility concerns.

This just allows more packages to be considered available to change which can prevent unclear failures.

The main case I can think of that this does something "undesirable" is when wanting to prevent another "bug" from manifesting: the updating of git dependencies when updating workspace members (#12599).  I think I'm ok with that as that needs to be looked into separately.
2023-09-05 22:28:10 +00:00
Arlo Siemsen e58b84d35e breaking change(cargo-credential)
Changes the JSON format for cache:expires
2023-09-05 15:22:27 -05:00
Arlo Siemsen b8099be284 fix: make more credential JSON fields skip_serializing if None 2023-09-05 13:31:23 -05:00
bors 5f40a97e5c Auto merge of #12618 - weihanglo:cleanup-170-debuginfo, r=Muscraft
test: new options of debuginfo are no longer unstable
2023-09-03 16:52:20 +00:00
Weihang Lo 63be1e0d8b
test: new options of debuginfo are no longer unstable 2023-09-01 16:19:47 +01:00
Ed Page e46379a7f3 fix(remove): Include 'cargo help' suggestion in -h 2023-09-01 09:30:00 -05:00
Ed Page 802cb380ed fix(cli): Be more specific in what is needed 2023-08-31 08:56:16 -05:00
Ed Page adea3d148e fix(cli): Help people find possible --target values 2023-08-31 08:55:36 -05:00
Ed Page b87c9323bb refactor(cli): Manually implement missing arg error for --target 2023-08-30 20:42:45 -05:00
Ed Page 801b223135 test(cli): Show existing --target behavior 2023-08-30 20:34:42 -05:00
Ed Page a78bba7a92 fix(manifest): Improve error on good pre-release 2023-08-30 16:42:08 -05:00
Ed Page 9fb8128d9e test(manifest): Verify error on good pre-release 2023-08-30 16:42:08 -05:00
bors 0bd1f71579 Auto merge of #12593 - epage:help-list, r=ehuss
fix(help): Provide better commands heading for styling

In working on #12578, I felt it would be weird to style the entire statement about commands but it also felt weird to not style it.  So this change explores an alternatively way of communicating the information.
2023-08-30 19:08:23 +00:00
Ed Page 0af2f65ce8 fix(resolver): Make resolver behavior independent of package order
This addresses the ordering issue of for one of the problems from #12599.

The intent behind the `path_pkg` check is to make sure we update
workspace members in the lockfile if their version number changed.
In this case, we don't need to recursively walk, because the change
doesn't affect dependencies.  However, we also shouldn't *prevent*
recursive walks which is what we are doing today, both for packages
marked to keep and for packages that have been "poisoned".  So we fix
this by moving that call after all recursive adds are complete so as to
not interfere with them.
2023-08-30 13:12:52 -05:00
Ed Page 2676a4ae79 test(update): Verify extra-update behavior 2023-08-30 13:07:15 -05:00
Ed Page 31e414cccb fix(help): Provide better commands heading for styling
In working on #12578, I felt it would be weird to style the entire
statement about commands but it also felt weird to not style it.  So
this change explores an alternatively way of communicating the
information.
2023-08-29 15:31:17 -05:00
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 c88137cd62 fix(pkgid): More consistently refer to SemVer 2023-08-29 10:49:09 -05:00
Ed Page 4238f689f5 fix(install): More consistently refer to SemVer 2023-08-29 10:49:02 -05:00
Ed Page 3d2f371737 test(pkgid): Add cases for partial versions 2023-08-29 10:40:47 -05:00
Ed Page 018b7589e8 test(pkgid): Focus tests on use cases, rather than success/failure
I assume the reason these aren't all individual tests is test-time but
if we divide by success/failure, I'll need to duplicate things to handle
partial versions.

Overall, I feel like this makes the tests make more sense.
2023-08-29 10:36:36 -05:00
Ed Page 3138f91d4d test(pkgid): Include test for ambiguous spec 2023-08-29 10:29:09 -05:00
Ed Page 82d78097c8 fix(update): Clarify meaning of --aggressive as --recursive
When working on cargo-upgrade, I found the meaning of `--aggressive`
confusing and named it `--recursive` there.

Renaming this in `cargo update` (with a backwards compatible alias) was
referenced in #12425.
2023-08-29 10:18:25 -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 &mdash; 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