Commit Graph

46199 Commits

Author SHA1 Message Date
Chris Denton
d4845e1b0b
Rollup merge of #139308 - Shourya742:2025-03-29-add-autodiff-inline, r=ZuseZ4
add autodiff inline

closes: #138920

r? ```@ZuseZ4```

try-job: dist-aarch64-linux
2025-04-28 23:29:14 +00:00
bors
25cdf1f674 Auto merge of #140388 - GuillaumeGomez:rollup-aj9o3ch, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #140056 (Fix a wrong error message in 2024 edition)
 - #140220 (Fix detection of main function if there are expressions around it)
 - #140249 (Remove `weak` alias terminology)
 - #140316 (Introduce `BoxMarker` to improve pretty-printing correctness)
 - #140347 (ci: clean more disk space in codebuild)
 - #140349 (ci: use aws codebuild for the `dist-x86_64-linux` job)
 - #140379 (rustc-dev-guide subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-28 17:22:11 +00:00
Michael Goulet
105d1dcefd Do not compute type_of for impl item if impl where clauses are unsatisfied 2025-04-28 17:15:11 +00:00
lcnr
016105cd77 review 2025-04-28 16:49:30 +00:00
lcnr
fa90feaeef only return nested goals for Certainty::Yes 2025-04-28 16:36:02 +00:00
Augie Fackler
ff6dad436d PassWrapper: adapt for llvm/llvm-project@d3d856ad84
LLVM 21 moves to making it more explicit what this function call is
doing, but nothing has changed behaviorally, so for now we just adjust
to using the new name of the function.

@rustbot label llvm-main
2025-04-28 11:53:43 -04:00
bit-aloo
7018392337
remove noinline attribute and add alwaysinline after AD pass 2025-04-28 21:10:32 +05:30
bors
7d65abfe80 Auto merge of #123948 - azhogin:azhogin/async-drop, r=oli-obk
Async drop codegen

Async drop implementation using templated coroutine for async drop glue generation.

Scopes changes to generate `async_drop_in_place()` awaits, when async droppable objects are out-of-scope in async context.

Implementation details:
https://github.com/azhogin/posts/blob/main/async-drop-impl.md

New fields in Drop terminator (drop & async_fut). Processing in codegen/miri must validate that those fields are empty (in full version async Drop terminator will be expanded at StateTransform pass or reverted to sync version). Changes in terminator visiting to consider possible new successor (drop field).

ResumedAfterDrop messages for panic when coroutine is resumed after it is started to be async drop'ed.

Lang item for generated coroutine for async function async_drop_in_place. `async fn async_drop_in_place<T>()::{{closure0}}`.

Scopes processing for generate async drop preparations. Async drop is a hidden Yield, so potentially async drops require the same dropline preparation as for Yield terminators.

Processing in StateTransform: async drops are expanded into yield-point. Generation of async drop of coroutine itself added.

Shims for AsyncDropGlueCtorShim, AsyncDropGlue and FutureDropPoll.

```rust
#[lang = "async_drop"]
pub trait AsyncDrop {
    #[allow(async_fn_in_trait)]
    async fn drop(self: Pin<&mut Self>);
}

impl Drop for Foo {
    fn drop(&mut self) {
        println!("Foo::drop({})", self.my_resource_handle);
    }
}

impl AsyncDrop for Foo {
    async fn drop(self: Pin<&mut Self>) {
        println!("Foo::async drop({})", self.my_resource_handle);
    }
}
```

First async drop glue implementation re-worked to use the same drop elaboration code as for sync drop.
`async_drop_in_place` changed to be `async fn`. So both `async_drop_in_place` ctor and produced coroutine have their lang items (`AsyncDropInPlace`/`AsyncDropInPlacePoll`) and shim instances (`AsyncDropGlueCtorShim`/`AsyncDropGlue`).
```
pub async unsafe fn async_drop_in_place<T: ?Sized>(_to_drop: *mut T) {
}
```
AsyncDropGlue shim generation uses `elaborate_drops::elaborate_drop` to produce drop ladder (in the similar way as for sync drop glue) and then `coroutine::StateTransform` to convert function into coroutine poll.

AsyncDropGlue coroutine's layout can't be calculated for generic T, it requires known final dropee type to be generated (in StateTransform). So, `templated coroutine` was introduced here (`templated_coroutine_layout(...)` etc).

Such approach overrides the first implementation using mixing language-level futures in https://github.com/rust-lang/rust/pull/121801.
2025-04-28 14:14:26 +00:00
Bastian Kersting
7082fa27a7 Rework the logic for PointerFinder::visit_place
This makes the implementation of our PointerFinder a bit more
straightforward.
2025-04-28 12:36:47 +00:00
Guillaume Gomez
cbc40c71c8
Rollup merge of #140316 - nnethercote:BoxMarker, r=dtolnay
Introduce `BoxMarker` to improve pretty-printing correctness

Box opening/closing is really easy to get wrong in the pretty-printers. This PR makes it much harder to get wrong.

r? `@Urgau`
2025-04-28 13:30:45 +02:00
Guillaume Gomez
7843686ffe
Rollup merge of #140249 - BoxyUwU:remove_weak_alias_terminology, r=oli-obk
Remove `weak` alias terminology

I find the "weak" alias terminology to be quite confusing. It implies the existence of "strong" aliases (which do not exist) and I'm not really sure what about weak aliases is "weak". I much prefer "free alias" as the term. I think it's much more obvious what it means as "free function" is a well defined term that already exists in rust.

It's also a little confusing given "weak alias" is already a term in linker/codegen spaces which are part of the compiler too. Though I'm not particularly worried about that as it's usually very obvious if you're talking about the type system or not lol. I'm also currently trying to write documentation about aliases and it's somewhat awkward/confusing to be talking about *weak* aliases, when I'm not really sure what the basis for that as the term actually *is*.

I would also be happy to just find out there's a nice meaning behind calling them "weak" aliases :-)

r? `@oli-obk`

maybe we want a types MCP to decide on a specific naming here? or maybe we think its just too late to go back on this naming decision ^^'
2025-04-28 13:30:45 +02:00
Guillaume Gomez
1a766a8772
Rollup merge of #140056 - yuk1ty:fix-static-mut-error-message, r=jieyouxu
Fix a wrong error message in 2024 edition

Fixes https://github.com/rust-lang/rust/issues/139952
2025-04-28 13:30:44 +02:00
Andrew Zhogin
c366756a85 AsyncDrop implementation using shim codegen of async_drop_in_place::{closure}, scoped async drop added. 2025-04-28 16:23:13 +07:00
bors
a932eb36f8 Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross
Implement a lint for implicit autoref of raw pointer dereference - take 2

*[t-lang nomination comment](https://github.com/rust-lang/rust/pull/123239#issuecomment-2727551097)*

This PR aims at implementing a lint for implicit autoref of raw pointer dereference, it is based on #103735 with suggestion and improvements from https://github.com/rust-lang/rust/pull/103735#issuecomment-1370420305.

The goal is to catch cases like this, where the user probably doesn't realise it just created a reference.

```rust
pub struct Test {
    data: [u8],
}

pub fn test_len(t: *const Test) -> usize {
    unsafe { (*t).data.len() }  // this calls <[T]>::len(&self)
}
```

Since #103735 already went 2 times through T-lang, where they T-lang ended-up asking for a more restricted version (which is what this PR does), I would prefer this PR to be reviewed first before re-nominating it for T-lang.

----

Compared to the PR it is as based on, this PR adds 3 restrictions on the outer most expression, which must either be:
   1. A deref followed by any non-deref place projection (that intermediate deref will typically be auto-inserted)
   2. A method call annotated with `#[rustc_no_implicit_refs]`.
   3. A deref followed by a `addr_of!` or `addr_of_mut!`. See bottom of post for details.

There are several points that are not 100% clear to me when implementing the modifications:
 - ~~"4. Any number of automatically inserted deref/derefmut calls." I as never able to trigger this. Am I missing something?~~ Fixed
 - Are "index" and "field" enough?

----

cc `@JakobDegen` `@WaffleLapkin`
r? `@RalfJung`

try-job: dist-various-1
try-job: dist-various-2
2025-04-28 08:25:23 +00:00
Oli Scherer
b023856f29 Add or-patterns to pattern types 2025-04-28 07:50:18 +00:00
Oli Scherer
cb6d3715a5 Split out various pattern type matches into their own function 2025-04-28 07:46:50 +00:00
Oli Scherer
6008592fca Separate pattern lowering from pattern type lowering 2025-04-28 07:36:59 +00:00
Oli Scherer
2134793792 Directly generate TyPat instead of TyPatKind 2025-04-28 07:36:59 +00:00
Oli Scherer
6338e364f0 Pull ast pattern type parsing out into a separate function 2025-04-28 07:36:59 +00:00
Oli Scherer
96918a4bd5 Prevent pattern type macro invocations from having trailing tokens 2025-04-28 07:36:59 +00:00
Nicholas Nethercote
bb04e11e47 Inline and remove three pretty-printer methods.
They all have a single call site, aren't that big, and removing them
avoids having to pass some `BoxMarker`s.
2025-04-28 15:51:27 +10:00
Nicholas Nethercote
61a66b188c Use PrintState::head in PrintState::block_to_string. 2025-04-28 15:51:27 +10:00
Nicholas Nethercote
aff1be2637 Introduce BoxMarker to pretty-printing.
The pretty-printers open and close "boxes" of text a lot. The open and
close operations must be matched. The matching is currently all implicit
and very easy to get wrong. (#140280 and #140246 are two recent
pretty-printing fixes that both involved unclosed boxes.)

This commit introduces `BoxMarker`, a marker type that represents an
open box. It makes box opening/closing explicit, which makes it much
easier to understand and harder to get wrong.

The commit also removes many comments are on `end` calls saying things
like "end outer head-block", "Close the outer-box". These demonstrate
how confusing the implicit approach was, but aren't necessary any more.
2025-04-28 15:51:25 +10:00
Chris Denton
5633102807
Rollup merge of #140345 - DaniPopes:get-def-path, r=Urgau
Avoid re-interning in `LateContext::get_def_path`

The def path printer in `get_def_path` essentially calls `Symbol::intern(&symbol.to_string())` for simple symbols in a path. This accounts for ~30% of the runtime of get_def_path.

We can avoid this by simply appending the symbol directly when available.
2025-04-28 01:58:50 +00:00
Michael Goulet
3ab6051b95 Move inline_asm to typeck, properly handle aliases 2025-04-27 22:05:07 +00:00
Trevor Gross
6ceeb0849e Implement the internal feature cfg_target_has_reliable_f16_f128
Support for `f16` and `f128` is varied across targets, backends, and
backend versions. Eventually we would like to reach a point where all
backends support these approximately equally, but until then we have to
work around some of these nuances of support being observable.

Introduce the `cfg_target_has_reliable_f16_f128` internal feature, which
provides the following new configuration gates:

* `cfg(target_has_reliable_f16)`
* `cfg(target_has_reliable_f16_math)`
* `cfg(target_has_reliable_f128)`
* `cfg(target_has_reliable_f128_math)`

`reliable_f16` and `reliable_f128` indicate that basic arithmetic for
the type works correctly. The `_math` versions indicate that anything
relying on `libm` works correctly, since sometimes this hits a separate
class of codegen bugs.

These options match configuration set by the build script at [1]. The
logic for LLVM support is duplicated as-is from the same script. There
are a few possible updates that will come as a follow up.

The config introduced here is not planned to ever become stable, it is
only intended to replace the build scripts for `std` tests and
`compiler-builtins` that don't have any way to configure based on the
codegen backend.

MCP: https://github.com/rust-lang/compiler-team/issues/866
Closes: https://github.com/rust-lang/compiler-team/issues/866

[1]: 555e1d0386/library/std/build.rs (L84-L186)
2025-04-27 19:58:44 +00:00
Andrew Zhogin
52c1838fa7 dropee_emit_retag function separated in drop glue build 2025-04-28 00:52:30 +07:00
Matthias Krüger
fdfc7c0044
Rollup merge of #140358 - Zoxc:variance-cycle, r=oli-obk
Use `search_for_cycle_permutation` to look for `variances_of`

This uses `search_for_cycle_permutation` to look for `variances_of` in case `variances_of` is not the first query in the cycle.

This may fix https://github.com/rust-lang/rust/issues/124423 and https://github.com/rust-lang/rust/issues/127971.

r? `@oli-obk`
2025-04-27 16:09:00 +02:00
Matthias Krüger
c006eb7010
Rollup merge of #140348 - ehuss:lint-docs-edition, r=compiler-errors
Update lint-docs to default to Rust 2024

This updates the lint-docs tool to default to the 2024 edition. The lint docs are supposed to illustrate the code with the latest edition, and I just forgot to update this in https://github.com/rust-lang/rust/pull/133349.

Some docs needed to add the `edition` attribute since they were assuming a particular edition, but were missing the explicit annotation.

This also includes a commit to simplify the edition handling in lint-docs.
2025-04-27 16:09:00 +02:00
Matthias Krüger
405c8afce3
Rollup merge of #140280 - nnethercote:improve-if-else-printing, r=Urgau
Improve if/else pretty printing

AST/HIR pretty printing of if/else is currently pretty bad. This PR improves it a lot.

r? `@Nadrieril`
2025-04-27 16:08:59 +02:00
Matthias Krüger
4f7aed6791
Rollup merge of #140246 - nnethercote:fix-never-pattern-printing, r=Nadrieril
Fix never pattern printing

It's currently broken, but there's an easy fix.

r? `@Nadrieril`
2025-04-27 16:08:58 +02:00
Matthias Krüger
aa5c6d44cf
Rollup merge of #140346 - petrochenkov:cleanhyg, r=compiler-errors
rustc_span: Some hygiene cleanups

Mostly enabled by #139241 and #139281.
2025-04-27 11:55:00 +02:00
Matthias Krüger
1e677438f8
Rollup merge of #140339 - petrochenkov:capanew, r=lqd
session: Cleanup `CanonicalizedPath::new`

It wants an owned path, so pass an owned path.
2025-04-27 11:54:59 +02:00
John Kåre Alsaker
c33b4f870e Use search_for_cycle_permutation to look for variances_of 2025-04-27 09:38:18 +02:00
bors
496145b9cc Auto merge of #139646 - lcnr:default-is-fully-concrete, r=BoxyUwU
check types of const param defaults

fixes #139643 by checking that the type of a const parameter default matches the type of the parameter as long as both types are fully concrete

r? `@BoxyUwU`
2025-04-27 01:59:43 +00:00
bors
43e62a789c Auto merge of #140288 - Zalathar:new-executor, r=jieyouxu
compiletest: Re-land using the new non-libtest executor by default

This PR re-lands #139998, which had the misfortune of triggering download-rustc in its CI jobs, so we didn't get proper test metrics for comparison with the old implementation. So that was PR was reverted in #140233, with the intention of re-landing it alongside a dummy compiler change to inhibit download-rustc.

---

Original PR description for #139998:
>The new executor was implemented in #139660, but required a manual opt-in. This PR activates the new executor by default, but leaves the old libtest-based executor in place (temporarily) to make reverting easier if something unexpectedly goes horribly wrong.
>
>Currently the new executor can be explicitly disabled by passing the `-N` flag to compiletest (e.g. `./x test ui -- -N`), but eventually that flag will be removed, alongside the removal of the libtest dependency. The flag is mostly there to make manual comparative testing easier if something does go wrong.
>
>As before, there *should* be no user-visible difference between the old executor and the new executor.

---
r? jieyouxu
2025-04-26 22:33:56 +00:00
Eric Huss
1f108fe08a Update lint-docs to default to Rust 2024
This updates the lint-docs tool to default to the 2024 edition. The lint
docs are supposed to illustrate the code with the latest edition, and I
just forgot to update this in
https://github.com/rust-lang/rust/pull/133349.

Some docs needed to add the `edition` attribute since they were assuming
a particular edition, but were missing the explicit annotation.
2025-04-26 14:08:58 -07:00
Vadim Petrochenkov
7148908ace hygiene: Use IndexVec for syntax context decode cache 2025-04-26 23:32:49 +03:00
DaniPopes
6f5698c368
Avoid re-interning in LateContext::get_def_path
The def path printer in `get_def_path` essentially calls
`Symbol::intern(&symbol.to_string())` for simple symbols in a path.
This accounts for ~30% of the runtime of get_def_path.

We can avoid this by simply appending the symbol directly when available.
2025-04-26 22:06:44 +02:00
Vadim Petrochenkov
c7ad140473 hygiene: Misc cleanups
Inline some functions used once.
Use `impl Trait` more.
Tweak some comments.
2025-04-26 23:00:51 +03:00
Vadim Petrochenkov
2e8c53cf07 hygiene: Remove decode placeholders
They are no longer necessary after #139281
2025-04-26 23:00:51 +03:00
Vadim Petrochenkov
86969dbe77 session: Cleanup CanonicalizedPath::new
It wants an owned path, so pass an owned path
2025-04-26 18:42:15 +03:00
Matthias Krüger
3c322bc1cc
Rollup merge of #140320 - lcnr:wf-use-term, r=compiler-errors
replace `GenericArg` with `Term` where applicable

r? types
2025-04-26 16:12:33 +02:00
Matthias Krüger
443358d25d
Rollup merge of #140318 - compiler-errors:specialized-async-fn-kind-err, r=fee1-dead
Simply try to unpeel AsyncFnKindHelper goal in `emit_specialized_closure_kind_error`

Tweak the handling of `AsyncFnKindHelper` goals in `emit_specialized_closure_kind_error` to not be so special-casey, and just try to unpeel one or two layers of obligation causes to get to their underlying `AsyncFn*` goal.

Fixes https://github.com/rust-lang/rust/issues/140292
2025-04-26 16:12:33 +02:00
Matthias Krüger
fbf68324fc
Rollup merge of #140317 - mejrs:check_on_uni, r=compiler-errors
Remove redundant check

We still check for `rustc_on_unimplemented` on implementations, but this functionality was removed in https://github.com/rust-lang/rust/pull/139091, since then it always returns `Ok` when called with a non-trait defid.

b4c8b0c3f0/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs (L557-L564)
2025-04-26 16:12:32 +02:00
Matthias Krüger
cbf5d72af2
Rollup merge of #140215 - joshlf:transmutability-char-nonzero, r=jswrenn
transmutability: Support char, NonZeroXxx

Note that `NonZero` support is not wired up, as the author encountered
bugs while attempting this. A future commit will wire up `NonZero`
support.

r? ````@jswrenn````
2025-04-26 16:12:31 +02:00
yuk1ty
bffb7608ce Fix error message for static references or mutable references 2025-04-26 14:48:30 +09:00
bors
5ae50d3b21 Auto merge of #140324 - matthiaskrgr:rollup-jlzvdre, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #139865 (Stabilize proc_macro::Span::{start,end,line,column}.)
 - #140086 (If creating a temporary directory fails with permission denied then retry with backoff)
 - #140216 (Document that "extern blocks must be unsafe" in Rust 2024)
 - #140253 (Add XtensaAsmPrinter)
 - #140272 (Improve error message for `||` (or) in let chains)
 - #140305 (Track per-obligation recursion depth only if there is inference in the new solver)
 - #140306 (handle specialization in the new trait solver)
 - #140308 (stall generator witness obligations: add regression test)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-26 05:18:22 +00:00
Matthias Krüger
54eae599e0
Rollup merge of #140306 - lcnr:specialization-new, r=compiler-errors
handle specialization in the new trait solver

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/187
also fixes the regression in `plonky2_field` from https://github.com/rust-lang/trait-system-refactor-initiative/issues/188

cc https://github.com/rust-lang/rust/pull/111994

r? ```@compiler-errors```
2025-04-26 07:13:09 +02:00
Matthias Krüger
f2f4152290
Rollup merge of #140305 - compiler-errors:coerce-loop, r=lcnr
Track per-obligation recursion depth only if there is inference in the new solver

Track how many times an obligation has been processed in the fulfillment context by reusing its recursion depth, and only overflow if a singular (root) goal hits the limit.

This also fixes a (probably theoretical at this point) problem where we don't detect pseudo-hangs across `select_where_possible` calls.

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/186

r? lcnr
2025-04-26 07:13:09 +02:00
Matthias Krüger
6f6fa0f23a
Rollup merge of #140272 - Kivooeo:new-fix-four, r=est31
Improve error message for `||` (or) in let chains

**Description**

This PR improves the error message when using `||` in an if let chain expression, addressing #140263.

**Changes**

1. Creates a dedicated error message specifically for `||` usage in let chains
2. Points the primary span directly at the `||` operator
3. Removes confusing secondary notes about "let statements" and unsupported contexts
5. Adds UI tests verifying the new error message and valid cases

**Before**
```rust
error: expected expression, found let statement
 --> src/main.rs:2:8
  |
2 |     if let true = true || false {}
  |        ^^^^^^^^^^^^^^^
  |
  = note: only supported directly in conditions of if and while expressions
note: || operators are not supported in let chain expressions
 --> src/main.rs:2:24
  |
2 |     if let true = true || false {}
  |
```

**After**
```rust
error: `||` operators are not supported in let chain conditions
 --> src/main.rs:2:24
  |
2 |     if let true = true || false {}
  |                        ^^
```

**Implementation details**
1. Added new `OrInLetChain` diagnostic in errors.rs

2. Modified `CondChecker` in expr.rs to prioritize the `||` error

3. Updated fluent message definitions to use clearer wording

**Related issue**
Fixes #140263

cc ```@ehuss``` (issue author)
2025-04-26 07:13:08 +02:00
Matthias Krüger
82a87f3ae3
Rollup merge of #140253 - SergioGasquez:feat/xtensa-asm-printer, r=cuviper
Add XtensaAsmPrinter

See https://github.com/rust-lang/rust/pull/133601. The PR was closed because it required LLVM 19 in CI added with (12167d7064)
2025-04-26 07:13:08 +02:00
Matthias Krüger
e970d63b61
Rollup merge of #140086 - ChrisDenton:backoff, r=petrochenkov
If creating a temporary directory fails with permission denied then retry with backoff

On Windows, if creating a temporary directory fails with permission denied then use a retry/backoff loop. This hopefully fixes a recuring error in our CI.

cc ```@jieyouxu,``` https://github.com/rust-lang/rust/issues/133959
2025-04-26 07:13:07 +02:00
lcnr
85fa3958b1 remove unnecessary match 2025-04-26 02:05:31 +00:00
lcnr
855035b038 convert some GenericArg to Term 2025-04-26 02:05:31 +00:00
bors
d3508a8ad0 Auto merge of #140177 - tmandry:compiletest-par, r=jieyouxu
[compiletest] Parallelize test discovery

Certain filesystems are slow to service individual read requests, but can service many in parallel. This change brings down the time to run a single cached test on one of those filesystems from 40s to about 8s.
2025-04-26 02:03:54 +00:00
Michael Goulet
4b309c67c6 Simply try to unpeel AsyncFnKindHelper goal in emit_specialized_closure_kind_error 2025-04-26 01:42:52 +00:00
mejrs
1ec3e626c2 Remove redundant check 2025-04-26 01:57:08 +02:00
bors
555e1d0386 Auto merge of #140295 - antoyo:subtree-update_cg_gcc_2025-04-25, r=GuillaumeGomez
Subtree update cg_gcc 2025/04/25

r? GuillaumeGomez
2025-04-25 21:58:13 +00:00
Nicholas Nethercote
7ac2d1f1bd Improve HIR pretty-printing of if/else some more.
In the AST the "then" block is represented as a `Block`. In HIR the
"then" block is represented as an `Expr` that happens to always be.
`ExprKind::Block`. By deconstructing the `ExprKind::Block` to extract
the block within, things print properly.

For `issue-82392.rs`, note that we no longer print a type after the
"then" block. This is good, it now matches how we don't print a type for
the "else" block. (Well, we do print a type after the "else" block, but
it's for the whole if/else.)

Also tighten up some of the pattern matching -- these block expressions
within if/else will never have labels.
2025-04-26 06:35:44 +10:00
Joshua Liebow-Feeser
ae0c2fe3d8 transmutability: Support char, NonZeroXxx
Note that `NonZero` support is not wired up, as the author encountered
bugs while attempting this. A future commit will wire up `NonZero`
support.
2025-04-25 12:55:50 -07:00
bors
b4c8b0c3f0 Auto merge of #140298 - matthiaskrgr:rollup-5tc1gvb, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #137683 (Add a tidy check for GCC submodule version)
 - #138968 (Update the index of Result to make the summary more comprehensive)
 - #139572 (docs(std): mention const blocks in const keyword doc page)
 - #140152 (Unify the format of rustc cli flags)
 - #140193 (fix ICE in `#[naked]` attribute validation)
 - #140205 (Tidying up UI tests [2/N])
 - #140284 (remove expect() in `unnecessary_transmutes`)
 - #140290 (rustdoc: fix typo change from equivelent to equivalent)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-25 18:51:15 +00:00
Michael Goulet
31c8d10342 Track per-obligation recursion depth only if there is inference 2025-04-25 18:14:39 +00:00
lcnr
009db53e49 handle specialization in the new trait solver
uwu :3
2025-04-25 17:59:33 +00:00
bors
e3e432d4d6 Auto merge of #139756 - Zoxc:out-of-order-dep-graph, r=oli-obk
Allow out of order dep graph node encoding

This allows out of order dep graph node encoding by also encoding the index instead of using the file node order as the index.

`MemEncoder` is also brought back to life and used for encoding.

Both of these are done to enable thread-local encoding of dep graph nodes.

This is based on https://github.com/rust-lang/rust/pull/139636.
2025-04-25 15:38:58 +00:00
Matthias Krüger
432393972c
Rollup merge of #140284 - bend-n:fix-expectation-unmet, r=jieyouxu
remove expect() in `unnecessary_transmutes`

removes expect() from #136083 and fixes #140277
includes regression test

r? lcnr
2025-04-25 17:31:49 +02:00
Matthias Krüger
7f27d16400
Rollup merge of #140193 - folkertdev:fix-issue-140082, r=jdonszelmann
fix ICE in `#[naked]` attribute validation

fixes https://github.com/rust-lang/rust/issues/140082

The comment here https://github.com/rust-lang/rust/pull/139615/files#r2040684192 is relevant, a better way to print the full path would be nice. If there's an issue I should `FIXME` this with let me know.

r? `@jdonszelmann`
cc `@nnethercote` https://github.com/rust-lang/rust/pull/139615
2025-04-25 17:31:48 +02:00
Matthias Krüger
eb225e395d
Rollup merge of #140152 - xizheyin:issue-140102, r=jieyouxu
Unify the format of rustc cli flags

As mentioned in #140102, I unified the format of rustc CLI flags.

I use the following rules:
1. `<param>`: Indicates a required parameter
2. `[param]`: Indicates an optional parameter
3. `|`: Indicates a mutually exclusive option
4. `*`: a list element with description

Current output:
```bash
Usage: rustc [OPTIONS] INPUT

Options:
    -h, --help          Display this message
        --cfg <SPEC>    Configure the compilation environment.
                        SPEC supports the syntax `<NAME>[="<VALUE>"]`.
        --check-cfg <SPEC>
                        Provide list of expected cfgs for checking
    -L [<KIND>=]<PATH>  Add a directory to the library search path. The
                        optional KIND can be one of
                        <dependency|crate|native|framework|all> (default:
                        all).
    -l [<KIND>[:<MODIFIERS>]=]<NAME>[:<RENAME>]
                        Link the generated crate(s) to the specified native
                        library NAME. The optional KIND can be one of
                        <static|framework|dylib> (default: dylib).
                        Optional comma separated MODIFIERS
                        <bundle|verbatim|whole-archive|as-needed>
                        may be specified each with a prefix of either '+' to
                        enable or '-' to disable.
        --crate-type <bin|lib|rlib|dylib|cdylib|staticlib|proc-macro>
                        Comma separated list of types of crates
                        for the compiler to emit
        --crate-name <NAME>
                        Specify the name of the crate being built
        --edition <2015|2018|2021|2024|future>
                        Specify which edition of the compiler to use when
                        compiling code. The default is 2015 and the latest
                        stable edition is 2024.
        --emit <TYPE>[=<FILE>]
                        Comma separated list of types of output for the
                        compiler to emit.
                        Each TYPE has the default FILE name:
                        * asm - CRATE_NAME.s
                        * llvm-bc - CRATE_NAME.bc
                        * dep-info - CRATE_NAME.d
                        * link - (platform and crate-type dependent)
                        * llvm-ir - CRATE_NAME.ll
                        * metadata - libCRATE_NAME.rmeta
                        * mir - CRATE_NAME.mir
                        * obj - CRATE_NAME.o
                        * thin-link-bitcode - CRATE_NAME.indexing.o
        --print <INFO>[=<FILE>]
                        Compiler information to print on stdout (or to a file)
                        INFO may be one of
                        <all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models>.
    -g                  Equivalent to -C debuginfo=2
    -O                  Equivalent to -C opt-level=3
    -o <FILENAME>       Write output to FILENAME
        --out-dir <DIR> Write output to compiler-chosen filename in DIR
        --explain <OPT> Provide a detailed explanation of an error message
        --test          Build a test harness
        --target <TARGET>
                        Target triple for which the code is compiled
    -A, --allow <LINT>  Set lint allowed
    -W, --warn <LINT>   Set lint warnings
        --force-warn <LINT>
                        Set lint force-warn
    -D, --deny <LINT>   Set lint denied
    -F, --forbid <LINT> Set lint forbidden
        --cap-lints <LEVEL>
                        Set the most restrictive lint level. More restrictive
                        lints are capped at this level
    -C, --codegen <OPT>[=<VALUE>]
                        Set a codegen option
    -V, --version       Print version info and exit
    -v, --verbose       Use verbose output

Additional help:
    -C help             Print codegen options
    -W help             Print 'lint' options and default settings
    -Z help             Print unstable compiler options
    --help -v           Print the full set of options rustc accepts
```
2025-04-25 17:31:47 +02:00
Antoni Boucher
3cd97b644d Merge commit '4f83a4258deb99f3288a7122c0d5a78200931c61' into subtree-update_cg_gcc_2025-04-25 2025-04-25 10:44:19 -04:00
bors
8f43b85954 Auto merge of #140282 - matthiaskrgr:rollup-g6ze4jj, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #137653 (Deprecate the unstable `concat_idents!`)
 - #138957 (Update the index of Option to make the summary more comprehensive)
 - #140006 (ensure compiler existance of tools on the dist step)
 - #140143 (Move `sys::pal::os::Env` into `sys::env`)
 - #140202 (Make #![feature(let_chains)] bootstrap conditional in compiler/)
 - #140236 (norm nested aliases before evaluating the parent goal)
 - #140257 (Some drive-by housecleaning in `rustc_borrowck`)
 - #140278 (Don't use item name to look up associated item from trait item)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-25 12:27:16 +00:00
Bastian Kersting
a3e7c699bc Extend the alignment check to borrows
The current alignment check does not include checks for creating
misaligned references from raw pointers, which is now added in this
patch.

When inserting the check we need to be careful with references to
field projections (e.g. `&(*ptr).a`), in which case the resulting
reference must be aligned according to the field type and not the
type of the pointer.
2025-04-25 12:16:40 +00:00
bendn
d3a4ebca85
remove expect() in unnecessary_transmutes 2025-04-25 19:07:41 +07:00
Kivooeo
f072d30741 resolved conflict 2025-04-25 17:02:59 +05:00
xizheyin
999b9069dd
Add option style comment for rustc_optgroups
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-25 19:37:42 +08:00
Chris Denton
c07054bdd1
Retry if creating temp fails with access denied
On Windows, if creating a temporary directory fails with permission denied then use a retry/backoff loop. This hopefully fixes a recuring error in our CI.
2025-04-25 11:28:36 +00:00
Zalathar
1670de40e0 Trivial compiler change to inhibit download-rustc in CI 2025-04-25 20:41:50 +10:00
bors
5c54aa781f Auto merge of #140273 - matthiaskrgr:rollup-rxmuvkg, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #137096 (Stabilize flags for doctest cross compilation)
 - #140148 (CI: use aws codebuild for job dist-arm-linux)
 - #140187 ([AIX] Handle AIX dynamic library extensions within c-link-to-rust-dylib run-make test)
 - #140196 (Improved diagnostics for non-primitive cast on non-primitive types (`Arc`, `Option`))
 - #140210 (Work around cygwin issue on condvar timeout)
 - #140213 (mention about `x.py setup` in `INSTALL.md`)
 - #140229 (`DelimArgs` tweaks)
 - #140248 (Fix impl block items indent)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-25 09:09:27 +00:00
Matthias Krüger
3c08a50a15
Rollup merge of #140278 - compiler-errors:name-based-comparison, r=nnethercote
Don't use item name to look up associated item from trait item

This fix should be self-justifying b/c the fact that we were using identifiers here was kinda sus anyways, esp b/c we have a failproof way of doing the comparison :) I'll leave some info about why this repro needs a macro.

Fixes https://github.com/rust-lang/rust/issues/140259

r? `@nnethercote`
2025-04-25 07:50:27 +02:00
Matthias Krüger
e534fad2e5
Rollup merge of #140257 - amandasystems:housecleaning, r=wesleywiser
Some drive-by housecleaning in `rustc_borrowck`

This commit picks up a few odd ends discovered during the work on #130227. It adds some documentation and renames a few methods with too generic names to describe what they actually do. It also adds some debug output that was helpful during bug hunting and generally cleans up a few things (for my values of "clean").

r? lcnr
2025-04-25 07:50:27 +02:00
Matthias Krüger
9eb0078556
Rollup merge of #140236 - lcnr:normalizes-to-goals, r=compiler-errors
norm nested aliases before evaluating the parent goal

see the explanation of the underlying issue in tests/ui/traits/next-solver/normalize/eager-norm-pre-normalizes-to.rs.

This is also the cause of https://github.com/rust-lang/trait-system-refactor-initiative/issues/184, fixing the overflow errors with the new solver. I did not add any tests based on it directly as relying on that behavior to cause recursion limit shenanigans feels fragile. Thanks `@Nadrieril` for minimizing the issue [on zulip](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/typenum.20.602.20.2F.201.60.20overflow.20error/with/513993621).

r? `@compiler-errors`
2025-04-25 07:50:26 +02:00
Matthias Krüger
564e5ccb5c
Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr
Make #![feature(let_chains)] bootstrap conditional in compiler/

Let chains have been stabilized recently in #132833, so we can remove the gating from our uses in the compiler (as the compiler uses edition 2024).
2025-04-25 07:50:25 +02:00
Matthias Krüger
f3641df491
Rollup merge of #140143 - thaliaarchi:move-env-pal, r=joboet
Move `sys::pal::os::Env` into `sys::env`

Although `Env` (as `Vars`), `Args`, path functions, and OS constants are publicly exposed via `std::env`, their implementations are each self-contained. Keep them separate in `std::sys` and make a new module, `sys::env`, for `Env`.

Also fix `unsafe_op_in_unsafe_fn` for Unix and update the `!DynSend` and `!DynSync` impls which had grown out of sync with the platforms (see #48005 for discussion on that).

r? joboet

Tracked in #117276.
2025-04-25 07:50:25 +02:00
bit-aloo
9bc04016e6
add custom enzyme markers to target methods 2025-04-25 11:09:52 +05:30
bit-aloo
f319dd909e
add llvm wrappers and corresponding methods in attribute 2025-04-25 11:09:52 +05:30
John Kåre Alsaker
c8e7c6261e Zero the buffer passed from write_with 2025-04-25 07:14:27 +02:00
Nicholas Nethercote
e37c367482 Improve pretty printing of if/else.
By removing some of the over-indenting. AST pretty printing now looks
correct. HIR pretty printing is better, but still over-indents some.
2025-04-25 14:33:16 +10:00
Nicholas Nethercote
ee43aa356a Fix some pretty printing indents.
Indents for `cbox` and `ibox` are 0 or `INDENT_UNIT` (4) except for a
couple of places which are `INDENT_UNIT - 1` for no clear reason.

This commit changes the three space indents to four spaces.
2025-04-25 14:33:16 +10:00
Michael Goulet
1d0b3be659 Don't use item name to look up associated item from trait item 2025-04-25 01:57:45 +00:00
bors
847e3ee6b0 Auto merge of #139752 - usamoi:macos-used, r=saethlin,madsmtm
set subsections_via_symbols for ld64 helper sections

closes https://github.com/rust-lang/rust/issues/139744
cc `@madsmtm`
2025-04-24 22:59:00 +00:00
Matthias Krüger
c43022f8cb
Rollup merge of #140229 - nnethercote:pre-DelimArgs-spacing, r=petrochenkov
`DelimArgs` tweaks

r? `@petrochenkov`
2025-04-25 00:54:01 +02:00
Matthias Krüger
02ebca2784
Rollup merge of #140196 - Kivooeo:new-fix-two, r=wesleywiser
Improved diagnostics for non-primitive cast on non-primitive types (`Arc`, `Option`)

here is a small fix that improving error messaging when user is trying to do something like this
```rust
let _ = "x" as Arc<str>;
let _ = 2 as Option<i32>;
```

before it looks like this
```rust
error[E0605]: non-primitive cast: `&'static str` as `Arc<str>`
 --> src\main.rs:3:13
  |
3 |     let _ = "x" as Arc<str>;
  |             ^^^^^^^^^^^^^^^ help: consider using the `From` trait instead: `Arc<str>::from("x")`

error[E0605]: non-primitive cast: `i32` as `Option<i32>`
 --> src\main.rs:4:13
  |
4 |     let _ = 2 as Option<i32>;
```
which looks horrible to be honest
so i made a small fix that make errors looks like this
```rust
error[E0605]: non-primitive cast: `&'static str` as `Arc<str>`
  |
3 |     let _ = "x" as Arc<str>;
  |             ^^^^^^^^^^^^^^^
  |
  = note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
help: consider using the `From` trait instead
  |
3 -     let _ = "x" as Arc<str>;
3 +     let _ = Arc::<str>::from("x");
  |

error[E0605]: non-primitive cast: `i32` as `Option<i32>`
  |
4 |     let _ = 2 as Option<i32>;
  |             ^^^^^^^^^^^^^^^^
  |
  = note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
help: consider using the `From` trait instead
  |
4 -     let _ = 2 as Option<i32>;
4 +     let _ = Option::<i32>::from(2);
```

**What improves?**
1) `Arc<str>::from("x")` which makes no sense because of missing `::`
2) readability

**Related Issue**
fixes #135412
2025-04-25 00:53:59 +02:00
dianne
0eb3b110f0 lower deref patterns on boxes using built-in derefs
This allows deref patterns to move out of boxes.

Implementation-wise, I've opted to put the information of whether a
deref pattern uses a built-in deref or a method call in the THIR. It'd
be a bit less code to check `.is_box()` everywhere, but I think this way
feels more robust (and we don't have a `mutability` field in the THIR
that we ignore when the smart pointer's a box). I'm not sure about the
naming (or using `ByRef`), though.
2025-04-24 14:25:27 -07:00
lcnr
e5e3a95c1e norm nested aliases before evaluating the parent goal 2025-04-24 18:41:43 +00:00
usamoi
b1a38313cb set subsections_via_symbols for ld64 helper sections 2025-04-25 01:41:25 +08:00
Amanda Stjerna
d8528c6a31 Some drive-by housecleaning in rustc_borrowck
This commit picks up a few odd ends discovered during the work on #130227.
It adds some documentation and renames a few methods with too generic names
to describe what they actually do. It also adds some debug output that was
helpful during bug hunting.
2025-04-24 17:27:49 +02:00
Matthias Krüger
cea6ba7a06
Rollup merge of #140172 - bjoernager:const-float-algebraic, r=RalfJung
Make algebraic functions into `const fn` items.

Tracking issue: #136469

This PR makes the algebraic intrinsics and the unstable, algebraic functions of `f16`, `f32`, `f64`, and `f128` into `const fn` items:

```rust
impl f16 {
    pub const fn algebraic_add(self, rhs: f16) -> f16;
    pub const fn algebraic_sub(self, rhs: f16) -> f16;
    pub const fn algebraic_mul(self, rhs: f16) -> f16;
    pub const fn algebraic_div(self, rhs: f16) -> f16;
    pub const fn algebraic_rem(self, rhs: f16) -> f16;
}

impl f32 {
    pub const fn algebraic_add(self, rhs: f32) -> f32;
    pub const fn algebraic_sub(self, rhs: f32) -> f32;
    pub const fn algebraic_mul(self, rhs: f32) -> f32;
    pub const fn algebraic_div(self, rhs: f32) -> f32;
    pub const fn algebraic_rem(self, rhs: f32) -> f32;
}

impl f64 {
    pub const fn algebraic_add(self, rhs: f64) -> f64;
    pub const fn algebraic_sub(self, rhs: f64) -> f64;
    pub const fn algebraic_mul(self, rhs: f64) -> f64;
    pub const fn algebraic_div(self, rhs: f64) -> f64;
    pub const fn algebraic_rem(self, rhs: f64) -> f64;
}

impl f128 {
    pub const fn algebraic_add(self, rhs: f128) -> f128;
    pub const fn algebraic_sub(self, rhs: f128) -> f128;
    pub const fn algebraic_mul(self, rhs: f128) -> f128;
    pub const fn algebraic_div(self, rhs: f128) -> f128;
    pub const fn algebraic_rem(self, rhs: f128) -> f128;
}

// core::intrinsics

pub const fn fadd_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn fsub_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn fmul_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn fdiv_algebraic<T: Copy>(a: T, b: T) -> T;
pub const fn frem_algebraic<T: Copy>(a: T, b: T) -> T;
```

This PR does not preserve the initial behaviour of these functions yielding non-deterministic output under Miri; it is most likely desired to reimplement this behaviour at some point.
2025-04-24 17:19:46 +02:00
Matthias Krüger
31a72bc45c
Rollup merge of #140139 - a4lg:riscv-feature-imply-adjust-1, r=Amanieu
rustc_target: Adjust RISC-V feature implication

This commit adjusts feature implication of the RISC-V ISA for better feature detection from the user perspective.

The main rule is:

*   If the feature `A` is a functional superset of the feature `B` (`A ⊃ B`),
    `A` is to imply `B`, even if this implication is not on the manual.

Such implications (not directly written in the ISA manual) are commented as `A ⊃ B`
which means "`A` is a (functional) superset of `B`".

1.  `Zbc` → `Zbkc` (add as a superset)
    The `Zbkc` extension is a subset of the `Zbc` extension (`Zbc` minus `clmulr` instruction).
2.  `Zkr` → (nothing) (remove dependency to `Zicsr`)
    Implication to the `Zicsr` extension is removed because (although nearly harmless), the `Zkr` extension (or the `seed` CSR section) defines its own subset of the `Zicsr` extension (guaranteed to work against the `seed` CSR which needs read/write access).
3.  `Zvbb` → `Zvkb` (comment as a superset)
    This implication was already there but not denoted as a functional superset.  This commit adds the comment.
4.  `Zvfh` → `Zvfhmin` (comment as a superset)
    This is similar to the case above (`Zvbb` → `Zvkb`).
5.  `Zvfh` → `Zve32f` (add implication per the ISA specification)
    This dependency is on the ISA manual but was missing (due to the fact that `Zvfh` indirectly implies `Zve32f` on the current implementation through `Zvfh` → `Zvfhmin` which is a functional relation). This commit ensures that this is *also* ISA-compliant in the source code level (there's no functional changes though).
6.  `Zvknhb` → `Zvknha` (add as a superset)
    The `Zvknhb` extension (SHA-256 / SHA-512) is a functional superset of the `Zvknha` extension (SHA-256 only).
2025-04-24 17:19:44 +02:00
Matthias Krüger
c3f811f02f
Rollup merge of #139700 - EnzymeAD:autodiff-flags, r=oli-obk
Autodiff flags

Interestingly, it seems that some other projects have conflicts with exactly the same LLVM optimization passes as autodiff.
At least `LLVMRustOptimize` has exactly the flags that we need to disable problematic opt passes.

This PR enables us to compile code where users differentiate two identical functions in the same module. This has been especially common in test cases, but it's not impossible to encounter in the wild.

It also enables two new flags for testing/debugging. I consider writing an MCP to upgrade PrintPasses to be a standalone -Z flag, since it is *not* the same as `-Z print-llvm-passes`, which IMHO gives less useful output. A discussion can be found here: [#t-compiler/llvm > Print llvm passes. @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/187780-t-compiler.2Fllvm/topic/Print.20llvm.20passes.2E/near/511533038)

Finally, it improves `PrintModBefore` and `PrintModAfter`. They used to work reliable, but now we just schedule enzyme as part of an existing ModulePassManager (MPM). Since Enzyme is last in the MPM scheduling, PrintModBefore became very inaccurate. It used to print the input module, which we gave to the Enzyme and was great to create llvm-ir reproducer. However, lately the MPM would run the whole `default<O3>` pipeline, which heavily modifies the llvm module, before we pass it to Enzyme. That made it impossible to use the flag to create llvm-ir reproducers for Enzyme bugs. We now schedule a PrintModule pass just before Enzyme, solving this problem.

Based on the PrintPass output, it also _seems_ like changing `registerEnzymeAndPassPipeline(PB, true);` to `registerEnzymeAndPassPipeline(PB, false);` has no effect. In theory, the bool should tell Enzyme to schedule some helpful passes in the PassBuilder. However, since it doesn't do anything and I'm not 100% sure anymore on whether we really need it, I'll just disable it for now and postpone investigations.

r? ``@oli-obk``

closes #139471

Tracking:

- https://github.com/rust-lang/rust/issues/124509
2025-04-24 17:19:44 +02:00
Matthias Krüger
27eac4b6d3
Rollup merge of #138282 - beetrees:repr128-not-ffi-safe, r=oli-obk
Add `#[repr(u128)]`/`#[repr(i128)]` enums to `improper_ctypes_definitions`

This makes them warn whenever a plain `u128`/`i128` would. If the lang team decides to merge #137306 then this can be reverted.

Tracking issue: #56071
2025-04-24 17:19:43 +02:00
Matthias Krüger
53afa97eb7
Rollup merge of #136083 - bend-n:⃤⃤, r=lcnr
Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc

implements #136067

Rust has helper methods for many kinds of safe transmutes, for example integer<->bytes. This is a lint against using transmute for these cases.

```rs
fn bytes_at_home(x: [u8; 4]) -> u32 {
   transmute(x)
}

// other examples
transmute::<[u8; 2], u16>();
transmute::<[u8; 8], f64>();
transmute::<u32, [u8; 4]>();
transmute::<char, u32>();
transmute::<u32, char>();
```
It would be handy to suggest `u32::from_ne_bytes(x)`.
This is implemented for `[u8; _]` -> `{float int}`

This also implements the cases:
`fXX` <-> `uXX` = `{from_bits, to_bits}`
`uXX` -> `iXX` via `cast_unsigned` and `cast_signed`
{`char` -> `u32`, `bool` -> `n8`} via `from`
`u32` -> `char` via `from_u32_unchecked` (note: notes `from_u32().unwrap()`) (contested)
`u8` -> `bool` via `==` (debatable)

---
try-job: aarch64-gnu
try-job: test-various
2025-04-24 17:19:42 +02:00