Commit Graph

14970 Commits

Author SHA1 Message Date
bors 6159a44067 Auto merge of #148434 - oli-obk:inherent-const-impl, r=fee1-dead
Inherent const impl

Some constifications are annoying because we need to repeat `T: Trait` bounds from an impl block on the individual constified `const fn`s as `T: [const] Trait`. We've brainstormed solutions before, and one would be to have separate `const impl` blocks or sth. However the final syntax will look, I decided to just impl this syntax and either have sth nice on nightly to work with or at least move the discussion along.

Also interacts with the discussion around `impl const Trait for Type` vs `const impl Trait for Type`, as we may want to use the latter to keep inherent and trait impls in sync (unless we come up with even another scheme).

* [ ] rustdoc + tests
* [ ] macro stability /regression tests

r? `@fee1-dead`

cc `@traviscross` `@rust-lang/project-const-traits`
2025-11-19 02:23:56 +00:00
Oli Scherer b41c2a2870 Forbid const fn within const impls 2025-11-18 16:00:18 +00:00
Oli Scherer ababa26251 Collect const_conditions for inherent impls 2025-11-18 16:00:18 +00:00
Oli Scherer 939afab37e Treat inherent methods in const impl blocks as const 2025-11-18 16:00:18 +00:00
Oli Scherer 00157d4a3d Allow inherent const impl blocks 2025-11-18 16:00:18 +00:00
Matthias Krüger 642300e339 Rollup merge of #148484 - JonathanBrouwer:wip_attr_style, r=jdonszelmann
Fix suggestion for the `cfg!` macro

r? `@jdonszelmann`
2025-11-18 16:52:11 +01:00
Oli Scherer 2a36d33930 Give all impls a constness 2025-11-18 09:20:21 +00:00
Oli Scherer 08c391ca09 Temporarily allow const impl and impl const at the same time to migrate 2025-11-18 09:20:21 +00:00
Camille Gillot e7991602ed Add THIR building test. 2025-11-18 00:32:51 +00:00
Camille Gillot 72444372ae Replace OffsetOf by an actual sum. 2025-11-18 00:10:03 +00:00
Matthias Krüger 0e0dac2efc Rollup merge of #148865 - lcnr:gat-inference-hack, r=BoxyUwU
move GAT inference prevention hack

The structure of `fn assemble_and_merge_candidates` is quite messy and the differences between `Host` and `NormalizesTo` goals is large enough that we should split them entirely. Intend to change this for https://github.com/rust-lang/trait-system-refactor-initiative/issues/245 by mentoring someone: https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/ask.20for.20help/near/554696331. Think it's still fine to merge this PR without that larger change.

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

r? `@BoxyUwU`
2025-11-17 18:07:33 +01:00
Matthias Krüger 3bc1eaa66a Rollup merge of #148698 - tiif:const_query_cycle, r=BoxyUwU
Fix query cycle when encounter unevaluated const

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/249

In this PR, the environment is dropped when evaluating const that does not have any generic parameter to fix the query cycle.
2025-11-17 18:07:33 +01:00
Stuart Cook b979e1ef06 Rollup merge of #148994 - folkertdev:abi-compatibility-cleanup, r=jieyouxu
Abi compatibility test cleanup

r? `@jieyouxu`

- moves `NonNull` (and some friends) into `minicore.rs` so it can be re-used.
- tests the abi compatibility of a couple more targets. It's useful to have a comprehensive overview of all ABIs that rust has some amount of support for, e.g. testing for c-variadic or guaranteed tail calls (cc https://github.com/rust-lang/rust/issues/148748)
2025-11-17 16:41:04 +11:00
Stuart Cook e34ef247cc Rollup merge of #148855 - ZuseZ4:autodiff-lto-error, r=bjorn3
Error if an autodiff user does not set lto=fat

Based on your feedback, I started to provide a nice error message for a lack of `lto=fat`, instead of us forcing it.

In a next step, we should replace  `RUSTFLAGS="-Zautodiff=Enable"` with another Cargo.toml setting, as discussed here: https://github.com/rust-lang/rust/issues/147487#issuecomment-3446558644

As another improvement, we should also figure out why rlib builds do not properly obey the fat=lto setting.

```````@bjorn3```````
2025-11-17 16:41:02 +11:00
Stuart Cook 2fbdc8a3ae Rollup merge of #148505 - cyrgani:pm-tests, r=madsmtm
add larger test for `proc_macro` `FromStr` implementations

Currently, there are only few tests that check the output of `TokenStream::from_str` and `Literal::from_str` (which is somewhat understandable as the rustc implementation just delegates these calls to the parser). In preparation for both the standalone backend (rust-lang/rust#130856) which will probably need to reimplement this logic as well as for removing panics from these functions (rust-lang/rust#58736), this PR adds a test which shows the various messy ways of how these functions report errors and the return values for successful parses.
Followup PRs such as rust-lang/rust#147859 will change more and more of these "diagnostic + error"s into `LexErrors`.

The test structure with the extra module is used to allow reusing it later easily for the standalone backend.
2025-11-17 16:41:00 +11:00
cyrgani 7194c921ca add larger test for proc_macro FromStr implementations 2025-11-16 23:14:51 +01:00
Matthias Krüger 79d765ed38 Rollup merge of #148703 - pitaj:rangefrom-overflow_checks, r=Mark-Simulacrum
Use `overflow_checks` intrinsic so `IterRangeFrom` yields MAX before panicking in debug

Based on rust-lang/rust#128666. For your convenience, here is the [diff from that PR](https://github.com/pitaj/rust/compare/intrinsic-overflow_checks...pitaj:rust:rangefrom-overflow_checks).

When `overflow_checks` are enabled, the following code will output as shown
```rust
for n in std::range::RangeFrom::from(253_u8..) {
    println!("{n}");
}
// 253
// 254
// 255
// panic
```

Which is a change from the current behavior, where it will panic after printing 254.

This behavior was [requested by the libs team](https://github.com/rust-lang/rust/issues/125687#issuecomment-2151118208)

r? `@Mark-Simulacrum`
2025-11-16 20:40:22 +01:00
Folkert de Vries 96c64272e2 abi/compatibility: test some additional targets 2025-11-16 13:13:59 +01:00
Folkert de Vries 4fd0dc1050 move NonNull into minicore 2025-11-16 13:13:18 +01:00
bors b25b6eab7f Auto merge of #148992 - Zalathar:rollup-c1aqvox, r=Zalathar
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#145954 (stabilize extern_system_varargs)
 - rust-lang/rust#148962 (fix(span): track unnormalized source len for dep-info)
 - rust-lang/rust#148969 (compiletest: Don't apply "emscripten" directives to `wasm32-unknown-unknown`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-16 10:19:40 +00:00
Stuart Cook a528a58a19 Rollup merge of #145954 - RalfJung:syscall-c-variadics, r=jackh726
stabilize extern_system_varargs

Based on top of https://github.com/rust-lang/rust/pull/144066. This has been already FCP'd over there, but `@workingjubilee` has some concerns regarding "system" varargs specifically (IIUC).

Reference PR: https://github.com/rust-lang/reference/pull/2069.
2025-11-16 20:30:53 +11:00
bors e1a2ec6051 Auto merge of #148259 - RalfJung:const-ptr-fragment, r=oli-obk
const-eval: fix and re-enable pointer fragment support

The pointer fragment support from https://github.com/rust-lang/rust/pull/144081 got disabled due to https://github.com/rust-lang/rust/issues/146291. This brings it back. To fix the issue, the per-byte provenance fragment tracking tracks *both* the provenance and raw address of the full pointer, so we can ensure that only fragments that are truly part of the same pointer are being merged.

r? `@oli-obk`
Cc `@theemathas`
Fixes https://github.com/rust-lang/const-eval/issues/72 again.
Also fixes https://github.com/rust-lang/rust/issues/147959.

`@traviscross` I assume this won't need another t-lang FCP since it already got FCP'd in rust-lang/rust#144081?
2025-11-16 07:09:45 +00:00
Peter Jaszkowiak 0e5c96c3ec IterRangeFrom: overflow panic after yielding MAX
check overflow after yielding MAX value
new `0_u8..` will yield `255` and only panic on the subsequent `next()`
2025-11-15 21:29:59 -07:00
Stuart Cook e00af8be3d Rollup merge of #148984 - Muscraft:update-annotate-snippets, r=Kivooeo
chore: Update annotate-snippets to 0.12.9

This PR updates `annotate-snippets` to `0.12.9`, which includes a fix for rust-lang/rust#148070.

fixes rust-lang/rust#148070
2025-11-16 14:40:06 +11:00
Stuart Cook 6ad2331ce8 Rollup merge of #148968 - scottmcm:try-block-brace-tests, r=Kivooeo
Add another *ExprWithBlock* test for `try` blocks

Looking to address this open item from rust-lang/rust#31436

> Add a test confirming that it's an `ExprWithBlock`, so works in a match arm without a comma

It turns out that rust-lang/rust#120540 addressed that one, but it made me think of this other case that probably ought to have some kind of test as well.
2025-11-16 14:40:05 +11:00
Stuart Cook 788788b37d Rollup merge of #148956 - folkertdev:reenable-wasm-abi-test, r=bjorn3
re-enable wasm abi test

The `wasm32-unknown-unknown` ABI has been fixed for a while now https://github.com/rust-lang/rust/issues/115666, so this test can be re-enabled and the fixme removed.

r? ``@bjorn3``
2025-11-16 14:40:02 +11:00
Scott Schafer 463c6cea68 chore: Update annotate-snippets to 0.12.9 2025-11-15 14:45:21 -07:00
Scott McMurray e10a7db4d4 Add another *ExprWithBlock* test for try blocks 2025-11-15 01:28:54 -08:00
Ralf Jung 324e47ba2b when writing a scalar pair, always reset the entire destination range 2025-11-15 10:09:43 +01:00
Ralf Jung 907fd85e16 const-eval: fix and re-enable pointer fragment support 2025-11-15 10:09:42 +01:00
bors 733108b6d4 Auto merge of #148706 - dianne:slightly-lazier-temporary-scoping, r=cjgillot
compute temporary scopes when building MIR, not THIR

This accomplishes two things:
- Makes the THIR slightly smaller by not attaching a full `TempLifetime` to every expression.
- Reduces the number of traversals of the `ScopeTree` by only calling `ScopeTree::temporary_scope` when building MIR for something that needs to be dropped in a temporary scope.
2025-11-15 04:33:47 +00:00
Folkert de Vries 583d5de732 re-enable wasm abi test 2025-11-15 00:17:14 +01:00
Stuart Cook f61bfb0037 Rollup merge of #148725 - scottmcm:experiment-new-try-block-v3, r=petrochenkov
Implement the alternative `try` block desugaring

As discussed in https://github.com/rust-lang/rfcs/pull/3721#issuecomment-3208342727, update the `try` in nightly to match the RFC as a way to experiment.

This addresses the following unresolved issue from https://github.com/rust-lang/rust/issues/31436

>  Address issues with type inference (`try { expr? }?` currently requires an explicit type annotation somewhere).
2025-11-14 19:57:06 +11:00
Stuart Cook bf7d5539f7 Rollup merge of #148638 - chenyukang:yukang-fix-148634-repr-simd-enum-ice, r=Kivooeo,lcnr
Fix ICE for repr simd on non struct

Fixes rust-lang/rust#148634

The ICE happened because
https://github.com/rust-lang/rust/blob/995c11894fdabe1c630694254de756f82389c6cf/compiler/rustc_middle/src/ty/mod.rs#L1531

will always set `IS_SIMD` according to `get_all_attrs`, and since we already report error `attribute should be applied to a struct`, it's OK to bypass here.
2025-11-14 19:57:06 +11:00
yukang 1610851356 add Tainted for NonAsmTypeReason 2025-11-14 12:42:50 +08:00
Stuart Cook 1c32a0b6bb Rollup merge of #148928 - WaffleLapkin:always-test, r=jieyouxu
Move & adjust some `!`-adjacent tests

I'm trying to clean up tests relating to the never type...
2025-11-14 13:14:10 +11:00
Stuart Cook 35a82b8dde Rollup merge of #148878 - folkertdev:tail-call-unsupported-abi, r=WaffleLapkin
error when ABI does not support guaranteed tail calls

Some ABIs cannot support guaranteed tail calls. There isn't really an exhaustive list, so this is a best effort. Conveniently, we already disallow calling most of these directly anyway. The only exception that I was able to trigger an LLVM assertion with so far was `cmse-nonsecure-entry`.

For that calling convention, LLVM specifically notes that  (guaranteed) tail calls cannot be supported:

https://github.com/llvm/llvm-project/blob/28dbbba6c3a4e026e085c48cc022cb97b5d8bc6d/llvm/lib/Target/ARM/ARMISelLowering.cpp#L2331-L2335

---

I have some doubts about the implementation here though. I think it would be nicer to use `CanonAbi`, and move the `become` ABI check into `rustc_hir_typeck`, similar to `check_call_abi`:

https://github.com/rust-lang/rust/blob/d6deffe2debecc66501e50f9573214139ab4d678/compiler/rustc_hir_typeck/src/callee.rs#L157-L194

Both the check for whether an ABI is callable and whether it supports guaranteed tail calls can then be methods (containing exhaustive matches) on `CanonAbi`. I'm however not sure

- if the ABI checks are deliberately only performed when constructing MIR
- what assumptions can be made about the `call` expression in [`check_expr_become`](https://github.com/rust-lang/rust/blob/d6deffe2debecc66501e50f9573214139ab4d678/compiler/rustc_hir_typeck/src/expr.rs#L1126-L1150), it looks like currently the check that the "argument" to `become` is a function call also only occurs later during MIR construction

Are there issues with validating the ABI earlier in `rustc_hir_typeck` that I'm overlooking? I believe that we should already know the call's ABI and whether it is c-variadic at that point.

cc ````@workingjubilee```` for `CanonAbi`, ````@davidtwco```` for cmse
r? ````@WaffleLapkin````
2025-11-14 13:14:04 +11:00
Waffle Lapkin fd50a37726 move DispatchFromDyn test out of never_type/
???
2025-11-14 00:04:58 +01:00
Waffle Lapkin b13f49e419 add explanation comments to !-related tests
... outside `tests/ui/never_type/`
2025-11-14 00:04:58 +01:00
Waffle Lapkin 5d33ab1316 fix some typos in !-related test comments 2025-11-14 00:04:54 +01:00
bors 2286e5d224 Auto merge of #148481 - GuillaumeGomez:subtree-update_cg_gcc_2025-11-04, r=GuillaumeGomez
Sync rustc_codegen_gcc subtree

cc `@antoyo`

r? ghost
2025-11-13 18:00:02 +00:00
Folkert de Vries 78beefed84 error when ABI does not support guaranteed tail calls 2025-11-13 15:31:37 +01:00
Guillaume Gomez 866de5fdcc Ignore tests/ui/lto/lto-global-allocator.rs for GCC backend 2025-11-13 15:23:14 +01:00
dianne cb427318cb compute temporary scopes when building MIR, not THIR 2025-11-13 00:07:36 -08:00
bors 5dbf4069dc Auto merge of #148885 - Zalathar:rollup-wrvewer, r=Zalathar
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#147701 (rustdoc: don't ignore path distance for doc aliases)
 - rust-lang/rust#148735 (Fix ICE caused by invalid spans for shrink_file)
 - rust-lang/rust#148839 (fix rtsan_nonblocking_async lint closure ICE)
 - rust-lang/rust#148846 (add a test for combining RPIT with explicit tail calls)
 - rust-lang/rust#148872 (fix: Do not ICE when missing match arm with ill-formed subty is met)
 - rust-lang/rust#148880 (Remove explicit install of `eslint` inside of `tidy`'s Dockerfile)
 - rust-lang/rust#148883 (bootstrap: dont require cmake if local-rebuild is enabled)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-13 02:39:06 +00:00
Stuart Cook 17c25e4483 Rollup merge of #148872 - ShoyuVanilla:issue-148192, r=chenyukang
fix: Do not ICE when missing match arm with ill-formed subty is met

Fixes rust-lang/rust#148192

The ICE comes from the following line, calling `normalize_erasing_regions` to a projection type whose trait bound is not met:
https://github.com/rust-lang/rust/blob/2fcbda6c1a70606bdb09857e01d01fc6229da712/compiler/rustc_pattern_analysis/src/rustc.rs#L185-L194

The above function is called while trying to lint missing match arms, or scrutinize ctors of missing(not necessary error) match arms.

So, the following code can trigger ICEs.
```rust
trait WhereTrait {
    type Type;
}

fn foo(e: Enum) {
    match e {
        Enum::Map(_) => (), // ICE, while trying to lint missing arms
    }

    if let Enum::Map(_) = e {} // ICE, while trying to scrutinize missing ctors (even worse)
}

enum Enum {
    Map(()),
    Map2(<() as WhereTrait>::Type),
}
```

This ICE won't be triggered with the following code, as this is filtered out before `check_match` as the existence of ill-formed type inside the variant marks the body as tainted by error in `hir_typeck`, but for the above code, the `hir_typeck` complains nothing because everything it sees is locally correct.

```rust
fn foo(e: Enum) {
    match e {
        Enum::Map2(_) => (), // No ICE
    }
}
```

I've considered visiting and wf checking for the match scrutinee before entering `check_match`, but that might regress the perf and I think just emitting delayed bug would enough as the normalization failure would be originated by other errors like ill-formdness.
2025-11-13 11:57:10 +11:00
Stuart Cook 1f2d7db112 Rollup merge of #148846 - folkertdev:tail-call-rpit, r=WaffleLapkin
add a test for combining RPIT with explicit tail calls

tracking issue: https://github.com/rust-lang/rust/issues/112788
fixes https://github.com/rust-lang/rust/issues/139305

Combining return position impl trait (RPIT) with guaranteed tail calls does not currently work, but at least it does not ICE any more.

Using RPIT probably should work, see also https://github.com/rust-lang/rust/issues/144953.

The snippet in the issue is not valid for a variety of reasons, and based on the assert that got triggered the ICE was just any `-> impl Trait` at all, so I've made a minimal example using RPIT.

r? `@WaffleLapkin`
2025-11-13 11:57:09 +11:00
Stuart Cook 20f111f0d8 Rollup merge of #148839 - luca3s:rtsan_ice_fix, r=WaffleLapkin
fix rtsan_nonblocking_async lint closure ICE

Fixes https://github.com/rust-lang/rust/issues/148750, which i introduced in https://github.com/rust-lang/rust/pull/147935.
I also added the bug report to the tests.
2025-11-13 11:57:08 +11:00
Stuart Cook 06b18db01b Rollup merge of #148735 - chenyukang:yukang-fix-ice-148732, r=nnethercote
Fix ICE caused by invalid spans for shrink_file

Fixes rust-lang/rust#148732

There are two issues in this function:
1. the original issue is caused by a typo error, which is fixed in the first commit
2. another different ice(Patch span `7..7` is beyond the end of buffer `0`) will be reported after fixing the first one, is caused by spans cross file boundaries due to macro expansion. It is fixed in the second commit.

r? `@nnethercote`

edited: also fixes rust-lang/rust#148684, added a new testcase for it in the last commit.
2025-11-13 11:57:07 +11:00
bors 503dce33e2 Auto merge of #148789 - m-ou-se:new-fmt-args-alt, r=wafflelapkin,jdonszelmann
New format_args!() and fmt::Arguments implementation

Part of https://github.com/rust-lang/rust/issues/99012

This is a new implementation of `format_args!()` and `fmt::Arguments`. With this implementation, `fmt::Arguments` is only two pointers in size. (Instead of six, before.) This makes it the same size as a `&str` and makes it fit in a register pair.

---

This `fmt::Arguments` can store a `&'static str` _without any indirection_ or additional storage. This means that simple cases like `print_fmt(format_args!("hello"))` are now just as efficient for the caller as `print_str("hello")`, as shown by this example:

> code:
> ```rust
> fn main() {
>     println!("Hello, world!");
> }
> ```
>
> before:
> ```asm
> main:
>  sub     rsp, 56
>  lea     rax, [rip + .Lanon_hello_world]
>  mov     qword ptr [rsp + 8], rax
>  mov     qword ptr [rsp + 16], 1
>  mov     qword ptr [rsp + 24], 8
>  xorps   xmm0, xmm0
>  movups  xmmword ptr [rsp + 32], xmm0
>  lea     rdi, [rsp + 8]
>  call    qword ptr [rip + std::io::stdio::_print]
>  add     rsp, 56
>  ret
> ```
>
> after:
> ```asm
> main:
>  lea     rsi, [rip + .Lanon_hello_world]
>  mov     edi, 29
>  jmp     qword ptr [rip + std::io::stdio::_print]
> ```

(`panic!("Hello, world!");` shows a similar change.)

---

This implementation stores all static information as just a single (byte) string, without any indirection:

> code:
> ```rust
> format_args!("Hello, {name:-^20}!")
> ```
>
> lowering before:
> ```rust
> fmt::Arguments::new_v1_formatted(
>     &["Hello, ", "!\n"],
>     &args,
>     &[
>         Placeholder {
>             position: 0usize,
>             flags: 3355443245u32,
>             precision: format_count::Implied,
>             width: format_count::Is(20u16),
>         },
>     ],
> )
> ```
>
> lowering after:
> ```rust
> fmt::Arguments::new(
>     b"\x07Hello, \xc3-\x00\x00\xc8\x14\x00\x02!\n\x00",
>     &args,
> )
> ```

This saves a ton of pointers and simplifies the expansion significantly, but does mean that individual pieces (e.g. `"Hello, "` and `"!\n"`) cannot be reused. (Those pieces are often smaller than a pointer to them, though, in which case reusing them is useless.)

---

The details of the new representation are documented in [library/core/src/fmt/mod.rs](https://github.com/m-ou-se/rust/blob/new-fmt-args-alt/library/core/src/fmt/mod.rs#L609-L712).
2025-11-12 23:21:24 +00:00