19545 Commits

Author SHA1 Message Date
Eric Huss
767445df48 Backing up changelog 2025-01-28 18:53:21 -08:00
Eric Huss
19b5e2356c Move changelog to the cargo book
Due to rendering limits with GitHub's markdown renderer, we're moving
the changelog to the cargo book where it can be statically served under
our control.
2025-01-28 18:52:33 -08:00
Ed Page
26ce02737a
Conditionally mark the test cfg as a well known cfg (#15007)
### What does this PR try to resolve?

This PR conditionally mark the `test` cfg as a well known cfg depending
on the target unit "test" field (ie `lib.test = false`, `[[bin]] test =
false` and others).

This is related to https://github.com/rust-lang/rust/issues/117778 and
https://users.rust-lang.org/t/cargo-what-is-the-purpose-of-lib-test-false/102361.

When defining `lib.test = false` (and others), any use of `cfg(test)`
will trigger the `unexpected_cfgs` lint.
```toml
[lib]
test = false  # will now warn on cfg(test)
```

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

Best reviewed commit by commit. Second commit removes the `test` cfg
from the `--check-cfg` args.

### Additional information

T-compiler
[MCP#785](https://github.com/rust-lang/compiler-team/issues/785) and
https://github.com/rust-lang/cargo/pull/14963 were of preparatory work.

r? @epage
2025-01-28 19:55:00 +00:00
Eric Huss
730d9977f1
fix broken links in the Cargo book (#15109)
This PR closes #15102. I fixed broken links in the SUMMARY.md and
guide/index.md of the Cargo book.
2025-01-28 03:44:32 +00:00
Eric Huss
ba4d7869a6
Fix a typo and touch up documentation (#15108)
This PR closes #15101. I fixed a typo and touched up some sentences.
2025-01-28 03:43:31 +00:00
Eric Huss
f71f565bbd
Fix shared_std_dependency_rebuild running on Windows (#15111)
This fixes the `standard_lib::shared_std_dependency_rebuild` test while
running on Windows. On my system, `CARGO_MANIFEST_DIR` is a normal
windows-style path (`D:\rust\cargo`) with backslashes. That is not valid
TOML syntax. I don't know why this doesn't fail on CI (maybe CI sets a
unix-style current dir?).
2025-01-28 03:39:35 +00:00
Eric Huss
f62525d31b
Fix warnings on Windows (#15112)
This fixes some warnings that show up on Windows:

```
warning: unused variable: `path`
    --> tests\testsuite\registry.rs:3146:24
     |
3146 |     fn set_permissions(path: &Path, permissions: u32) {
     |                        ^^^^ help: if this is intentional, prefix it with an underscore: `_path`
     |
     = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `permissions`
    --> tests\testsuite\registry.rs:3146:37
     |
3146 |     fn set_permissions(path: &Path, permissions: u32) {
     |                                     ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_permissions`
```
2025-01-28 03:34:33 +00:00
yegeunyang
a9eec5cbb5 Fix a typo and touch up documentation 2025-01-27 19:14:24 -08:00
Eric Huss
7908e4210b Sync reference contents with SUMMARY.md 2025-01-27 19:12:01 -08:00
yegeunyang
8cd5cdf91e fix broken links in the Cargo book 2025-01-27 19:10:04 -08:00
Eric Huss
caff80d7f5 Fix shared_std_dependency_rebuild running on Windows 2025-01-27 19:06:22 -08:00
Eric Huss
e722344620 Fix warnings on Windows 2025-01-27 19:05:28 -08:00
Weihang Lo
9eda47ee04
fix(login): Deprecate CLI token (#15057)
### What does this PR try to resolve?

This came up in #13623 to avoid putting tokens into shell history.

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

The exact approach to deprecation can vary
- Include `<token>` in at least some docs for discovery (most likely the
man page)
- Don't warn yet

etc

I also suspect we could reorganize `cargo help login` but wanted to
decouple that from this change.

### Additional information
2025-01-28 02:53:08 +00:00
Eric Huss
fd4f492125
Update tests to fix nightly errors (#15110)
There were some changes in the latest nightly which is breaking some
tests:

* https://github.com/rust-lang/rust/pull/133154 updated the wording of a
message. I adjusted the test to be less sensitive to the exact wording.
* https://github.com/rust-lang/rust/pull/119286 added the
`linker-messages` lint which shows the output from the linker. Some of
our tests were passing dummy flags to the linker, which it was
complaining about. This updates it so that it uses real directories.
* This also fixes an incidental issue, where
`build_script_needed_for_host_and_target` was not testing for the
correct command-line flags. These got lost in
https://github.com/rust-lang/cargo/pull/14132.
2025-01-28 02:33:18 +00:00
Eric Huss
c35cb56d32 Update tests to deal with linker warnings
Nightly recently introduced the `linker-messages` lint which prints any
messages from linkers. These tests were triggering that lint because
they were passing missing directories to the linker. This fixes it by
creating empty directories to pass to the linker.

Note that this lint will be downgraded soon via
https://github.com/rust-lang/rust/pull/136098, but it seemed worthwhile
to fix the underlying problem.

This also fixes a problem where build_script_needed_for_host_and_target
was not testing for the correct command-line flags. These got lost
in https://github.com/rust-lang/cargo/pull/14132.
2025-01-26 13:25:17 -08:00
Eric Huss
2c6338b856 Update test message for E0433
The text of the message was changed in https://github.com/rust-lang/rust/pull/133154
2025-01-26 12:43:34 -08:00
Weihang Lo
e63457a4ce
Fix comment on Ord for SourceId (#15103)
### What does this PR try to resolve?

In PR #14980, the Ord impl for SourceId was changed, but the comment
wasn’t updated. So it is now incorrect.

This PR updates the comment to match the implementation.

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

Read the Ord for SourceId code and make sure the updated comment
describes what it does.

### Additional information

None
2025-01-25 20:35:24 +00:00
teor
6e46d4c862
Fix comment on Ord for SourceId 2025-01-26 05:58:00 +10:00
Weihang Lo
cecde95c11
Remove unused -C link-arg=-fuse-ld=lld (#15097)
That's a gcc flag. lld is a linker, not a C compiler, and doesn't accept
a `use-ld` flag. `-C linker=rust-lld` (which is already present in the
test) is enough.

This fixes the following warning found in rust-lang/rust#119286:
```
---- expected: tests\testsuite\freshness.rs:2822:27
++++ actual:   stderr
   1    1 | [FRESH] foo v0.1.0 ([ROOT]/foo)
        2 + [WARNING] linker stderr: rust-lld: ignoring unknown argument '-fuse-ld=lld'␍
        3 +   |
        4 +   = [NOTE] `#[warn(linker_messages)]` on by default
        5 +
        6 + [WARNING] `foo` (lib) generated 1 warning
   2    7 | [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
```

<!--
Thanks for submitting a pull request 🎉! Here are some tips for you:

* If this is your first contribution, read "Cargo Contribution Guide"
first:
  https://doc.crates.io/contrib/
* Run `cargo fmt --all` to format your code changes.
* Small commits and pull requests are always preferable and easy to
review.
* If your idea is large and needs feedback from the community, read how:
  https://doc.crates.io/contrib/process/#working-on-large-features
* Cargo takes care of compatibility. Read our design principles:
  https://doc.crates.io/contrib/design.html
* When changing help text of cargo commands, follow the steps to
generate docs:

https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages
* If your PR is not finished, set it as "draft" PR or add "WIP" in its
title.
* It's ok to use the CI resources to test your PR, but please don't
abuse them.

### What does this PR try to resolve?

Explain the motivation behind this change.
A clear overview along with an in-depth explanation are helpful.

You can use `Fixes #<issue number>` to associate this PR to an existing
issue.

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

Demonstrate how you test this change and guide reviewers through your
PR.
With a smooth review process, a pull request usually gets reviewed
quicker.

If you don't know how to write and run your tests, please read the
guide:
https://doc.crates.io/contrib/tests

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
-->
2025-01-24 17:15:24 +00:00
jyn
00d4e3d1ad Remove unused -C link-arg=-fuse-ld=lld
That's a gcc flag. lld is a linker, not a C compiler, and doesn't accept
a `use-ld` flag. `-C linker` (which is already present in the test) is
enough.

This fixes the following warning found in rust-lang/rust#119286:
```
---- expected: tests\testsuite\freshness.rs:2822:27
++++ actual:   stderr
   1    1 | [FRESH] foo v0.1.0 ([ROOT]/foo)
        2 + [WARNING] linker stderr: rust-lld: ignoring unknown argument '-fuse-ld=lld'␍
        3 +   |
        4 +   = [NOTE] `#[warn(linker_messages)]` on by default
        5 +
        6 + [WARNING] `foo` (lib) generated 1 warning
   2    7 | [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
```
2025-01-24 11:44:49 -05:00
Ed Page
86e83e8b38
Remove unsafe by using LazyLock (#15096)
There isn't a good reason to use unsafe code here, and as far as I know
`LazyLock` meets the MSRV of 1.82 as it was added in 1.80. Should have
no change to behavior.
2025-01-24 15:46:49 +00:00
anteater
8da5ba4f1c
Remove unsafe by using LazyLock 2025-01-24 15:14:15 +00:00
Ed Page
91d8140d66
Print globs when workspace members can't be found (#15093)
Cargo expands globs when loading workspace members. If the glob happens
to match some non-crate directory, it causes an error that may be tricky
to understand, because it makes Cargo complain that it failed to read a
`Cargo.toml` from a specific directory, but that directory name won't be
listed explicitly anywhere in `Cargo.toml`, so it may seem that Cargo is
trying to read some made-up phantom manifest.

I've made the error messages mention which glob has been used to select
the missing workspace member.
2025-01-23 21:13:33 +00:00
Kornel
9b3146432d Print globs when workspace members can't be found 2025-01-23 20:43:12 +00:00
Weihang Lo
53a2fdf0c0
Make --allow-dirty imply --allow-staged (#15013)
Staged changes don't really need protecting, and `--allow-dirty` is
stronger than `--allow-staged`, so it can imply `--allow-staged` to make
usage of `cargo fix` less verbose.

Closes #14176
2025-01-21 21:09:16 +00:00
Eric Huss
2668a4f936
fix(config): When merging, replace rather than combining specific configuration keys (#15066)
In general, Cargo merges lists in configuration by concatenating them.
However, sometimes the lists don't make sense for merging, such as a
program and its arguments. We had the `UnmergedStringList` type that
handled this case for merging environment variables, but it did not work
for multiple configs.

* Removes the `UnmergedStringList` type, which only worked for
preventing merging of environment variables with configuration.
* Adds a new function `is_nonmergable_list` which hard-codes which
configuration keys contain lists that should not be merged.

Fixes #14906
2025-01-21 16:32:27 +00:00
Arlo Siemsen
99c57c02d7 fix(config): Don't merge unmergable config 2025-01-20 15:20:27 -06:00
Arlo Siemsen
1948c90a78 Show existing behavior 2025-01-20 14:34:08 -06:00
Rustin170506
1514c7e630 test: add test for script as a dependency
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-01-20 21:53:15 +08:00
Rustin170506
95f6d0b2da feat: use full URL for embedded script paths
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-01-20 21:53:15 +08:00
Rustin170506
d4c1eeeaa0 refactor: use manifest path as the key
Signed-off-by: Rustin170506 <techregister@pm.me>

fix
2025-01-20 21:53:13 +08:00
Ed Page
045bf21b36
created a function for user defined aliases (#15076)
Hey there,

As mentioned in this
[issue](https://github.com/rust-lang/cargo/issues/14520), I worked on
the functionality of autocompleting the user-defined aliases and I moved
the code of user-defined aliases into a separate function by defining
two parameters. The first one is global context or gctx and the second
one is the commands that can be called in the list_commands function.

Thank you!

<!--
Thanks for submitting a pull request 🎉! Here are some tips for you:

* If this is your first contribution, read "Cargo Contribution Guide"
first:
  https://doc.crates.io/contrib/
* Run `cargo fmt --all` to format your code changes.
* Small commits and pull requests are always preferable and easy to
review.
* If your idea is large and needs feedback from the community, read how:
  https://doc.crates.io/contrib/process/#working-on-large-features
* Cargo takes care of compatibility. Read our design principles:
  https://doc.crates.io/contrib/design.html
* When changing help text of cargo commands, follow the steps to
generate docs:

https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages
* If your PR is not finished, set it as "draft" PR or add "WIP" in its
title.
* It's ok to use the CI resources to test your PR, but please don't
abuse them.

### What does this PR try to resolve?

Explain the motivation behind this change.
A clear overview along with an in-depth explanation are helpful.

You can use `Fixes #<issue number>` to associate this PR to an existing
issue.

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

Demonstrate how you test this change and guide reviewers through your
PR.
With a smooth review process, a pull request usually gets reviewed
quicker.

If you don't know how to write and run your tests, please read the
guide:
https://doc.crates.io/contrib/tests

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
-->
2025-01-17 14:59:36 +00:00
Bilal Khan
e01660d656 created a function for user defined aliases
removed the command parameter and returned it in order to extend the command with an alias
2025-01-17 11:08:03 +05:00
Ed Page
531215f6ac
took the functionality of the third party subcommand from the list_commands function (#15075)
Hey there,

I just moved the functionality of the third-party subcommand from the
[list_commands](https://github.com/rust-lang/cargo/blob/master/src/bin/cargo/main.rs#L184)
function to another new function by the name of third_party_subcommand
name and called that function in the list_commands function.

From my understanding regarding the third-party subcommand from this
[tracking issue](https://github.com/rust-lang/cargo/issues/14520),
following points should be performed.

- The code that gathers third-party subcommands in list_commands should
be moved into a separate function that I did.

- This new function will be called both by list_commands and the code
for adding subcommand completions. Although I called the function in the
list_commands but didn't understand the second point.

- Test the change that I made in the first place but it gave me this
error:

![carbon
(68)](https://github.com/user-attachments/assets/fb4c5a55-ea4b-4d22-b187-c2a417f5128d)

<!--
Thanks for submitting a pull request 🎉! Here are some tips for you:

* If this is your first contribution, read "Cargo Contribution Guide"
first:
  https://doc.crates.io/contrib/
* Run `cargo fmt --all` to format your code changes.
* Small commits and pull requests are always preferable and easy to
review.
* If your idea is large and needs feedback from the community, read how:
  https://doc.crates.io/contrib/process/#working-on-large-features
* Cargo takes care of compatibility. Read our design principles:
  https://doc.crates.io/contrib/design.html
* When changing help text of cargo commands, follow the steps to
generate docs:

https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages
* If your PR is not finished, set it as "draft" PR or add "WIP" in its
title.
* It's ok to use the CI resources to test your PR, but please don't
abuse them.

### What does this PR try to resolve?

Explain the motivation behind this change.
A clear overview along with an in-depth explanation are helpful.

You can use `Fixes #<issue number>` to associate this PR to an existing
issue.

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

Demonstrate how you test this change and guide reviewers through your
PR.
With a smooth review process, a pull request usually gets reviewed
quicker.

If you don't know how to write and run your tests, please read the
guide:
https://doc.crates.io/contrib/tests

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
-->
2025-01-16 23:18:38 +00:00
Bilal Khan
ea83afd783 took the functionality of the third party subcommand from the list_commands function
corrected the formatting
2025-01-17 03:48:38 +05:00
Ed Page
dc0d02a1fc
fix: wrong concat and field name (#15074)
### What does this PR try to resolve?

Fixes a wrong concatenation in macro, and one wrong field name.

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

`cargo doc --document-private-items --no-deps --open`
2025-01-16 20:22:34 +00:00
Weihang Lo
e2f85e1c8c
fix: wrong concat and typos 2025-01-16 14:46:41 -05:00
Weihang Lo
150bbc4d50
fix(publish): Report all unpublishable packages (#15070)
### What does this PR try to resolve?
I didn't extend this to multiple packages restricted to specific
registries.
It seems less likely to be a problem and more complex to gather and
report.

This was inspired by feedback left at #10948

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

### Additional information
2025-01-16 13:44:50 +00:00
Weihang Lo
1177d2a230
docs(cargo-clippy): correct typo (#15072)
Fix typo in command docs for `cargo-clippy`. The command is
`cargo-clippy` not `cargo-miri`!
2025-01-16 13:23:48 +00:00
overlookmotel
7b7661941f docs(cargo-clippy): correct typo 2025-01-16 11:23:55 +00:00
Ed Page
1eafdb2656 fix(publish): Report all unpublishable packages
I didn't extend this to multiple packages restricted to specific
registries.
It seems less likely to be a problem and more complex to gather and
report.

This was inspired by feedback left at #10948
2025-01-15 20:24:52 -06:00
Ed Page
a282233ae4 test(publish): Check with multiple unpublishable packages 2025-01-15 20:23:19 -06:00
Ed Page
d54c5d404a
docs(cargo-package): alwasy include the lockfile (#15067)
### What does this PR try to resolve?

This was overlooked in #14815.

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

```
cargo build
target/debug/cargo help package
# and read the manpage
```
2025-01-16 01:49:03 +00:00
Weihang Lo
662394e10f
docs(cargo-package): alwasy include the lockfile
This was overlooked in #14815.
2025-01-15 20:18:08 -05:00
Weihang Lo
2909c013ea
docs(ref): Deprecate 'package.authors' (#15068)
### What does this PR try to resolve?

This was left as a future-possibility in
[RFC
#3052](https://rust-lang.github.io/rfcs/3052-optional-authors-field.html).
Without a clear role for this field within Cargo/crates.io,
there seems little reason to actively support it (e.g. #14949, #15027),
including working through feature requests.
I see the potential for having some fields with more specific roles
(where to go for support, where to go for disclosing vulnerabilities,
etc)
but even these run into the mutable data problem of `authors`.
Users can always manage metadata for their own purposes through
`package.metadata`.

The RFC called out clap as an example of something that uses this.
Clap no longer does by default but users can opt-in through a
`help_template`.

For now, this notes the status in the documentation.
When we have[user control over Cargo lint (#12235)
(and figure out namespacing with lints that overlap with Rust),
we can give a warning on this.
Based on feedback from users, we can evaluate removing this field in a
future edition.

This is as discussed in a recent Cargo team meeting

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

### Additional information

We may want to consider doing similar for `badges`
2025-01-16 00:42:57 +00:00
Ed Page
149aa21df0
fix(build-std): parse as comma-separated list (#15065)
### What does this PR try to resolve?

Restore to the behavior prior to
30d11ce1d9f06907d1e707c4fe379ebf57305a5e
Also extend `build-std-features` to support comma-separated list.

Fixes #15064

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

A test has been added.
2025-01-15 23:39:25 +00:00
Weihang Lo
93c764d805 fix(build-std): parse as comma-separated list
Restore to the behavior prior to 30d11ce1d9f06907d1e707c4fe379ebf57305a5e
Also extend `build-std-features` to support comma-separated list.
2025-01-15 15:09:19 -08:00
Weihang Lo
ffe841c540 test: verify how build-std flag be deserialized now
It doesn't parse as comma-separated list.
It did before #14899
2025-01-15 15:09:19 -08:00
Weihang Lo
ac22fd3d2d
Fix benchsuite issue with newer versions of git (#15069)
This fixes a problem introduced with git 2.48.0 where the benchsuite
would fail to run. The problem is that 2.48 changed the behavior so that
HEAD would get changed to follow the remote. crates.io-index's default
branch is "main". The benchsuite uses git to initialize the bare repo
with a HEAD of "refs/heads/master" (the default of
`init.defaultBranch`). Older versions of git would leave HEAD untouched,
but newer versions update it to "refs/heads/main" after fetching to
match the remote. This causes cargo to try to clone a branch called
"main" which is empty.

The solution here is to just force HEAD to be main, and use that as the
branch for our time-travelling snapshot.

Tested with git 2.47.0 and 2.48.1. Test is roughly:

```
rm -rf target/tmp/bench ; cargo test -p benchsuite --all-targets -- cargo && cargo test -p benchsuite --all-targets -- cargo`
```

(Run it twice to verify it can do an incremental fetch.)
2025-01-15 22:16:56 +00:00
Eric Huss
5ac521c649 Fix benchsuite issue with newer versions of git 2025-01-15 13:43:53 -08:00