Commit graph

44894 commits

Author SHA1 Message Date
Jacob Pratt
6da26f7cfe
Rollup merge of #138552 - jieyouxu:print-request-cleanups, r=Urgau
Misc print request handling cleanups + a centralized test for print request stability gating

I was working on implementing `--print=supported-crate-types`, then I noticed some things that were mildly annoying me, so I pulled out these changes. In this PR:

- First commit adds a centralized test `tests/ui/print/stability.rs` that is responsible for exercising stability gating of the print requests.
    - AFAICT we didn't have any test that systematically checks this.
    - I coalesced `tests/ui/feature-gates/feature-gate-print-check-cfg.rs` (for `--print=check-cfg`) into this test too, since `--print=check-cfg` is only `-Z unstable-options`-gated like other unstable print requests, and is not additionally feature-gated. cc ``@Urgau`` in case you have any concerns.
- Second commit alphabetically sorts the `PrintKind` enum for consistency because the `PRINT_KINDS` list (using the enum) is *already* alphabetically sorted.
- Third commit pulls out two helpers:
    1. A helper `check_print_request_stability` for checking stability of print requests and the diagnostics for using unstable print requests without `-Z unstable-options`, to avoid repeating the same logic over and over.
    2. A helper `emit_unknown_print_request_help` for the unknown print request diagnostics to make print request collection control flow more obvious.
- Fourth commit renames `PrintKind::{TargetSpec,AllTargetSpecs}` to `PrintKind::{TargetSpecJson,AllTargetSpecsJson}` to better reflect their actual print names, `--print={target-spec-json,all-target-specs-json}`.

r? ``@nnethercote`` (or compiler/reroll)
2025-03-16 21:47:44 -04:00
bors
227690a258 Auto merge of #137011 - LuuuXXX:promote-ohos-with-host-tools, r=Amanieu
Promote ohos targets to tier2 with host tools.

### What does this PR try to resolve?

Try to promote the following [[Tier 2 without Host Tools](https://doc.rust-lang.org/rustc/platform-support.html#tier-2-without-host-tools)](https://doc.rust-lang.org/rustc/platform-support.html#tier-2-without-host-tools) targets to [[Tier 2 with Host Tools](https://doc.rust-lang.org/rustc/platform-support.html#tier-2-with-host-tools)](https://doc.rust-lang.org/rustc/platform-support.html#tier-2-with-host-tools):

- `aarch64-unknown-linux-ohos`
- `armv7-unknown-linux-ohos`
- `x86_64-unknown-linux-ohos`

### More Information?

see MCP: https://github.com/rust-lang/compiler-team/issues/811

### Blockage to be solved?

- [x] Submit an MCP
- [x] Submit code of promote ohos targets
- [x] Resolve related dependencies (`measureme`)

The modified code of the measureme has been merged (see https://github.com/rust-lang/measureme/pull/238). [done]
The new version will was released (https://github.com/rust-lang/measureme/pull/240). [done]
2025-03-16 18:42:18 +00:00
Jieyou Xu
24edbfbc24
Rename PrintKind::{AllTargetSpecs,TargetSpec} to {AllTargetSpecsJson,TargetSpecJson}
To correspond to their actual print request names, `target-spec-json`
and `all-target-specs-json`, and for consistency with other print name
<-> print kind mappings.
2025-03-16 21:56:02 +08:00
Jieyou Xu
f9eabc28d9
Extract print request stability gating and unknown print request help into helpers
To avoid duplicating stability check logic and make the print request
collection logic more straightforward.
2025-03-16 21:56:02 +08:00
Jieyou Xu
5f8e0920f9
Alphabetically sort PrintKind and enforce with tidy 2025-03-16 21:56:02 +08:00
许杰友 Jieyou Xu (Joe)
e714c3be9f
Rollup merge of #138549 - scottmcm:option-ssa, r=saethlin
Fix the OperandRef type for NullOp::{UbChecks,ContractChecks}

Stumbled on this while looking at something totally unrelated 🙃

r? saethlin
2025-03-16 13:19:53 +08:00
Scott McMurray
3d42541313 Fix the OperandRef type for NullOp::{UbChecks,ContractChecks} 2025-03-15 19:39:15 -07:00
许杰友 Jieyou Xu (Joe)
f4372f5d12
Rollup merge of #138484 - xizheyin:issue-138392, r=compiler-errors
Use lit span when suggesting suffix lit cast

Fixes #138392
2025-03-16 09:40:10 +08:00
许杰友 Jieyou Xu (Joe)
e0846806db
Rollup merge of #138082 - thaliaarchi:slice-cfg-not-test, r=thomcc
Remove `#[cfg(not(test))]` gates in `core`

These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-03-16 09:40:05 +08:00
许杰友 Jieyou Xu (Joe)
8882dac342
Rollup merge of #137956 - compiler-errors:rtn-rustdoc, r=fmease
Add RTN support to rustdoc

This adds support to rustdoc and rustdoc-json for rendering `(..)` RTN (return type notation) style generics.

---

Cleaning `rustc_middle::ty::Ty` is not correct still, though, and ends up rendering a function like:

```rust
pub fn foreign<T: Foreign<bar(..): Send>>()
where
    <T as Foreign>::bar(..): 'static,
    T::bar(..): Sync,
```

Into this:

```rust
pub fn foreign<T>()
where
    T: Foreign,
    impl Future<Output = ()>: Send + 'static + Sync,
```

This is because `clean_middle_ty` doesn't actually have sufficient context about whether the RPITIT is in its "defining scope" or not, so we don't know if the type was originally written like `-> impl Trait` or with RTN like `T::method(..)`.

Partially addresses #123996 (i.e., HIR side, not middle::ty one)
2025-03-16 09:40:04 +08:00
Michael Goulet
e3ac1fa81a Add RTN support to rustdoc 2025-03-15 18:13:27 +00:00
Michael Goulet
13134dd096 Don't drop Rvalue::WrapUnsafeBinder during GVN 2025-03-15 18:10:55 +00:00
bors
4d30011f6c Auto merge of #138532 - matthiaskrgr:rollup-mgcynqu, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #138283 (Enforce type of const param correctly in MIR typeck)
 - #138439 (feat: check ARG_MAX on Unix platforms)
 - #138502 (resolve: Avoid some unstable iteration)
 - #138514 (Remove fake borrows of refs that are converted into non-refs in `MakeByMoveBody`)
 - #138524 (Mark myself as unavailable for reviews temporarily)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-15 11:40:17 +00:00
Matthias Krüger
81ba55746d
Rollup merge of #138514 - compiler-errors:fake-borrow-ref-to-value, r=oli-obk
Remove fake borrows of refs that are converted into non-refs in `MakeByMoveBody`

Remove fake borrows of closure captures if that capture has been replaced with a by-move version of that capture.

For example, given an async closure that looks like:

```
let f: Foo;
let c = async move || {
    match f { ... }
};
```

... in this pair of coroutine-closure + coroutine, we capture `Foo` in the parent and `&Foo` in the child. We will emit two fake borrows like:

```
_2 = &fake shallow (*(_1.0: &Foo));
_3 = &fake shallow (_1.0: &Foo);
```

However, since the by-move-body transform is responsible for replacing `_1.0: &Foo` with `_1.0: Foo` (since the `AsyncFnOnce` coroutine will own `Foo` by value), that makes the second fake borrow obsolete since we never have an upvar of type `&Foo`, and we should replace it with a `nop`.

As a side-note, we don't actually even care about fake borrows here at all since they're fully a MIR borrowck artifact, and we don't need to borrowck by-move MIR bodies. But it's best to preserve as much as we can between these two bodies :)

Fixes #138501

r? oli-obk
2025-03-15 11:29:27 +01:00
Matthias Krüger
232ec5caea
Rollup merge of #138502 - petrochenkov:resinstab, r=compiler-errors
resolve: Avoid some unstable iteration

This PR replaces https://github.com/rust-lang/rust/pull/131213.
2025-03-15 11:29:26 +01:00
Matthias Krüger
06b135f6bc
Rollup merge of #138439 - weihanglo:argmax, r=jieyouxu
feat: check ARG_MAX on Unix platforms

On Unix the limits can be gargantuan anyway so we're pretty unlikely to hit them, but might still exceed it.
We consult ARG_MAX here to get an estimate.

Fixes #138421

r? `@jieyouxu`
2025-03-15 11:29:26 +01:00
Matthias Krüger
a384039053
Rollup merge of #138283 - compiler-errors:enforce-const-param, r=BoxyUwU
Enforce type of const param correctly in MIR typeck

Properly intercepts and then annotates the type for a `ConstKind::Param` in the MIR.

This code should probably be cleaned up, it's kinda spaghetti, but no better structure really occurred to me when writing this case.

We could probably gate this behind the feature gate or add a fast path when the args have no free regions if perf is bad.

r? `@BoxyUwU`
2025-03-15 11:29:25 +01:00
bors
aa95b9648a Auto merge of #138464 - compiler-errors:less-type-ir, r=lcnr
Use `rustc_type_ir` directly less in the codebase

cc https://github.com/rust-lang/rust/issues/138449

This is a somewhat opinionated bundle of changes that will make working on https://github.com/rust-lang/rust/issues/138449 more easy, since it cuts out the bulk of the changes that would be necessitated by the lint. Namely:

1. Fold `rustc_middle::ty::fold` and `rustc_middle::ty::visit` into `rustc_middle::ty`. This is because we already reexport some parts of these modules into `rustc_middle::ty`, and there's really no benefit from namespacing away the rest of these modules's functionality given how important folding and visiting is to the type layer.
2. Rename `{Decodable,Encodable}_Generic` to `{Decodable,Encodable}_NoContext`[^why], change it to be "perfect derive" (`synstructure::AddBounds::Fields`), use it throughout `rustc_type_ir` instead of `TyEncodable`/`TyDecodable`.
3. Make `TyEncodable` and `TyDecodable` derives use `::rustc_middle::ty::codec::TyEncoder` (etc) for its generated paths, and move the `rustc_type_ir::codec` module back to `rustc_middle::ty::codec` 🎉.
4. Stop using `rustc_type_ir` in crates that aren't "fundamental" to the type system, namely middle/infer/trait-selection. This amounted mostly to changing imports from `use rustc_type_ir::...` to `use rustc_middle::ty::...`, but also this means that we can't glob import `TyKind::*` since the reexport into `rustc_middle::ty::TyKind` is a type alias. Instead, use the prefixed variants like `ty::Str` everywhere -- IMO this is a good change, since it makes it more regularized with most of the rest of the compiler.

[^why]: `_NoContext` is the name for derive macros with no additional generic bounds and which do "perfect derive" by generating bounds based on field types. See `HashStable_NoContext`.

I'm happy to cut out some of these changes into separate PRs to make landing it a bit easier, though I don't expect to have much trouble with bitrot.

r? lcnr
2025-03-15 08:36:38 +00:00
Michael Goulet
b88f85a410 Stop relying on rustc_type_ir in non-type-system crates 2025-03-15 06:42:48 +00:00
Michael Goulet
19c84c8812 Move codec module back into middle 2025-03-15 06:42:48 +00:00
Michael Goulet
6438b9eca8 Use {Decodable,Encodable}_NoContext in type_ir 2025-03-15 06:34:36 +00:00
Michael Goulet
e5a2220327 Fold visit into ty 2025-03-15 06:34:36 +00:00
Michael Goulet
dc0cdfd753 Squash fold into ty 2025-03-15 06:34:36 +00:00
bors
adea7cbc09 Auto merge of #138379 - estebank:macro-backtrace-note, r=petrochenkov
Do not suggest using `-Zmacro-backtrace` for builtin macros

For macros that are implemented on the compiler, or that are annotated with `rustc_diagnostic_item`, which have arbitrary implementations from the point of view of the user and might as well be intrinsics, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros like `panic!` and `format!`.

This PR adds a field to every `Span`'s `ExpnData` stating whether it comes from a builtin macro. This is determined by the macro being annotated with either `#[rustc_builtin_macro]` or `#[rustc_diagnostic_item]`. An alternative to using these attributes that already exist for other uses would be to introduce another attribute like `#[rustc_no_backtrace]` to have finer control on which macros are affected (for example, an error within `vec![]` now doesn't mention the backtrace, but one could make the case that it should). Ideally, instead of carrying this information in the `ExpnData` we'd instead try to query the `DefId` of the macro (that is already stored) to see if it is annotated in some way, but we do not have access to the `TyCtxt` from `rustc_errors`.

r? `@petrochenkov`
2025-03-15 05:29:22 +00:00
León Orell Valerian Liehr
9838591694
Rollup merge of #138518 - yotamofek:pr/hir-lint-typo, r=compiler-errors
Fix typo in hir lowering lint diag
2025-03-15 00:18:27 +01:00
León Orell Valerian Liehr
79775921aa
Rollup merge of #138511 - mohe2015:rustc-parse-pub-parse-expr-cond, r=oli-obk
Make `Parser::parse_expr_cond` public

This allows usage in rustfmt and rustfmt forks.

I'm using this for custom macro formatting, see 30c83df9e1/src/parse/macros/html.rs (L57)

It would be great if this could be upstreamed so I don't need to rely on a fork.
2025-03-15 00:18:26 +01:00
León Orell Valerian Liehr
370f8fb99d
Rollup merge of #138482 - nnethercote:fix-hir-printing, r=compiler-errors
Fix HIR printing of parameters

HIR pretty printing does the wrong thing for anonymous parameters, and there is no test coverage for it. This PR remedies both of those things.

r? ``@lcnr``
2025-03-15 00:18:25 +01:00
León Orell Valerian Liehr
03cda6b022
Rollup merge of #138474 - remexre:refactor-is-snake-case, r=compiler-errors
Refactor is_snake_case.

I wondered what the definition of this actually was, and found the original hard to read. I believe this change preserves the original behavior, but is hopefully clearer.
2025-03-15 00:18:25 +01:00
León Orell Valerian Liehr
43c41a801a
Rollup merge of #138460 - xizheyin:issue-138319, r=petrochenkov
Pass struct field HirId when check_expr_struct_fields

Fixes #138319

r? compiler

cc ``@Mark-Simulacrum``
2025-03-15 00:18:24 +01:00
León Orell Valerian Liehr
10055fb03a
Rollup merge of #138056 - heiher:loong64v1.1-features, r=petrochenkov
rustc_target: Add target features for LoongArch v1.1

This patch adds new target features for LoongArch v1.1:

* div32
* lam-bh
* lamcas
* ld-seq-sa
* scq
2025-03-15 00:18:22 +01:00
Yotam Ofek
e6f7ab50c0 Small grammar fix in comment 2025-03-14 21:03:21 +00:00
Yotam Ofek
5da1ba41b3 Fix typo in hir lowering lint diag 2025-03-14 21:03:21 +00:00
Esteban Küber
f0b8e13b59 Do not suggest using -Zmacro-backtrace for builtin macros
For macros that are implemented on the compiler, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros.
2025-03-14 19:50:03 +00:00
Michael Goulet
e54bde6d47 Remove fake borrows of refs that are converted into non-refs in MakeByMoveBody 2025-03-14 19:38:29 +00:00
Moritz Hedtke
66c49c73ee Make Parser::parse_expr_cond public.
This allows usage in rustfmt and rustfmt forks.
2025-03-14 19:55:55 +01:00
León Orell Valerian Liehr
881d237cd9
Rollup merge of #137619 - Pyr0de:issue_137249, r=fmease
Provide helpful diagnostics for shebang lookalikes

When `[` is not found after a `#!`, a note will be added to the exisiting error

```
error: expected `[`, found `/`
 --> src/main.rs:2:3
  |
2 | #!/usr/bin/env -S cargo +nightly -Zscript
  |   ^ expected `[`
  |
  = note: the token sequence `#!` here looks like the start of a shebang interpreter directive but it is not
  = help: if you meant this to be a shebang interpreter directive, move it to the very start of the file
```

Fixes #137249

r? `@fmease`
2025-03-14 17:26:17 +01:00
León Orell Valerian Liehr
f8842bd752
Rollup merge of #134720 - malezjaa:feat/crate-type-valid-values, r=jieyouxu
Display valid crate types in error message for --crate-type flag

This PR improves the error message for the --crate-type flag. When an invalid crate type is provided, the compiler will now show a list of valid options.

### Before
![image](https://github.com/user-attachments/assets/4922e4e5-eeca-40cd-ac1c-1c6319a81aee)

### After
![image](https://github.com/user-attachments/assets/67ea1f35-aa41-4e4f-8691-47c273d0cff9)

I based the implementation on `OutputType::shorthands_display`

Closes #70183
2025-03-14 17:26:13 +01:00
Vadim Petrochenkov
a891139df1 resolve: Avoid some unstable iteration 2025-03-14 18:34:08 +03:00
Weihang Lo
08166b5b23
feat(linker): check ARG_MAX on Unix platforms
On Unix the limits can be gargantuan anyway so we're pretty
unlikely to hit them, but might still exceed it.
We consult ARG_MAX here to get an estimate.
2025-03-14 09:45:49 -04:00
Weihang Lo
a672448f0d
fix(linker): use arg list estimate on only Windows
Though I doubt anyone running rustc outside Unix/Windows
2025-03-14 09:42:18 -04:00
Weihang Lo
79034bd291
fix(linker): prevent overflow when estimating CLI arg list length
This also updates the estimate on Windows of the length argument
list to `saturating_add` to avoid overflow.
2025-03-14 09:42:12 -04:00
xizheyin
bc6047a5a7
Use lit span when suggesting suffix lit cast
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-14 20:44:49 +08:00
malezjaa
90bf2b159a Show valid crate types when the user passes unknown --crate-type value
Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
2025-03-14 15:53:42 +08:00
bors
f7b4354283 Auto merge of #138480 - jhpratt:rollup-y3b8wu5, r=jhpratt
Rollup of 16 pull requests

Successful merges:

 - #136001 (Overhaul examples for PermissionsExt)
 - #136230 (Reword incorrect documentation about SocketAddr having varying layout)
 - #136892 (Sync Fuchsia target spec with clang Fuchsia driver)
 - #136911 (Add documentation URL to selected jobs)
 - #137870 ( Improve HashMap docs for const and static initializers)
 - #138179 (Add `src/tools/x` to the main workspace)
 - #138389 (use `expect` instead of `allow`)
 - #138396 (Enable metrics and verbose tests in PR CI)
 - #138398 (atomic intrinsics: clarify which types are supported and (if applicable) what happens with provenance)
 - #138432 (fix: remove the check of lld not supporting `@response-file)`
 - #138434 (Visit `PatField` when collecting lint levels)
 - #138441 (update error message)
 - #138442 (EUV: fix place of deref pattern's interior's scrutinee)
 - #138457 (Remove usage of legacy scheme paths on RedoxOS)
 - #138461 (Remove an outdated line from a test comment)
 - #138466 (Remove myself from libs review)

Failed merges:

 - #138452 (Remove `RUN_CHECK_WITH_PARALLEL_QUERIES`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-14 07:02:26 +00:00
xizheyin
aad1db7373
Pass precise HirId when calling check_stability
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-14 14:51:58 +08:00
Jacob Pratt
f5055722b6
Rollup merge of #138442 - dianne:deref-pat-euv-fix, r=compiler-errors
EUV: fix place of deref pattern's interior's scrutinee

The place previously used here was that of the temporary holding the reference returned by `Deref::deref` or `DerefMut::deref_mut`. However, since the inner pattern of `deref!(inner)` expects the deref-target type itself, this would ICE when that type was inspected (e.g. by the EUV case for slice patterns). This adds a deref projection to fix that.

Since current in-tree consumers of EUV (upvar inference and clippy) don't care about Rvalues, the place could be simplified to `self.cat_rvalue(pat.hir_id, self.pat_ty_adjusted(subpat)?)` to save some cycles. I personally find EUV to be a bit fragile, so I've opted for pedantic correctness. Maybe a `HACK` comment would suffice though?

Fixes #125059

r? `@compiler-errors`
2025-03-14 01:37:35 -04:00
Jacob Pratt
fb2a7fa209
Rollup merge of #138434 - compiler-errors:lint-level-pat-field, r=jieyouxu
Visit `PatField` when collecting lint levels

Fixes #138428

Side-note, I vaguely skimmed over the other nodes we could be visiting here and it doesn't *seem* to me that we're missing anything, though I may be mistaken given recent(?) support for attrs in where clauses(??). Can be fixed in a follow-up PR.
2025-03-14 01:37:34 -04:00
Jacob Pratt
e928a8f4a0
Rollup merge of #138432 - weihanglo:lld, r=lqd
fix: remove the check of lld not supporting @response-file

In LLVM v9, lld has supported `@response-file.`
LLVM v9 was released on 2019-09-19.
The check was added back to 2018-03-14 (1.26.0) via 04442af18b.
It has been more than five years, and we ship our own lld regardlessly.
This should be happily removed.

See also:

* <bb12396f91>
* <https://reviews.llvm.org/D63024>
2025-03-14 01:37:33 -04:00
Jacob Pratt
91e4bab25f
Rollup merge of #138398 - RalfJung:atomic-intrinsics-provenance, r=nnethercote
atomic intrinsics: clarify which types are supported and (if applicable) what happens with provenance

The provenance semantics match what Miri implements and what the `AtomicPtr` API expects.
2025-03-14 01:37:32 -04:00
Jacob Pratt
459352a217
Rollup merge of #136892 - erickt:fuchsia-target, r=jieyouxu
Sync Fuchsia target spec with clang Fuchsia driver

This updates the Fuchsia target spec with the [Clang Fuchsia driver], which picks up a few changes:

* Adds `-z start-stop-visibility=hidden` and `-z rel` to the pre link arguments.
* Adds `--execute-only` and `--fix-cortex-a53-843419` for `aarch64-unknown-fuchsia`.
* Enables the equivalent cpu features for `x86-64-v2` for `x86_64-unknown-fuchsia`, which is our minimum supported x86_64 platform according to [RFC-0073].

try-job: x86_64-fuchsia

[Clang Fuchsia driver]: 8374d42186/clang/lib/Driver/ToolChains/Fuchsia.cpp
[RFC-0073]: https://fuchsia.dev/fuchsia-src/contribute/governance/rfcs/0073_x86_64_platform_requirement
2025-03-14 01:37:29 -04:00