17597 Commits

Author SHA1 Message Date
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
Urgau
388a17f23f Update regular tests for always-on check-cfg 2024-05-01 12:56:04 +02:00
Urgau
60a5026885 Adjust documentation for newly stabilized -Zcheck-cfg 2024-05-01 12:56:04 +02: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
Urgau
a5669e8fa3 Stabilize -Zcheck-cfg as always enabled-by-default 2024-04-30 23:00:43 +02: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
bors
b861629ef6 Auto merge of #13832 - ferrocene:pa-source-tarball-git, r=weihanglo
Populate git information when building Cargo from Rust's source tarball

### What does this PR try to resolve?

Right now Cargo doesn't populate the commit hash or date in its version output when it's built from Rust's plain source tarball (like `rustc-1.77.2-src.tar.xz`). That's because Cargo's build script only looks for information in the `.git` directory, which is missing from that tarball.

I opened https://github.com/rust-lang/rust/pull/124553 to have bootstrap inject a `git-commit-info` file in `src/tools/cargo` when building the plain source tarball, containing the correct git information. This is the approach also used by the compiler.

This PR updates the build script to read the information from that file if there is no `.git` and the file is present.

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

To test the PR you need to move the `.git` directory somewhere else and create a `git-commit-info` file like this:

```
25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
25ef9e3d8
2024-04-09
```

Then clearing the build cache and running `cargo run -- -vV` should show the git information in the `git-commit-info` file.

### Additional information

This PR can be merged independently from https://github.com/rust-lang/rust/pull/124553
2024-04-30 16:45:10 +00:00
Scott Schafer
5415b04fdd
refactor: Move diagnostic printing to Shell 2024-04-30 10:36:34 -06:00
Pietro Albini
bd752e9920
add support for reading git-commit-info 2024-04-30 10:44:27 +02:00
Pietro Albini
80f96704e0
refactor setting the git info to support more sources 2024-04-30 10:35:11 +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
Weihang Lo
bd31d7c599
docs(changelog): typo fixes 2024-04-29 23:05:41 -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
bors
e0b9fae7ce Auto merge of #13830 - epage:trace, r=weihanglo
fix(toml): Improve granularity of traces

### What does this PR try to resolve?

Once we move resolving out of `to_targets`, we won't have tracing visibility.  As we don't have a top-level function for resolving, I put it on each. I mirrored this for "to_" for consistency and it seems useful when looking at the output.

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

### Additional information
2024-04-29 22:03:25 +00: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
ba6fb40528 Auto merge of #13713 - epage:no-auto, r=weihanglo
fix(toml): Warn, rather than fail publish, if a target is excluded

### What does this PR try to resolve?

We have a couple of problems with publishing
- Inconsistent errors: if a target that `package` doesn't verify is missing `path`, it will error, while one with `path` won't, see #13456
- Users may want to exclude targets and their choices are
  - Go ahead and include them.  I originally excluded my examples before doc-scraping was a think.  The problem was if I had to set `required-features`, I then could no longer exclude them
  - Muck with `Cargo.toml` during publish and pass `--allow-dirty`

This fixes both by auto-stripping targets on publish.  We will warn the user that we did so.

This is a mostly-one-way door on behavior because we are turning an error case into a warning.
For the most part, I think this is the right thing to do.
My biggest regret is that the warning is only during `package`/`publish` as it will be too late to act on it and people who want to know will want to know when the problem is introduced.
The error is also very late in the process but at least its before a non-reversible action has been taken.
Dry-run and `yank` help.

Fixes #13456
Fixes #5806

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

Tests are added in the first commit and you can then follow the commits to see how the test output evolved.

The biggest risk factors for this change are
- If the target-stripping logic mis-identifies a path as excluded because of innocuous path differences (e.g. case)
- Setting a minimum MSRV for published packages: `auto*` were added in 1.27 (#5335) but were insta-stable.  `autobins = false` did nothing until 1.32 (#6329).  I have not checked to see how this behaves pre-1.32  or pre-1.27.  Since my memory of that error is vague, I believe it will either do a redundant discovery *or* it will implicitly skip discovery

Resolved risks
- #13729 ensured our generated target paths don't have `\` in them
- #13729 ensures the paths are normalize so the list of packaged paths

For case-insensitive filesystems, I added tests to show the original behavior (works locally but will fail when depended on from a case-sensitive filesystem) and tracked how that changed with this PR (on publish warn that those targets are stripped).  We could try to normalize the case but it will also follow symlinks and is likely indicative of larger casing problems that the user had.  Weighing how broken things are now , it didn't seem changing behavior on this would be too big of a deal.

We should do a Call for Testing when this hits nightly to have people to `cargo package` and look for targets exclusion warnings that don't make sense.

### Additional information

This builds on #13701 and the work before it.

By enumerating all targets in `Cargo.toml`, it makes it so rust-lang/crates.io#5882 and rust-lang/crates.io#814 can be implemented without any other filesystem interactions.

A follow up PR is need to make much of a difference in performance because we unconditionally walk the file system just in case `autodiscover != Some(false)` or a target is missing a `path`.

We cannot turn off auto-discovery of libs, so that will always be done for bin-only packages.
2024-04-29 18:22:56 +00:00
bors
d071c59ad1 Auto merge of #13829 - Muscraft:ensure-cap-lints, r=epage
test(cargo-lints): Add a test to ensure cap-lints works

When implementing the linting system, [it was noted that there was no test to ensure this it is to cap-lints](https://github.com/rust-lang/cargo/pull/13621#discussion_r1538154508), this PR adds that missing test.
2024-04-29 17:49:34 +00:00
Ed Page
8cc2f391ba docs(toml): Clarify what resolving a TOML means 2024-04-29 12:25:57 -05:00
Ed Page
06a57142f1 fix(toml): Warn, rather than fail publish, if targets are excluded
This could offer performance gains when parsing a published
manifest since the targets don't need to be discovered.
To see this, we'd first need to stop discovering potential targets even when it isn't
needed.
2024-04-29 12:25:56 -05:00
Ed Page
1e6047763d fix(toml): Warn, rather than fail publish, if build.rs is excluded
This could offer a minor performance gain when reading this manifest
since the target doesn't need to be discovered.
2024-04-29 12:25:19 -05:00
Ed Page
39f1a210b8 perf(toml): Avoid looking up readme on published packages
Not much of a performance gain;
this is mostly done to be consistent with the target work.
2024-04-29 12:25:19 -05:00
Ed Page
0cf29c5713 test(package): Show different crate discovery cases
I left off the explicit `path` cases because I hope that will become
moot
2024-04-29 12:25:19 -05:00
Ed Page
340050e0cb test(package): Show current case behavior 2024-04-29 12:25:19 -05:00
bors
cc20b551ce Auto merge of #13788 - epage:badges, r=weihanglo
fix(toml)!: Remove support for inheriting badges

### What does this PR try to resolve?

We allowed `[badges]` to inherit from `[workspace.package.badges]` which was a bug:
- This was not specified in the RFC
- We did not document this
- Even if someone were to try to guess to use this, it is inconsistent with how inheritance works because this should inherit from `workspace.badges` instead of `workspace.package.badges`

While keeping in mind that `[badges]` is effectively deprecated.

In that context, I think its safe to break support for this without a transition period.

Fixes #13643

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

### Additional information
2024-04-29 16:55:22 +00:00
Scott Schafer
cbb1cd2382
test(cargo-lints): Add a test to ensure cap-lints works 2024-04-29 10:36:29 -06:00
bors
e31c27d0fe Auto merge of #13827 - epage:bump-check, r=weihanglo
chore(ci): Don't check `cargo` against beta channel

We already only partially check it and it has been a source of false positives.

While there is trust in the job, contributors and maintainers go into the job assuming there is a problem and it takes time to break that assumption.

If we lose trust in the job, we then won't trust it when it fails for other reasons.

This also increases the risk of us not seeing other problems `bump-checks` is meant to find if the steps in the job get re-arranged to make this one of the early ones.
2024-04-29 14:28:16 +00:00
Ed Page
705c4f1cae chore(ci): Don't check cargo against beta channel
We already only partially check it and it has been a source of false
positives.

While there is trust in the job, contributors and maintainers go into
the job assuming there is a problem and it takes time to break that
assumption.

If we lose trust in the job, we then won't trust it when it fails for
other reasons.

This also increases the risk of us not seeing other problems
`bump-checks` is meant to find if the steps in the job get re-arranged
to make this one of the early ones.
2024-04-29 09:05:33 -05:00
bors
080869e835 Auto merge of #13817 - rukai:fix_target_gitignore, r=weihanglo
Fix target entry in .gitignore

The directories at:
* https://github.com/rust-lang/cargo/tree/master/tests/testsuite/cargo_remove/target
* https://github.com/rust-lang/cargo/tree/master/tests/testsuite/cargo_add/target

Are getting picked up by the `target` entry in .gitignore, causing git to ignore any extra files added to those directories.
A minor issue I know, but I still think its worth fixing.

## Alternative

An alternative solution would be to rename those directories which I'm more than happy to do.
But I think we are better off just changing .gitignore as that is more future proof.
2024-04-29 13:57:46 +00:00
bors
b74573b8fb Auto merge of #13823 - weihanglo:version-bump, r=epage
Bump to 0.81.0; update changelog
2024-04-29 13:28:45 +00:00
Weihang Lo
f1c5693aef
Update changelog for 1.80.0 2024-04-28 23:58:04 -04:00
Weihang Lo
0ee2a330d2
Update changelog for 1.79.0 2024-04-28 23:57:56 -04:00
Weihang Lo
910efc4d23
Bump to 0.81.0 2024-04-28 23:57:55 -04:00
Lucas Kent
433635b9fe Fix target entry in .gitignore 2024-04-29 07:39:04 +10:00
bors
cbca426209 Auto merge of #13816 - rukai:bindep_cargo_tree_panic_test, r=weihanglo
Add failing test: artifact_dep_target_specified

This PR pulls the failing test out of https://github.com/rust-lang/cargo/pull/13207

[During review](https://github.com/rust-lang/cargo/pull/13207#discussion_r1543463395), it was requested there be a previous commit with a failing test.
It will be a while before I have the time to address the other issues with the PR, so I figured for now we should land this failing test first.
2024-04-28 13:17:55 +00:00
Piotr Osiewicz
c770700885 Clean non-filetype based entries just once 2024-04-28 13:09:14 +02:00
Lucas Kent
4079305704 Add failing test: artifact_dep_target_specified 2024-04-28 17:49:16 +10:00