Commit Graph

10761 Commits

Author SHA1 Message Date
bors 7ebc065673 Auto merge of #13571 - Urgau:stabilize-check-cfg, r=weihanglo
Stabilize `-Zcheck-cfg` as always enabled

This PR stabilize the `-Zcheck-cfg` option as always enabled.

~~Waiting on https://github.com/rust-lang/rust/issues/82450#issuecomment-1965328542 to complete, but is otherwise ready to be reviewed (in particular the documentation changes).~~ (https://github.com/rust-lang/rust/pull/123501)

Fixes https://github.com/rust-lang/cargo/issues/10554
2024-05-03 15:38:39 +00:00
bors cf7b3c4cf3 Auto merge of #13852 - Muscraft:revert-seperating-lints, r=epage
fix(lints): Prevent inheritance from bring exposed for published packages

#13843 demonstrated a regression caused by #13801, where we started to keep `[lints]` and `[workspace.lints]` separate, and not truly resolve `[lints]`. This was a nice thing to have and made it easier to tell when a lint came from a workspace. The downside of doing so is the lints table would not get resolved when vendoring or publishing.

To fix this issue, I reverted the change for keeping `[lints]` and `[workspace.lints]` separate and modified how cargo's linting system figures out where a lint is coming from. Due to this change, we no longer specify that a lint was set by `[workspace.lints]`, only `[lints]`. It is true that a lint level is set by `[lints]` always, as it would've had to specify the lint outright or specify that it was inheriting it, seeing that, I do not think this is a regression in diagnostic quality. I still manage to keep the ability to render a lint's location in the workspace's manifest when running ` analyze_cargo_lints_table`, which I am pleased about.
2024-05-03 00:49:36 +00:00
Scott Schafer 6c2334613c
fix(lints): Prevent inheritance from bring exposed for published packages 2024-05-02 15:37:53 -06:00
bors 9e57a8d830 Auto merge of #13849 - epage:no-infer, r=weihanglo
perf(toml): Avoid inferring when targets are known

### What does this PR try to resolve?

We read the file system to infer two different data points
- Implicit targets
- Implicit `path` values for targets

I took a shortcut for this case and recognize the scenario where we can
bypass both and do so.
I went with a bypass, rather than this being integrating into the
inferring code because the inferring code is complex and I didn't want
to add to it further in isolating the inferring to only when its needed.

The validation gets duplicated because having it in the middle of the resolve code provides a better user experience and it would be messy to add the conditionals to get all of that working.  I at least worked to keep the duplicated validation close to each other.

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

### Additional information
2024-05-02 19:41:57 +00:00
Eddie Webbinaro e62ef14fd8
Update continuous-integration.md: Include CircleCI reference
Adds simple example to run `cargo test` on CircleCI
2024-05-02 12:30:59 -04:00
bors 27d3e3d603 Auto merge of #13818 - osiewicz:clean-package-perf-improvements, r=weihanglo
Clean package perf improvements

### What does this PR try to resolve?

I've noticed that `cargo clean -p` execution time scales poorly with size of target directory; in my case (~250GB target directory on M1 Mac) running `cargo clean -p` takes circa 35 seconds. Notably, it's the file listing that takes that time, not deleting the package itself. That is, when running `cargo clean -p SOME_PACKAGE` twice in a row, both executions take roughly the same time.

I've tracked it down to the fact that we seem quite happy to use `glob::glob` function, which iterates over contents of target dir. It also was a bit sub-optimal when it came to doing that, for which I've already filled a PR in https://github.com/rust-lang/glob/pull/144 - that PR alone takes down cleaning time down to ~14 seconds. While it is a good improvement for a relatively straightforward change, this PR tries to take it even further. With glob PR applied + changes from this PR, my test case goes down to ~6 seconds. I'm pretty sure that we could squeeze this further, but I'd rather do so in a follow-up PR.

Notably, this PR doesn't help with *just* super-large target directories. `cargo clean -p serde` on cargo repo (with ~7Gb target directory size) went down from ~380ms to ~100ms for me. Not too shabby.

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

I've mostly tested it manually, running `cargo clean` against multiple different repos.

### Additional information
TODO:
- [x] [c770700](c770700885) is not quite correct; we need to consider that it changes how progress reporting works; as is, we're gonna report all progress relatively quickly and stall at the end (when we're actually iterating over directories, globbing, removing files, that kind of jazz). I'll address that.
2024-05-02 13:59:32 +00:00
Piotr Osiewicz 9c1139ec72 feedback: rewrite doc comment for rm_rf_prefix_list 2024-05-02 12:37:25 +02:00
Piotr Osiewicz 574d086cb3 fixup! Update src/cargo/ops/cargo_clean.rs 2024-05-02 12:30:38 +02:00
Piotr Osiewicz a49a2b9584
Update src/cargo/ops/cargo_clean.rs
Change Rc<str> to &str

Co-authored-by: Weihang Lo <weihanglo@users.noreply.github.com>
2024-05-02 12:29:28 +02:00
Ed Page f5892f210e perf(toml): Avoid inferring when targets are known
We read the file system to infer two different data points
- Implicit targets
- Implicit `path` values for targets

I took a shortcut for this case and recognize the scenario where we can
bypass both and do so.
I went with a bypass, rather than this being integrating into the
inferring code because the inferring code is complex and I didn't want
to add to it further in isolating the inferring to only when its needed.
2024-05-01 19:42:19 -05:00
Ed Page 3740bbb36c refactor(toml): Defer inferred discovery 2024-05-01 19:42:19 -05:00
Ed Page cdae596394 refactor(toml): Consistently document motivation for validation order 2024-05-01 19:42:02 -05:00
Ed Page fe0819ee9e fix(toml): Validate crates_types/proc-macro for bin like others
Turns out, we allow these fields, just in limited ways, so we need to be
consistent.

I limited when this applies to reduce noise from the user solving there
problem because they are unlikely to keep the field and switch it to the
opposite value
2024-05-01 19:36:30 -05:00
Urgau 60a5026885 Adjust documentation for newly stabilized -Zcheck-cfg 2024-05-01 12:56:04 +02:00
Urgau a5669e8fa3 Stabilize -Zcheck-cfg as always enabled-by-default 2024-04-30 23:00:43 +02:00
bors 05066fe989 Auto merge of #13831 - weihanglo:typos, r=Muscraft
docs: fix several typos found by `typos-cli`
2024-04-30 04:17:19 +00:00
Weihang Lo 7a33639876
docs: doc comments typo fixes 2024-04-29 23:08:14 -04:00
Weihang Lo 16bc8720b7
docs(man): typo fixes 2024-04-29 23:07:44 -04:00
bors c10b6d39ad Auto merge of #13819 - heisen-li:alias, r=weihanglo
fix(alias): Aliases without subcommands should not panic

### What does this PR try to resolve?

Fixes #13814
2024-04-30 02:56:46 +00:00
heisen-li 45851ef31e fix(alias): Aliases without subcommands should not panic 2024-04-30 09:30:22 +08:00
Piotr Osiewicz 634dca4ddd Clean up commentary for new code 2024-04-30 00:44:17 +02:00
Piotr Osiewicz d33ef8fbe7 Treat calls to rm_rf_prefix_list as idempotent
Starting with this commit we deduplicate calls to rm_rf_prefix_list by crate name and not by directory; this can lead to more calls to rm_rf_prefix_list (especially in presence of multiple -p arguments),
but it is also more transparent in terms of progress reporting (we're just storing away whether a given directory + glob pair has already been removed)
2024-04-30 00:26:51 +02:00
Ed Page a226ce1719 fix(toml): Improve granularity of traces 2024-04-29 16:46:41 -05:00
Ed Page 72b170e7e1 refactor(toml): Group related validation functions 2024-04-29 14:56:24 -05:00
Ed Page 640d41d641 refactor(toml): Validate bin in resolve, like other targets 2024-04-29 14:55:42 -05:00
Ed Page 330d5ea93a refactor(toml): Pull bin proc-macro validation out 2024-04-29 14:55:41 -05:00
Ed Page f71515698e refactor(toml): Pull bin crate-types validation out 2024-04-29 14:54:52 -05:00
bors d34d0a1e15 Auto merge of #13839 - epage:df_2024, r=Muscraft
fix(toml): On 2024 Edition, disallow ignored `default-features` when inheriting

### What does this PR try to resolve?

This is part of rust-lang/rust#123754

This is a follow up to #11409 which tweaked how we do inheritance of default-features, including warning when `default-features = false` is ignored.  This turns those warnings into an error.

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

### Additional information
2024-05-01 22:06:45 +00:00
bors bbea43745c Auto merge of #13837 - Muscraft:only-underscores-lint-names, r=epage
fix(lints): Remove ability to specify `-` in lint name

In a recent Cargo Team meeting, it was discussed whether our lint should use `-` or `_` and if we should rewrite the wrong form to the correct one. It was decided that Cargo would use `_` for lint names and would not convert `-` to `_` automatically; instead, we would warn about an "unknown lint" and mention the similarly named lint with `_`, if found.

The decision to ise `_` was made because it is the canonical representation, as well as [RFC #344](https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints) specifies:
> Use snake case in the same way you would for function names.

This PR implements these changes.

Note: This adds an `unknown_lints` lint, that tries to mirror [the lint `rustc` has with the same name](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#unknown-lints).
2024-05-01 20:31:49 +00:00
Ed Page 627b1d1470 feat(fix): Migrate inherited deps with ignored default-features 2024-05-01 12:43:47 -05:00
Ed Page 5965c15179 fix(toml): Disallow ignored default-features when inheriting 2024-05-01 12:04:07 -05:00
Ed Page 656107a173 refactor(toml): Allow adding errors to ws dep inheritance 2024-05-01 12:04:07 -05:00
Ed Page 7f2c7061f1 refactor(toml): Move the ws default features function out 2024-05-01 12:04:07 -05:00
Ed Page 738cdeca8b refactor(toml): Clarify what the ws default features function does 2024-05-01 12:04:07 -05:00
bors 82dca28700 Auto merge of #13791 - epage:msrv-unset, r=Eh2406
fix(resolver): Treat unset MSRV as compatible

### What does this PR try to resolve?

Have the resolver treat no-MSRV as `rust-version = "*"`, like `cargo add` does for version-requirement selection

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

We last tweaked this logic in #13066.
However, we noticed this was inconsistent with `cargo add` in automatically selecting version requirements.

It looks like this is a revert of #13066, taking us back to the behavior in #12950.
In #12950 there was a concern about the proliferation of no-MSRV and whether we should de-prioritize those to make the chance of success more likely.

There are no right answes here, only which wrong answer is ok enough.
- Do we treat lack of rust version as `rust-version = "*"` as some people expect or do we try to be smart?
- If a user adds or removes `rust-version`, how should that affect the priority?

One piece of new information is that the RFC for this has us trying to fill the no-MSRV gap with
`rust-version = some-value-representing-the-current-toolchain>`.

See also https://github.com/rust-lang/cargo/issues/9930#issuecomment-1977471059

r? `@Eh2406`

### Additional information
2024-05-01 16:56:30 +00:00
Scott Schafer 6c08e58de9
feat(cargo-lints): Add a lint for unknown_lints 2024-05-01 10:45:09 -06:00
Scott Schafer 9159ebb083
fix(cargo-lints): Don't rewrite dash to underscore in lint name 2024-05-01 10:41:35 -06:00
Ed Page 1fc366826c refactor(toml): Use exhaustive destructure to ensure we inherit dep fields 2024-05-01 11:04:47 -05:00
Ed Page e8ba122c8b fix(toml): Don't lose 'public' when inheriting a dep
When inheriting a simple dep, we preserved the package dep's `public`
field but lost it when inheriting a detailed dep.

This was done by consolidating the code paths.  This also reduces the
risk of us doing this again in the future.
2024-05-01 10:57:42 -05:00
Ed Page bfe62a670d refactor(toml): Always create a detailed dep
This minimizes risk as we add more dependency features
2024-05-01 10:51:36 -05:00
Ed Page 7820a0b446 refactor(toml): Clarify which dep we are talking about 2024-05-01 10:41:00 -05:00
bors 6fc9e4b9a1 Auto merge of #13805 - Muscraft:im-a-teapot-lint-unstable, r=epage
Error when unstable lints are specified but not enabled

In [#13797, it was noted that](https://github.com/rust-lang/cargo/pull/13797#discussion_r1578162057) the `im-a-teapot` lint should always be unstable. This PR makes it so that `im-a-teapot` is unstable, and it is an error to specify it without the `test-dummy-unstable` cargo feature.

It does this by adding a `feature-gate` field to `Lint` and `LintGroup` that optionally
puts the lint/lint group behind a feature. The `feature-gate` is then checked during the new `analyze_cargo_lints_table` step that runs across all lints (and groups) specified in `[lints.cargo]` or `[workspace.lints]` if the package is inheriting its lints from a workspace.

The error looks like the following:
No inherit
![No inherit](https://github.com/rust-lang/cargo/assets/23045215/c245af87-8623-42dc-9652-be461809bb30)
Inherited
![Inhrtited](https://github.com/rust-lang/cargo/assets/23045215/5a90b7c9-0e9e-4a07-ab0e-e2e43cca8991)
2024-05-01 13:59:51 +00:00
Scott Schafer 712946c518
fix(lints): Mark the test_dummy_unstable lint group as unstable 2024-04-30 20:35:50 -06:00
Scott Schafer f007527291
fix(lints): Mark the im_a_teapot lint as unstable 2024-04-30 20:34:17 -06:00
Scott Schafer 2df02f07d8
fix(lints): Feature-gate the im_a_teapot lint 2024-04-30 20:31:12 -06:00
bors 1c92c1eef0 Auto merge of #13833 - Muscraft:warn-unknown-tool-lints-table, r=epage
fix(lint): Warn not Error on unsupported lint tool

In a recent Cargo Team meeting, it was decided to lessen the error on an unsupported tool in `[lints]` to a warning. This PR implements that change.
2024-05-01 02:30:51 +00:00
bors 6087566b3f Auto merge of #13792 - weihanglo:fix-in-rust-src, r=ehuss
fix(cargo-fix): dont fix into standard library
2024-04-30 20:45:20 +00:00
bors a1f8e450b3 Auto merge of #13813 - Muscraft:add-global-renderer, r=weihanglo
refactor: Move diagnostic printing to Shell

As I have been working on cargo's diagnostic system, I have disliked copying around the code for a new `Renderer`, and then emitting the diagnostic:
```rust
let renderer = Renderer::styled().term_width(
    gctx.shell()
        .err_width()
        .diagnostic_terminal_width()
        .unwrap_or(annotate_snippets::renderer::DEFAULT_TERM_WIDTH),
);
writeln!(gctx.shell().err(), "{}", renderer.render(message))?;
```

Moving to a method on `Shell` helps mitigate the risk of updating duplicate code and missing one. It should also make it nearly impossible to get into scenarios where `gctx.shell()` is borrowed twice, leading to panics. This problem was one I ran into early on as I tried to write messages to `stderr` like so:
```rust
writeln!(
    gctx.shell().err(),
    "{}",
    Renderer::styled()
        .term_width(
            gctx.shell()
                .err_width()
                .diagnostic_terminal_width()
                .unwrap_or(annotate_snippets::renderer::DEFAULT_TERM_WIDTH),
        )
        .render(message)
)?;
```
2024-04-30 18:25:52 +00:00
Scott Schafer 72f265b22d
refactor: Warn not Error on unsupported lint tool 2024-04-30 10:46:07 -06:00
Scott Schafer 5415b04fdd
refactor: Move diagnostic printing to Shell 2024-04-30 10:36:34 -06:00