20211 Commits

Author SHA1 Message Date
Weihang Lo
f1193861a3
Remove double reference in Shell::print_json (#15460)
`obj` is already `&T`.

<!--
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-06-03 13:42:01 +00:00
A4-Tacks
b066b7848a
Add --offline for comp 2025-06-03 14:20:52 +08:00
Ed Page
f6bebc3abb
fix(trim-paths): remap all paths to build.build-dir (#15614)
### What does this PR try to resolve?

Remap all paths pointing to `build.build-dir`,
i.e., `[BUILD_DIR]/debug/deps/foo-[HASH].dwo` would be remapped to
`/cargo/build-dir/debug/deps/foo-[HASH].dwo`
(note the `/cargo/build-dir` prefix).

This covers scenarios like:

* Build script generated code. For example, a build script may call
`file!`
macros, and the associated crate uses `include!` to include the expanded
  `file!` macro in-place via the `OUT_DIR` environment.
* On Linux, `DW_AT_GNU_dwo_name` that contains paths to split debuginfo
  files (dwp and dwo).

### How to test and review this PR?

Should be quite straightforward.

The open question is what we want to remap _to_, to help debugger to
find the source files.
cc #12137 and #13171
2025-06-02 19:04:43 +00:00
Weihang Lo
281629bd2b
fix(trim-paths): remap all paths to build.build-dir
Remap all paths pointing to `build.build-dir`,
i.e., `[BUILD_DIR]/debug/deps/foo-[HASH].dwo` would be remapped to
`/cargo/build-dir/debug/deps/foo-[HASH].dwo`
(note the `/cargo/build-dir` prefix).

This covers scenarios like:

* Build script generated code. For example, a build script may call `file!`
  macros, and the associated crate uses [`include!`] to include the expanded
  [`file!`] macro in-place via the `OUT_DIR` environment.
* On Linux, `DW_AT_GNU_dwo_name` that contains paths to split debuginfo
  files (dwp and dwo).
2025-06-02 14:26:36 -04:00
Weihang Lo
463e9ed3cd
test(trim-paths): not remapped in build script gen'd code
This was discovered in
<https://github.com/rust-lang/rust/issues/111540#issuecomment-2544049895>.

Co-authored-by: Urgau <urgau@numericable.fr>
2025-06-02 14:26:35 -04:00
Weihang Lo
56a1118e52
test(trim-paths): match the actual sanitized paths
The old wildcard matched too much and didn't really
show whether the paths were sanitized.
2025-06-02 14:26:35 -04:00
Weihang Lo
d8ac8dd2e5
test(trim-paths): re-enable more symbols trimming check
rust-lang/rust#117652 has been fixed.
2025-06-02 14:26:35 -04:00
Ed Page
b646f83935
test(trim-paths): enable more tests for windows-msvc (#15621)
### What does this PR try to resolve?

Before this some end-to-end tests didn't cover Windows platforms.

After this, we cover windows-msvc for

* End-to-end debugger tests.
* Check path is trimmed with symbol viewers like `strings`.

windows-gnu isn't covered

### How to test and review this PR?

There are things needing attentions:

* This adds a new CI job for window-msvc "nightly" toolchain.
* In 2f923b3ff25f847d we don't check if an executable's availability by
running `<cmd> --version`. Instead, we check the file execute bit.
* Enabled windows-msvc tests rely on the software provided by [GitHub
windows runner
image](e330e24b7e/images/windows/Windows2022-Readme.md)
  * Windows SDK which provides cdb and other debugger tools
  * `strings` is provided by MinGW.
2025-06-02 17:17:38 +00:00
Weihang Lo
120ad80c57
fix(fingerprint): explicit reason rather than "stale; unknown reason" (#15617)
### What does this PR try to resolve?

This was discovered during playing with rmeta reuse between cargo-check
and cargo-build.

An rmeta mtime failure is basically the same as "failed to read
metadata".

While we don't report in tracing log, that should be fine because dirty
reason will be reported in the other place.

### How to test and review this PR?

Should have no real user-facing behavior change.
2025-06-02 16:51:33 +00:00
Weihang Lo
4e507121a0
test(trim-paths): verify trim-paths=object works on windows-msvc 2025-06-02 08:10:24 -04:00
Weihang Lo
11e40ae867
test(trim-paths): verify Windows cdb works after trimmed
GitHub Actions has Windows SDK pre-installed,
so cdb should be available at that path always.

Additionally, this adds a new CI job for windows-msvc nightly toolchain
2025-06-02 08:10:24 -04:00
Weihang Lo
cf87e117ae
fix(test-support): check executability instead of running --version
Not every executable has a `--version` flag.
Let's check the exectuability instead.

Note that on Windows we check if it is file only.
There is a `is_executable` crate on crates.io,
though that still depend on winapi so don't bother using it.
2025-06-02 08:10:24 -04:00
Weihang Lo
d7940042bd
Fix cargo add overwriting symlinked Cargo.toml files (#15281)
### What does this PR try to resolve?

This PR fixes a bug where `cargo add` breaks symlinks to Cargo.toml
files. Currently, when Cargo.toml is a symlink and `cargo add` is used
to add a dependency, the symlink is replaced with a regular file,
breaking the link to the original target file.

This issue was reported in #15241 where a user who relies on symlinked
Cargo.toml files found that `cargo add` breaks their workflow.

Fixes #15241

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

I've modified `LocalManifest::write()` to check if the path is a
symlink, and if so, follow it to get the actual target path. This
ensures we write to the actual file rather than replacing the symlink.

I've also added a test in `tests/testsuite/cargo_add/symlink.rs` that:
1. Creates a symlinked Cargo.toml file
2. Runs `cargo add` to add a dependency
3. Verifies the symlink is preserved and the dependency is added to the
target file

I've manually tested this fix and confirmed it works correctly.
2025-06-02 10:23:52 +00:00
Raghavender Singh
ecfe3a961d fix: handle symlinks properly in write_atomic
- Preserve symlinks when writing files atomically in write_atomic()
- Update test to verify correct symlink preservation behavior
- Apply rustfmt formatting

This fixes the issue where cargo add would replace symlinked Cargo.toml
files with regular files, breaking the symlink to the original target.

Fixes #15241
2025-06-02 10:26:42 +05:30
Weihang Lo
21a67e29e6
chore(deps): update alpine docker tag to v3.22 (#15616)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| alpine | final | minor | `3.21` -> `3.22` |

---

### Configuration

📅 **Schedule**: Branch creation - "before 5am on the first day of the
month" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/rust-lang/cargo).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC4zMy42IiwidXBkYXRlZEluVmVyIjoiNDAuMzMuNiIsInRhcmdldEJyYW5jaCI6Im1hc3RlciIsImxhYmVscyI6W119-->
2025-06-01 14:04:39 +00:00
Weihang Lo
c6f5f3fcae
fix(fingerprint): explicit reason than "stale; unknown reason"
This was discovered during playing with rmeta reuse
between cargo-check and cargo-build
2025-05-31 21:17:59 -04:00
renovate[bot]
bf7ac6563f
chore(deps): update alpine docker tag to v3.22 2025-06-01 00:50:52 +00:00
Ed Page
64a1246070
chore: remove HTML comments and inline guide (#15613)
### What does this PR try to resolve?

The HTML comments in the PR template, after this repo migrated to GitHub
merge queue, often show up in the merge commit message when people
forgot to delete it.

This PR removes those, as they are only important for people never look
at the contributor guide. We keep one link to the guide though at the
top of the template.

It also moves the entire template out of HTML comments, so it is more
obvious for maintainers to see what will be in the merge commit message.

The “Additional information” paragraph is removed, as I observed it is
seldom used.

### How to test and review this PR?

Copy and paste the PR template into the PR description preview, and see
if it satisfies your eyes.
2025-05-30 18:25:08 +00:00
Weihang Lo
a5a9efcf72
chore: remove HTML comments and inline guide
Also make template lighter.

See
https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/pr.20template/with/521309075
2025-05-30 13:55:31 -04:00
Ed Page
2744aa9c82
Add .git-blame-ignore-revs (#15612)
This adds a file to ignore most formatting commits in `git blame`. These
commits usually are not interesting, and being able to skip them makes
it a little easier to traverse a blame history. This is a feature
natively supported by GitHub automatically to ignore these. When running
locally, you need to first configure git to use it.

I was a little on the fence on which PRs to include here. Many of these
are small and probably not too important. However, instead of trying to
figure out some threshold of "is this large enough", I decided to just
include all of them.

I checked these by visually looking at each commit and briefly checking
that it didn't seem to include any non-formatting changes.

I think it would be nice to try to keep commits a little cleaner in the
future, and avoid merging PRs that have things like this (unless it is
due to a change in rustfmt itself). I admit I don't always enforce it
since it can be a significant drag, though.
2025-05-30 15:31:17 +00:00
Eric Huss
e1658633ab
refactor: cleanup for CompileMode (#15608)
### What does this PR try to resolve?

Some more cleanup after #15601

See each commit message for details.

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

Help review whether it has really no behavior change.
2025-05-30 14:57:23 +00:00
Eric Huss
75d712a323 Add .git-blame-ignore-revs
This adds a file to ignore most formatting commits in `git blame`. These
commits usually are not interesting, and being able to skip them makes
it a little easier to traverse a blame history. This is a feature
natively supported by GitHub automatically to ignore these. When running
locally, you need to first configure git to use it.

I was a little on the fence on which PRs to include here. Many of these
are small and probably not too important. However, instead of trying to
figure out some threshold of "is this large enough", I decided to just
include all of them.

I checked these by visually looking at each commit and briefly checking
that it didn't seem to include any non-formatting changes.

I think it would be nice to try to keep commits a little cleaner in the
future, and avoid merging PRs that have things like this (unless it is
due to a change in rustfmt itself). I admit I don't always enforce it
since it can be a significant drag, though.
2025-05-30 07:50:37 -07:00
Weihang Lo
8a388b0392
test(test): ensure panic=abort not added to default example inclusion
`cargo test` will implicitly build examples as examples binaries
(without --test) by default, when no target selection flags provided.
We don't have test exercising this, so add one.
2025-05-29 20:45:47 -04:00
Raghavender Singh
35d2a30a5c test: Add test demonstrating cargo add replaces symlinks
This test shows the current behavior where cargo add replaces
symlinked Cargo.toml files with regular files. The test passes,
documenting this problematic behavior.
2025-05-30 00:25:18 +05:30
Weihang Lo
d0cbbac2b3
refactor: remove fields in CompileMode::Doc
They are globally determined at Cargo invocation level,
and can all be derived from `UserIntent`.
2025-05-29 09:29:25 -04:00
Weihang Lo
5fb96e85bc
refactor: remove unreachable match arms for tests/benches
To justify why it won't affect any existing behavior:

* For the default set of Cargo targets,
  test/bench targets would only be selected by `cargo test`,
  whose UserIntent will turn into `CompileMode::Test`,
  but never `CompileMode::Build`.

* For selective Cargo targets, i.e., `--tests`, or `--test`,
  Their `CompileMode` would either be `Check { test }` or `Test`.
  They will never be `Build`.
  See https://github.com/rust-lang/cargo/blob/bffece899e9/src/cargo/ops/cargo_compile/unit_generator.rs#L450-L465

According to these facts, there won't be a case that
bench/test targets get assigned to `CompileMode::Build`.
2025-05-29 08:51:33 -04:00
Weihang Lo
bef07b2de1
docs: fix typo 2025-05-29 08:37:46 -04:00
Eric Huss
bffece899e
refactor: separate "global" mode from CompileMode (#15601)
### What does this PR try to resolve?

This separates the concern of two different "mode".

- UserIntent: focus on the overall goal of the build
- CompileMode: the actual compile operation for each unit (I'd like to
rename it to something else in the future, such as CompileAction)

This is a preparation of adding `-Zno-link`/`-Zlink-only` support,
which we'll have `CompileMode::Link` but that doesn't make sense to
show up in `UserIntent`.

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

It should have no functional change.

### Additional information
2025-05-28 23:50:22 +00:00
Ed Page
36daa739ca
fix(doc): pass toolchain-shared-resources to get doc styled (#15605)
### What does this PR try to resolve?

Fixes #15604

rustdoc assumes to add static files only when the
toolchain-shared-resources emit-type is specified, or when no emit-type
is specified.

See
80c34983c6/src/librustdoc/html/render/write_shared.rs (L206-L213)

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

Not going to write a test because I don't think we want to inspect into
how rustdoc arranges static files.

See #15604 for how to reproduce/test.

### Additional information

cc #15370
2025-05-28 21:03:49 +00:00
Weihang Lo
6abe54c653
fix(rustdoc-depinfo): pass also toolchain-shared-resources to get doc styled
rustdoc assumes to add static files only when the
toolchain-shared-resources emit-type is specified,
or when no emit-type is specified.

See
80c34983c6/src/librustdoc/html/render/write_shared.rs (L206-L213)
2025-05-28 16:29:55 -04:00
Weihang Lo
c8d15a37e3
fix(embedded): Resolve multiple bugs in frontmatter parser (#15573)
### What does this PR try to resolve?

This pulls in the tests from rust-lang/rust#140035 and ensures we pass
them, including switching our parser to be more like the one from
rust-lang/rust#137193.

I've added comments specifying why our test results differ from rustcs.

This is part of #12207

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

### Additional information

We still have work to do to improve the quality of our error messages
2025-05-27 20:13:03 +00:00
Weihang Lo
310e4f36fc
chore: Upgrade schemars (#15602)
### What does this PR try to resolve?

0.9.0 may look like a downgrade but the maintainer has decided to go
  back to `0.x` versions rather than continuing to use pre-release
versions

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

### Additional information
2025-05-27 20:01:20 +00:00
Ed Page
92cb7b9a60 chore: Upgrade schemars
0.9.0 may look like a downgrade but the maintainer has decided to go
  back to `0.x` versions rather than continuing to use pre-release
versions
2025-05-27 12:34:14 -05:00
Weihang Lo
2fc7e6ed86
refactor: remove unsed Bench mode
The purpose of it was for indicating old "global mode".
There should be no difference between building a test or a bench,
as we already coerce Bench to Test:
https://github.com/rust-lang/cargo/blob/6ffc01f9fa7aa50d0/src/cargo/ops/cargo_compile/unit_generator.rs#L91-L99

The the removal of serialization for `CompileMode::Bench` affects
nothing because it was never really constructed.
2025-05-27 11:49:19 -04:00
Weihang Lo
2bab011078
refactor: separate "global" mode from CompileMode
This separates the concern of two different "mode".

- UserIntent: focus on the overall goal of the build
- CompileMode: the actual compile operation for each unit

This is a preparation of adding `-Zno-link`/`-Zlink-only` support,
which we'll have `CompileMode::Link` but that doesn't make sense to
show up in `UserIntent`.
2025-05-27 11:48:30 -04:00
Weihang Lo
a9e8aa2c65
Update gix & socket2 (#15600)
Closes #15442
Closes #15468
Closes #15469

r? @weihanglo

cc @jeremyd2019
2025-05-26 16:10:58 +00:00
王宇逸
bb62903ad7 Update gix & socket2 2025-05-26 21:42:47 +08:00
Weihang Lo
6ffc01f9fa
Add -Zfix-edition (#15596)
This adds a new `cargo fix -Zfix-edition` permanently unstable flag to
assist with edition migration testing, particularly with crater.

The commits and given documentation should explain how it works, but
there will be forthcoming edition documentation (on the forge) once all
the pieces with crater come together.
2025-05-26 11:57:32 +00:00
Eric Huss
21629670f4 Implement -Zfix-edition
This adds the implementation for the behavior of `cargo fix
-Zfix-edition`.
2025-05-25 08:24:09 -07:00
Eric Huss
331dcec02d Add EditionFixMode
This adds the `EditionFixMode` enum to control the behavior of
`cargo fix --edition`. The main intent is to provide a way to force
`cargo fix` to migrate to a specific edition, instead of just going to
the "next".

This will be needed for `-Zfix-edition` in order to force it to use the
"future" edition, which is never the "next" edition.

This requires being able to serialize and deserialize this setting as it
is conveyed through an environment variable to the recursive cargo
invocation.
2025-05-25 08:18:41 -07:00
Eric Huss
9d93b42c4c Add the -Zfix-edition flag
This adds support for parsing the `-Zfix-edition` flag.
2025-05-25 08:18:41 -07:00
Eric Huss
778ff6885a Factor out workspace reloading
This factors out the code to reload a workspace since I will be needing
to reuse this elsewhere.

There is some risk with this method not getting updated correctly in the
future as new fields are added to Workspace (and it may be missing some
things now), but that is an issue with the existing code.
2025-05-25 08:18:41 -07:00
Weihang Lo
8d17219da9
chore(toml): disable toml's default features, unless necessary (#15598)
### What does this PR try to resolve?

This reduces the build time of `cargo-util-schemas` by disabling the
unused `display` and `parse` features of `toml` (which are enabled by
default).

This is useful as `cargo-util-schemas` is intended to be reused outside
of Cargo.

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

As I believe these features only *feature-gate* items on `toml` (they do
not affect runtime behavior silently), the CI building successfully
should be enough to make sure this does not break anything. ~If this
does not build, I will try to tend to it today, otherwise feel free to
push to this branch.~
2025-05-25 14:46:55 +00:00
AudaciousAxiom
8362109b8e chore(toml): disable toml's default features, unless necessary
This reduces the build time of `cargo-util-schemas`.
2025-05-25 13:31:18 +02:00
Weihang Lo
4aa973480b
docs(README): fix the link to the changelog in the Cargo book (#15597)
<!--
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.
-->
### What does this PR try to resolve?

When Cargo's changelog was moved into the book in #15123, it seems the
extension was left as `.md`, whereas the link should point to the
rendered version, which ends with `.html`.

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

Following the new link in the README's rendered view and observing that
it does indeed point to the changelog should be enough.
2025-05-25 10:42:48 +00:00
AudaciousAxiom
2243b6d5b6
docs(README): fix the link to the changelog in the Cargo book 2025-05-25 10:05:19 +00:00
Weihang Lo
f19321e343
Add the future edition (#15595)
This adds support for the "future" edition which was added to rustc in
https://github.com/rust-lang/rust/pull/137606.

To enable support for unstable editions, this introduces a new
`unstable-editions` cargo feature. The intent is that instead of having
a new feature for each edition that we reuse this feature for all new
editions. I don't see a particular reason we should have a separate one
for each edition, and this helps a bit with scalability and simplifies
some of the edition process.

This also includes a change to rework `supports_compat_lint` explained
in the comment.
2025-05-25 01:06:12 +00:00
Eric Huss
5f5ad05d80 Add the future edition
This adds support for the "future" edition which was added to rustc in
https://github.com/rust-lang/rust/pull/137606.

To enable support for unstable editions, this introduces a new
`unstable-editions` cargo feature. The intent is that instead of having
a new feature for each edition that we reuse this feature for all new
editions. I don't see a particular reason we should have a separate one
for each edition, and this helps a bit with scalability and simplifies
some of the edition process.

This also includes a change to rework `supports_compat_lint` explained
in the comment.
2025-05-24 17:36:32 -07:00
Weihang Lo
68db37499f
chore(gh): Add new-lint issue template (#15575)
### What does this PR try to resolve?

We aren't quite ready for writing lints (waiting on an annotate-snippets
release) but I wanted to start recording some lint ideas I had.

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

Based on clippy's which I assumed would be a good starting point. There
are more area we'll need to fill out during discussion, like the lint
name, what primary group the lint would be in, etc.

### Additional information
2025-05-22 14:27:15 +00:00
Ed Page
5661fb89c1 chore(gh): Add new-lint template
Based on clippy's
2025-05-22 08:42:14 -05:00