Commit Graph

277980 Commits

Author SHA1 Message Date
Jacob Pratt
54c324f47b
Rollup merge of #134977 - estebank:issue-112357, r=BoxyUwU
Detect `mut arg: &Ty` meant to be `arg: &mut Ty` and provide structured suggestion

When a newcomer attempts to use an "out parameter" using borrows, they sometimes get confused and instead of mutating the borrow they try to mutate the function-local binding instead. This leads to either type errors (due to assigning an owned value to a mutable binding of reference type) or a multitude of lifetime errors and unused binding warnings.

This change adds a suggestion to the type error

```
error[E0308]: mismatched types
  --> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:6:14
   |
LL | fn change_object(mut object: &Object) {
   |                              ------- expected due to this parameter type
LL |     let object2 = Object;
LL |     object = object2;
   |              ^^^^^^^ expected `&Object`, found `Object`
   |
help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding
   |
LL ~ fn change_object(object: &mut Object) {
LL |     let object2 = Object;
LL ~     *object = object2;
   |
```
and to the unused assignment lint
```
error: value assigned to `object` is never read
  --> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:11:5
   |
LL |     object = &object2;
   |     ^^^^^^
   |
note: the lint level is defined here
  --> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:1:9
   |
LL | #![deny(unused_assignments, unused_variables)]
   |         ^^^^^^^^^^^^^^^^^^
help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding
   |
LL ~ fn change_object2(object: &mut Object) {
LL |     let object2 = Object;
LL ~     *object = object2;
   |
```

Fix #112357.
2025-01-13 20:43:45 -05:00
Jacob Pratt
81f742954a
Rollup merge of #134498 - oli-obk:push-wmxynprsyxvr, r=compiler-errors
Fix cycle error only occurring with -Zdump-mir

fixes #134205

During mir dumping, we evaluate static items to render their allocations. If a static item refers to itself, its own MIR will have a reference to itself, so during mir dumping we end up evaluating the static again, causing us to try to build MIR again (mir dumping happens during MIR building).

Thus I disabled evaluation of statics during MIR dumps in case the MIR body isn't far enough along yet to be able to be guaranteed cycle free.
2025-01-13 20:43:44 -05:00
bors
2ae9916816 Auto merge of #135192 - jdupak-ms:cdb-tests, r=wesleywiser
Add and improve debuginfo tests for Windows

Adds new test for closures and function pointers.
Improves robustness of existing tests by sorting wildcard matched outputs.

try-job: i686-msvc
2025-01-13 18:13:53 +00:00
bors
7a202a9056 Auto merge of #135204 - RalfJung:win64-zst, r=SparrowLii
fix handling of ZST in win64 ABI on windows-msvc targets

The Microsoft calling conventions do not really say anything about ZST since they do not seem to exist in MSVC. However, both GCC and clang allow passing ZST over  `__attribute__((ms_abi))` functions (which matches our `extern "win64" fn`) on `windows-gnu` targets, and therefore implicitly define a de-facto ABI for these types (and lucky enough they seem to define the same ABI). This ABI should be the same for windows-msvc and windows-gnu targets, so we use this as a hint for how to implement this ABI everywhere: we always pass ZST by-ref.

The best alternative would be to just reject compiling functions which cannot exist in MSVC, but that would be a breaking change.

Cc `@programmerjake` `@ChrisDenton`
Fixes https://github.com/rust-lang/rust/issues/132893
2025-01-13 13:05:53 +00:00
bors
3ff1b6410e Auto merge of #135167 - mzacho:depth-limit-const-eval-query, r=oli-obk
Depth limit const eval query

Currently the const-eval query doesn't have a recursion limit or timeout, causing the complier to freeze in an infinite loop, see #125718. This PR depth limits the `eval_to_const_value_raw` query (with the [`recursion_limit`](https://doc.rust-lang.org/reference/attributes/limits.html) attribute) and improves the diagnostics for query overflow errors, so spans are reported for other dep kinds than `layout_of` (e.g. `eval_to_const_value_raw`).

fixes #125718
fixes #114192
2025-01-13 10:18:26 +00:00
Jakub Dupak
75e9b19d78 Add and improve debuginfo tests for Windows 2025-01-13 09:38:04 +01:00
bors
b4045a404e Auto merge of #135430 - jhpratt:rollup-39cecwd, r=jhpratt
Rollup of 3 pull requests

Successful merges:

 - #135355 (ci: added test log format for ci)
 - #135386 (clean up code related to the rustdoc-js test suite)
 - #135391 (bootstrap: Implement conditional `tracing` infra)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-13 07:34:54 +00:00
Jacob Pratt
cc00936dda
Rollup merge of #135391 - jieyouxu:conditional-tracing, r=onur-ozkan
bootstrap: Implement conditional `tracing` infra

Add a conditional `tracing` setup that is gated behind `BOOTSTRAP_TRACING` env var. This `tracing` infra is implemented by:

- Introducing an optional `tracing` cargo feature in bootstrap.
- Added optional `tracing*` dependencies which are gated behind the `tracing` cargo feature.
- When `BOOTSTRAP_TRACING` is set, `bootstrap.py` will build bootstrap with `--features=tracing`.

There is a small trick here to share `BOOTSTRAP_TRACING` env var without having to add a separate env var:

- `BOOTSTRAP_TRACING=1` is not a registered `tracing` filter target, so that can be used to enable the `tracing` cargo feature yet not actually enable any tracing logs (useful for editor r-a setups without actually outputting any tracing logs).
- `BOOTSTRAP_TRACING=TRACE` and such are actually valid `tracing` filters, but that sets `BOOTSTRAP_TRACING` anyway.

Example usage: https://github.com/rust-lang/rust/pull/135299 (that experimental PR is not conditionally gated)
This PR is intentionally kept minimal to focus on the infra itself. To get actual mileage, instrumentations will need to be added to individual `Step`s and such.

r? `@onur-ozkan` (or reroll)
2025-01-13 01:05:11 -05:00
Jacob Pratt
abdd40d84d
Rollup merge of #135386 - lolbinarycat:bootstrap-test-cleanup, r=jieyouxu
clean up code related to the rustdoc-js test suite

r? `@jieyouxu`
2025-01-13 01:05:11 -05:00
Jacob Pratt
cc19b9b83b
Rollup merge of #135355 - ranger-ross:improved-ci-logs, r=onur-ozkan
ci: added test log format for ci

This PR adds a new test render format specifically for ci.
The goal as stated in #134910 is to make reviewing test failures in CI easier.

See the new test output format in the CI for this PR ([here](https://github.com/rust-lang/rust/actions/runs/12723914643/job/35469515397?pr=135355))

closes #134910 cc: `@jyn514`
2025-01-13 01:05:10 -05:00
许杰友 Jieyou Xu (Joe)
3ae724e6a0 rustc-dev-guide: document BOOTSTRAP_TRACING and bootstrap tracing setup 2025-01-13 13:46:20 +08:00
bors
a2016aaba6 Auto merge of #135352 - notriddle:notriddle/stability-shown, r=camelid
rustdoc: use import stability marker in display

Fixes #135078
2025-01-13 04:49:27 +00:00
bors
047bc17d4f Auto merge of #135371 - Mark-Simulacrum:no-alloc-case-cmp, r=compiler-errors
Remove allocations from case-insensitive comparison to keywords

Follows up on work in 99d02fb40f, expanding the alloc-free comparisons to more cases of case-insensitive keyword matching.

r? ghost for perf
2025-01-13 02:00:41 +00:00
许杰友 Jieyou Xu (Joe)
a4b9aa3e6e bootstrap.py: build bootstrap binary with --features=tracing if BOOTSTRAP_TRACING env var is set 2025-01-13 08:16:18 +08:00
许杰友 Jieyou Xu (Joe)
1307c950c4 bootstrap: add tracing and tracing-tree based tracing setup 2025-01-13 08:16:18 +08:00
许杰友 Jieyou Xu (Joe)
97d59c5af3 bootstrap: add optional tracing cargo feature and optional tracing* deps 2025-01-13 07:33:37 +08:00
bors
e7ad3ae331 Auto merge of #135420 - GuillaumeGomez:rollup-93vepka, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #135348 (rustdoc-json: Include items in stripped modules in `Crate::paths`.)
 - #135365 (Update the explanation for why we use box_new in vec!)
 - #135383 (De-abstract tagged ptr and make it covariant)
 - #135401 (Remove some empty expected files to fix blessing)
 - #135406 (Update unstable lint docs to include required feature attributes)
 - #135407 (Deny various clippy lints)
 - #135411 (run_make_support: add `#![warn(unreachable_pub)]`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-12 23:08:30 +00:00
Guillaume Gomez
223a7c1237
Rollup merge of #135411 - Urgau:unreach_pub-run-make, r=jieyouxu
run_make_support: add `#![warn(unreachable_pub)]`

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) lint as warn in the `run_make_support` crate.

Related to https://github.com/rust-lang/compiler-team/issues/773

r? ``@jieyouxu``
2025-01-12 23:09:01 +01:00
Guillaume Gomez
80784f0f83
Rollup merge of #135407 - joshtriplett:more-clippy, r=compiler-errors
Deny various clippy lints

Almost all of these clippy lints have zero occurrences. Two of them have one each, and this PR fixes those.
2025-01-12 23:09:00 +01:00
Guillaume Gomez
d8e88c9751
Rollup merge of #135406 - Aditya-PS-05:fix/unstable-lint-docs, r=compiler-errors
Update unstable lint docs to include required feature attributes

closes #135298

## Summary
This PR updates the documentation examples for the following unstable lints to ensure they include the necessary feature attributes for proper usage:

- fuzzy_provenance_casts
- lossy_provenance_casts
- unqualified_local_imports
- test_unstable_lint

## Changes Made:

- Added the appropriate #![feature(...)] attributes to the example code for each lint.
- Updated the examples to produce correct and meaningful warnings, ensuring they align with current lint behavior.

Reference:
- Used the `must_not_suspend` lint documentation as a template for these updates.
2025-01-12 23:08:59 +01:00
Guillaume Gomez
834f57555f
Rollup merge of #135401 - joshtriplett:empty-expected, r=lqd
Remove some empty expected files to fix blessing

https://github.com/rust-lang/rust/pull/134808 made --bless remove empty
expected files. Remove some empty files that were causing noise in
unrelated `--bless` invocations.
2025-01-12 23:08:59 +01:00
Guillaume Gomez
fad3039124
Rollup merge of #135383 - BoxyUwU:cov_tag_ptr, r=compiler-errors
De-abstract tagged ptr and make it covariant

In #135272 I needed to use a tagged ptr in `hir::TyKind` in order to not regress hir type sizes. Unfortunately the existing `CopyTaggedPtr` abstraction is insufficient as it makes the `'hir` lifetime invariant.

I spent some time trying to keep existing functionality while making it covariant but in the end I realised that actually we dont use *any* of this code *anywhere* in rustc, so I've just removed everything and replaced it with a much less general abstraction that is suitable for what I need in #135272.

Idk if anyone has a preference for just keeping all the abstractions here in case anyone needs them in the future 🤷‍♀️
2025-01-12 23:08:58 +01:00
Guillaume Gomez
24cc0cb6fe
Rollup merge of #135365 - saethlin:box-new, r=compiler-errors
Update the explanation for why we use box_new in vec!

The perf run in this PR demonstrates that there is no longer a dramatic change in compile time with the intrinsic `box_new` vs calling `Box::new`, but I've locally confirmed that there is still a dramatic change in stack use.
2025-01-12 23:08:58 +01:00
Guillaume Gomez
9d3ae11c54
Rollup merge of #135348 - aDotInTheVoid:pathspathspaths, r=GuillaumeGomez
rustdoc-json: Include items in stripped modules in `Crate::paths`.

Closes #135309

When we're running rustdoc-json, we should err on the side of adding more items to `Cache::paths`, as that directly becomes `Crate::paths` in the output.

r? ``@GuillaumeGomez.`` Best reviewed commit-by-commit.
2025-01-12 23:08:57 +01:00
bors
48a426eca9 Auto merge of #135384 - saethlin:inline-copy-from-slice, r=joboet
Add #[inline] to copy_from_slice

I'm doing cooked things to CGU partitioning for compiler-builtins (https://github.com/rust-lang/rust/pull/135395) and this was the lone symbol in my compiler-builtins rlib that wasn't an intrinsic. Adding `#[inline]` makes it go away.

Perf report indicates a marginal but chaotic effect on compile time, marginal improvement in codegen. As expected.
2025-01-12 20:16:25 +00:00
Aditya-PS-05
7ece88a2d7 remove test_unstable_lint feature 2025-01-13 00:14:24 +05:30
Ben Kimock
6024a06dba Update the explanation for why we use box_new in vec! 2025-01-12 13:17:16 -05:00
bors
627513a764 Auto merge of #135281 - onur-ozkan:build-stamps, r=jieyouxu
centralize build stamp logic

This PR brings all the stamp file handling into one place inside `build_stamp` module, which takes care of everything related to build stamps. By doing this, we cut down on duplicated code and types and keep the codebase easier to maintain and more consistent.

Main goals are:

- Make stamp handling stricter so we don't have to pass `Path`s around and manually `join` on arbitrary directories
- Keep all stamp-related logic in one place
- Make it easier to test and debug
- Avoid duplication
- Keep things simple and well-documented

Resolves #134962
2025-01-12 17:28:00 +00:00
Urgau
f25b0815a7 run_make_support: add #![warn(unreachable_pub)] 2025-01-12 16:12:34 +01:00
Boxy
4de8cefbdf De-abstract tagged pointer abstraction 2025-01-12 14:56:10 +00:00
bors
7bb9888953 Auto merge of #135402 - matthiaskrgr:rollup-cz7hs13, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #129259 (Add inherent versions of MaybeUninit methods for slices)
 - #135374 (Suggest typo fix when trait path expression is typo'ed)
 - #135377 (Make MIR cleanup for functions with impossible predicates into a real MIR pass)
 - #135378 (Remove a bunch of diagnostic stashing that doesn't do anything)
 - #135397 (compiletest: add erroneous variant to `string_enum`s conversions error)
 - #135398 (add more crash tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-12 14:43:10 +00:00
Aditya-PS-05
562107760d Update unstable lint docs to include required feature attributes 2025-01-12 19:31:05 +05:30
Josh Triplett
af7bc3158a Deny clippy::four_forward_slashes in library (no occurrences) 2025-01-12 15:58:01 +02:00
Josh Triplett
fcc7803822 Deny clippy::to_string_in_format_args (no occurrences) 2025-01-12 15:29:56 +02:00
Josh Triplett
fb2e70690b Deny clippy::single_char_add_str (no occurrences) 2025-01-12 15:26:24 +02:00
Josh Triplett
57fcee8655 Deny clippy::same_item_push (no occurrences) 2025-01-12 15:24:29 +02:00
Josh Triplett
132e640fbf Deny clippy::print_literal (no occurrences) 2025-01-12 15:22:06 +02:00
Josh Triplett
e6056b54cf Deny clippy::needless_bool and clippy::needless_bool_assign (no occurrences) 2025-01-12 15:17:29 +02:00
Josh Triplett
fc683cbc0e Deny clippy::non_minimal_cfg (no occurrences) 2025-01-12 15:15:49 +02:00
Josh Triplett
3b262bdf24 Deny clippy::char_lit_as_u8 (no occurrences) 2025-01-12 15:11:58 +02:00
Josh Triplett
9c5b99dc92 Deny clippy:;four_forward_slashes and fix the only occurrence 2025-01-12 15:09:16 +02:00
Josh Triplett
e54264c509 Deny clippy::format_in_format_args and fix the only occurrence 2025-01-12 15:09:16 +02:00
Ralf Jung
675a1036ca on Windows, consistently pass ZST by-ref 2025-01-12 13:32:36 +01:00
bors
c0f6a1ce3f Auto merge of #135262 - mrkajetanp:ci-aarch64-dist-reland, r=Kobzol
ci: Move dist-aarch64-linux to an aarch64 runner

Move the dist-aarch64-linux CI job to an aarch64 runner instead of cross-compiling it from an x86 one. This will make it possible to perform optimisations such as LTO, PGO and BOLT later on.

r? `@Kobzol`

Reland of #133809 now that the higher page sizes are fixed.

try-job: dist-aarch64-linux
try-job: dist-x86_64-linux
try-job: dist-i686-linux
2025-01-12 11:56:04 +00:00
Matthias Krüger
2fd11d0042
Rollup merge of #135398 - matthiaskrgr:crash, r=lqd
add more crash tests

try-job: aarch64-apple
try-job: x86_64-msvc
try-job: x86_64-gnu
try-job: dist-i586-gnu-i586-i686-musl
2025-01-12 12:07:59 +01:00
Matthias Krüger
1b45dad34e
Rollup merge of #135397 - lqd:compiletest-enums, r=jieyouxu
compiletest: add erroneous variant to `string_enum`s conversions error

As requested in #135392, this adds which variant caused the string conversion failure.

r? jieyouxu
fixes #135392
2025-01-12 12:07:59 +01:00
Matthias Krüger
b53239668a
Rollup merge of #135378 - compiler-errors:unnecessary-stashing, r=chenyukang
Remove a bunch of diagnostic stashing that doesn't do anything

#121669 removed a bunch of conditional diagnostic stashing/canceling, but left around the `steal` calls which just emitted the error eagerly instead of canceling the diagnostic. I think that these no-op `steal` calls don't do much and are confusing to encounter, so let's remove them.

The net effect is:
1. We emit more duplicated errors, since stashing has the side effect of duplicating diagnostics. This is not a big deal, since outside of `-Zdeduplicate-diagnostics=no`, the errors are already being deduplicated by the compiler.
2. It changes the order of diagnostics, since we're no longer stashing and then later stealing the errors. I don't think this matters much for the changes that the UI test suite manifests, and it makes these errors less order dependent.
2025-01-12 12:07:58 +01:00
Matthias Krüger
988137c040
Rollup merge of #135377 - compiler-errors:impossible-step, r=oli-obk
Make MIR cleanup for functions with impossible predicates into a real MIR pass

It's a bit jarring to see the body of a function with an impossible-to-satisfy where clause suddenly go to a single `unreachable` terminator when looking at the MIR dump output in order, and I discovered it's because we manually replace the body outside of a MIR pass.

Let's make it into a fully flegded MIR pass so it's more clear what it's doing and when it's being applied.
2025-01-12 12:07:58 +01:00
Matthias Krüger
55503a1d0e
Rollup merge of #135374 - compiler-errors:typo-trait-method, r=fee1-dead
Suggest typo fix when trait path expression is typo'ed

When users write something like `Default::defualt()` (notice the typo), failure to resolve the erroneous `defualt` item will cause resolution + lowering to interpret this as a type-dependent path whose self type is `Default` which is a trait object without `dyn`, rather than a trait function like `<_ as Default>::default()`.

Try to provide a bit of guidance in this situation when we can detect the typo.

Fixes https://github.com/rust-lang/rust/issues/135349
2025-01-12 12:07:57 +01:00
Matthias Krüger
08968a4baf
Rollup merge of #129259 - clarfonthey:maybe_uninit_slices, r=tgross35
Add inherent versions of MaybeUninit methods for slices

This is my attempt to un-stall #63569 and #79995, by creating methods that mirror the existing `MaybeUninit` API:

```rust
impl<T> MaybeUninit<T> {
    pub fn write(&mut self, value: T) -> &mut T;
    pub fn as_bytes(&self) -> &[MaybeUninit<u8>];
    pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>];
    pub unsafe fn assume_init_drop(&mut self);
    pub unsafe fn assume_init_ref(&self) -> &T;
    pub unsafe fn assume_init_mut(&mut self) -> &mut T;
}
```

Adding these APIs:

```rust
impl<T> [MaybeUninit<T>] {
    // replacing copy_from_slice; renamed to avoid conflict
    pub fn write_copy_of_slice(&mut self, value: &[T]) -> &mut [T] where T: Copy;

    // replacing clone_from_slice; renamed to avoid conflict
    pub fn write_clone_of_slice(&mut self, value: &[T]) -> &mut [T] where T: Clone;

    // identical to non-slice versions; no conflict
    pub fn as_bytes(&self) -> &[MaybeUninit<u8>];
    pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>];
    pub unsafe fn assume_init_drop(&mut self);
    pub unsafe fn assume_init_ref(&self) -> &[T];
    pub unsafe fn assume_init_mut(&mut self) -> &mut [T];
}
```

Since the `assume_init` methods are identical to those on non-slices, they feel pretty natural. The main issue with the write methods is naming, as discussed in #79995 among other places. My rationale:

* The term "write" should be in them somewhere, to mirror the other API, and this pretty much automatically makes them not collide with any other inherent slice methods.
* I chose `write_clone_of_slice` and `write_copy_of_slice` since `clone` and `copy` are being used as objects here, whereas they're being used as actions in `clone_from_slice` and `copy_from_slice`.

The final "weird" thing I've done in this PR is remove a link to `Vec<T>` from `assume_init_drop` (both copies, since they're effectively copied docs), since there's no good way to link to `Vec` for something that can occur both on the page for `std/primitive.slice.html` and `std/vec/struct.Vec.html`, since the code here lives in libcore and can't use intra-doc-linking to mention `Vec`. (see: #121436)

The reason why this method shows up both on `Vec<T>` and `[T]` is because the `[T]` docs are automatically inlined on `Vec<T>`'s page, since it implements `Deref`. It's unfortunate that rustdoc doesn't have a way of dealing with this at the moment, but it is what it is, and it's a reasonable compromise for now.
2025-01-12 12:07:57 +01:00