Commit Graph

46199 Commits

Author SHA1 Message Date
Nicholas Nethercote
0ea204a5ff Add useful comments on ExprKind::If variants.
Things that aren't obvious and took me a while to work out.
2025-05-02 15:53:39 +10:00
Matthias Krüger
1e440aecc8
Rollup merge of #140516 - rperier:type-ir-to-type-middle, r=lcnr
Replace use of rustc_type_ir by rustc_middle

cc #138449

I want to help on this issue. I have replaced all the rustc_type_ir uses by the equivalent type in rustc_middle.
DelayedSet is also re-exposed by rustc_middle.
2025-04-30 17:28:02 +02:00
Matthias Krüger
62a48cd9c3
Rollup merge of #140504 - tmiasko:answer-ensure-stack, r=jswrenn
transmutability: ensure_sufficient_stack when answering query

Based on #140380.

Fixes #118860. The compile time was addressed earlier, this merely addresses stack overflow part of the issue.

r? `@jswrenn` `@joshlf`
2025-04-30 17:28:01 +02:00
Matthias Krüger
21df9db1f6
Rollup merge of #140498 - compiler-errors:check-fn-tweaks, r=oli-obk
Misc tweaks to HIR typeck (mostly w.r.t. checking calls)

Just some cleanups.

r? oli-obk
2025-04-30 17:28:00 +02:00
Matthias Krüger
ce9fc4a9e9
Rollup merge of #140450 - petrochenkov:vistok, r=nnethercote
ast: Remove token visiting from AST visitor

It's no longer necessary after the removal of nonterminal tokens in #124141.

r? `@nnethercote`
2025-04-30 17:28:00 +02:00
Matthias Krüger
1a64f2c461
Rollup merge of #140203 - Wyliodrin:error_for_no_mangle_weak_language_items, r=bjorn3
Issue an error when using `no_mangle` on language items

This pull requests adds the code to issue an error or a warning when using `no_mangle` on language items. This should detail why the `undefined symbol` error is issued for the code described in #139923.

The pull request adds two ui tests, one testing the error and the other one the warning.

I would love some feedback here, as I am not sure that the error and warning are issues using the right API.
2025-04-30 17:27:59 +02:00
Matthias Krüger
230215f890
Rollup merge of #140090 - Urgau:snake_case-fn-var, r=petrochenkov
Check bare function idents for non snake-case name

This PR adds the check required to lint on bare function idents for non snake-case name.

Reported at #140089.
cc `@theemathas`
2025-04-30 17:27:58 +02:00
Matthias Krüger
555df301f8
Rollup merge of #134232 - bjorn3:naked_asm_improvements, r=wesleywiser
Share the naked asm impl between cg_ssa and cg_clif

This was introduced in https://github.com/rust-lang/rust/pull/128004.
2025-04-30 17:27:57 +02:00
Romain Perier
ea7af1803f Use less rustc_type_ir in the compiler codebase
This commit does the following:
 - Replaces use of rustc_type_ir by rustc_middle
 - Removes the rustc_type_ir dependency
 - The DelayedSet type is exposed by rustc_middle so everything can be
   accessed through rustc_middle in a coherent manner.
2025-04-30 16:42:33 +02:00
bjorn3
3e174d4e69 Fix naked asm symbol name for cg_clif on macOS 2025-04-30 12:59:50 +00:00
Alexandru RADOVICI
07c7e5ffb3 error when using no_mangle on language items
add suggestion on how to add a panic breakpoint

Co-authored-by: Pat Pannuto <pat.pannuto@gmail.com>
delete no_mangle from ui/panic-handler/panic-handler-wrong-location test

issue an error for the usage of #[no_mangle] on internal language items

delete the comments

add newline

rephrase note

Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
update error not to leak implementation details

delete no_mangle_span

Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
delete commented code
2025-04-30 14:54:10 +03:00
Tomasz Miąsko
0138df1f3d transmutability: ensure_sufficient_stack when answering query 2025-04-30 12:06:14 +02:00
Matthias Krüger
ae7d78a8ff
Rollup merge of #140448 - Zalathar:query-append, r=compiler-errors
Rename `rustc_query_append!` to `rustc_with_all_queries!`

Whenever I'm trying to make sense of the query system internals, I always get tripped up on this unhelpfully-named macro. The fact that it's a higher-order proc macro is already mind-melting enough on its own.

This new name, `rustc_with_all_queries!`, forms a much more intuitive combination with the helper macros that it invokes. And only one of the call sites was even making use of the “append” part of its old name.

This PR also reformats the parameters matched by the helper macros, to make the actual argument syntax a bit easier to see.

---

Renaming and reformatting only; no functional changes.
2025-04-30 10:18:29 +02:00
Matthias Krüger
9625096d2c
Rollup merge of #140445 - oli-obk:const-manually-drop, r=fee1-dead
Treat ManuallyDrop as ~const Destruct

cc https://github.com/rust-lang/rust/issues/133214#issuecomment-2838078133

r? ```@compiler-errors```

cc ```@fee1-dead```
2025-04-30 10:18:28 +02:00
Matthias Krüger
254f050eb4
Rollup merge of #140439 - RalfJung:miri-algebraic-float-nondet, r=oli-obk
miri: algebraic intrinsics: bring back float non-determinism

Fixes https://github.com/rust-lang/miri/issues/4289
Cc ```@bjoernager```
r? ```@oli-obk```
2025-04-30 10:18:28 +02:00
Matthias Krüger
b1a1c671e8
Rollup merge of #140404 - lcnr:canonical-no-type-foldable, r=compiler-errors
rm `TypeVistable` impls for `Canonical`

similar to `EarlyBinder`, you generally do not want to fold a canonical value directly without first instantiating it. In places where you do want to look into the `Canonical`, it's likely better to do so manually.

r? ```@compiler-errors```
2025-04-30 10:18:26 +02:00
Matthias Krüger
56e01fe1a4
Rollup merge of #140312 - nnethercote:DelimArgs-spacing, r=petrochenkov
Improve pretty-printing of braces

r? ````@petrochenkov````
2025-04-30 10:18:26 +02:00
Matthias Krüger
e89714426b
Rollup merge of #139059 - RalfJung:uses_power_alignment, r=nagisa
uses_power_alignment: wording tweaks

Slightly improves the wording introduced with https://github.com/rust-lang/rust/pull/135552.
2025-04-30 10:18:24 +02:00
Vadim Petrochenkov
6668d13de2 ast: Remove token visiting from AST visitor
It's no longer necessary after the removal of nonterminal tokens in #124141.
2025-04-30 10:36:03 +03:00
Michael Goulet
f986d124f1 Inline check_method_argument_types and remove error_reported special casing (unnecessary) 2025-04-30 03:53:55 +00:00
Michael Goulet
6aa3dd1943 Inline check_method_argument_types to get rid of TupleArgumentsFlag arg 2025-04-30 02:58:29 +00:00
Michael Goulet
e650c1da46 Move the error handling out of confirm_builtin_call 2025-04-30 02:58:28 +00:00
Michael Goulet
bd2c653374 Rename lookup_method_in_trait and consolidate a Ident::with_dummy_span call 2025-04-30 02:58:28 +00:00
bors
f242d6c26c Auto merge of #127516 - nnethercote:simplify-LazyAttrTokenStream, r=petrochenkov
Simplify `LazyAttrTokenStream`

`LazyAttrTokenStream` is an unpleasant type: `Lrc<Box<dyn ToAttrTokenStream>>`. Why does it look like that?
- There are two `ToAttrTokenStream` impls, one for the lazy case, and one for the case where we already have an `AttrTokenStream`.
- The lazy case (`LazyAttrTokenStreamImpl`) is implemented in `rustc_parse`, but `LazyAttrTokenStream` is defined in `rustc_ast`, which does not depend on `rustc_parse`. The use of the trait lets `rustc_ast` implicitly depend on `rustc_parse`. This explains the `dyn`.
- `LazyAttrTokenStream` must have a `size_of` as small as possible, because it's used in many AST nodes. This explains the `Lrc<Box<_>>`, which keeps it to one word. (It's required `Lrc<dyn _>` would be a fat pointer.)

This PR moves `LazyAttrTokenStreamImpl` (and a few other token stream things) from `rustc_parse` to `rustc_ast`. This lets us replace the `ToAttrTokenStream` trait with a two-variant enum and also remove the `Box`, changing `LazyAttrTokenStream` to `Lrc<LazyAttrTokenStreamInner>`. Plus it does a few cleanups.

r? `@petrochenkov`
2025-04-30 00:09:21 +00:00
lcnr
7275462ab9 canonical no type foldable :< 2025-04-29 23:17:31 +00:00
Nicholas Nethercote
880e6f716d Use ThinVec to shrink LazyAttrTokenStreamInner. 2025-04-30 07:12:09 +10:00
Nicholas Nethercote
298c56f4ba Simplify LazyAttrTokenStream.
This commit does the following.
- Changes it from `Lrc<Box<dyn ToAttrTokenStream>>` to
  `Lrc<LazyAttrTokenStreamInner>`.
- Reworks `LazyAttrTokenStreamImpl` as `LazyAttrTokenStreamInner`, which
  is a two-variant enum.
- Removes the `ToAttrTokenStream` trait and the two impls of it.

The recursion limit must be increased in some crates otherwise rustdoc
aborts.
2025-04-30 07:10:56 +10:00
bors
0fbb922e53 Auto merge of #140023 - cjgillot:arena-try-alloc, r=BoxyUwU
Introduce Arena::try_alloc_from_iter.

`alloc_from_iter` already collects the iterator for reentrancy. So adding an early exit for a fallible iterator integrates naturally into the code. This avoids the other solution to allocate and dump the allocation.
2025-04-29 21:06:15 +00:00
Tomasz Miąsko
88a86794b9 transmutability: uninit transition matches unit byte only
The previous implementation was inconsistent about transitions that
apply for an init byte. For example, when answering a query, an init
byte could use corresponding init transition. Init byte could also use
uninit transition, but only when the corresponding init transition was
absent. This behaviour was incompatible with DFA union construction.

Define an uninit transition to match an uninit byte only and update
implementation accordingly. To describe that `Tree::uninit` is valid
for any value, build an automaton that accepts any byte value.

Additionally, represent byte ranges uniformly as a pair of integers to
avoid special case for uninit byte.
2025-04-29 20:42:43 +02:00
Trevor Gross
ff6a9800a3
Rollup merge of #140433 - BjoernLange:master, r=nnethercote
Replace the \01__gnu_mcount_nc to LLVM intrinsic for additional ARM targets

This is an extension to #113814 which seems to have missed two targets which also need this patch for instrumentation with `-Z instrument-mcount` to work correctly.

For anyone who might stumble over this issue again in the future: As a workaround one can dump the current target configuration using

```
rustc +nightly -Z unstable-options --target armv7-unknown-linux-gnueabihf --print target-spec-json
```

(assuming `armv7-unknown-linux-gnueabihf` is the target to build for) add the line

```
    "llvm-mcount-intrinsic": "llvm.arm.gnu.eabi.mcount",
```

and compile with

```
RUSTFLAGS="-Z instrument-mcount -C passes=ee-instrument<post-inline>" cargo +nightly build -Z build-std --target <path to directory with modified target config>/armv7-unknown-linux-gnueabihf.json
```

It might be necessary to set the compiler for cross compiling using something like

```
export TARGET_CC=arm-linux-gnueabihf-gcc
```
2025-04-29 12:28:25 -04:00
Trevor Gross
561f6a1309
Rollup merge of #140432 - tgross35:target-config-docs-update, r=jieyouxu
Update documentation for `fn target_config`

This was missed as part of [1].

[1]: https://github.com/rust-lang/rust/pull/140323
2025-04-29 12:28:25 -04:00
Trevor Gross
219f0b7082
Rollup merge of #140400 - durin42:llvm-21-getguid, r=cuviper
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-29 12:28:24 -04:00
Trevor Gross
a20fe8ff23
Rollup merge of #139909 - oli-obk:or-patterns, r=BoxyUwU
implement or-patterns for pattern types

These are necessary to represent `NonZeroI32`, as the range for that is `..0 | 1..`. The `rustc_scalar_layout_range_*` attributes avoided this by just implementing wraparound and having a single `1..=-1` range effectively. See https://rust-lang.zulipchat.com/#narrow/channel/481660-t-lang.2Fpattern-types/topic/.60or.20pattern.60.20representation.20in.20type.20system/with/504217694 for some background discussion

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

r? `@BoxyUwU`
2025-04-29 12:28:22 -04:00
Trevor Gross
4f20444ad5
Rollup merge of #138344 - tgross35:x86-f16-math, r=Amanieu
Enable `reliable_f16_math` on x86

This has been disabled due to an LLVM misoptimization with `powi.f16` [1]. This was fixed upstream and the fix is included in LLVM20, so tests no longer need to be disabled.

`f16` still remains disabled on MinGW due to the ABI issue.

[1]: https://github.com/llvm/llvm-project/issues/98665

try-job: x86_64-gnu
try-job: x86_64-gnu-llvm-19-1
try-job: x86_64-gnu-llvm-20-1
2025-04-29 12:28:22 -04:00
Zalathar
ed2f4b6d2d Reformat parameters to macros used by with-all-queries 2025-04-29 20:48:51 +10:00
Zalathar
64bcf3b9f6 Rename rustc_query_append! to rustc_with_all_queries! 2025-04-29 20:48:51 +10:00
Oli Scherer
a1c70590b2 Treat ManuallyDrop as ~const Destruct 2025-04-29 10:39:54 +00:00
Ralf Jung
2393e447eb miri: algebraic intrinsics: bring back float non-determinism 2025-04-29 11:05:06 +02:00
Björn Barwinski
6aea9f40ce
Replace the \01__gnu_mcount_nc to LLVM intrinsic for additional ARM targets 2025-04-29 08:15:23 +02:00
Trevor Gross
e3458dcf19 Update documentation for fn target_config
This was missed as part of [1].

[1]: https://github.com/rust-lang/rust/pull/140323
2025-04-29 06:13:02 +00:00
Trevor Gross
19e82b43eb Enable target_has_reliable_f16_math on x86
This has been disabled due to an LLVM misoptimization with `powi.f16`
[1]. This was fixed upstream and the fix is included in LLVM20, so tests
no longer need to be disabled.

`f16` still remains disabled on MinGW due to the ABI issue.

[1]: https://github.com/llvm/llvm-project/issues/98665
2025-04-29 05:39:15 +00:00
bors
4c83e55e2d Auto merge of #137940 - 1c3t3a:alignment-borrows-check, r=saethlin
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.

r? `@saethlin`

cc `@RalfJung,` after our discussion in #134424
2025-04-29 05:36:44 +00:00
Nicholas Nethercote
99f6b6328e Improve pretty-printing of braces.
Most notably, the `FIXME` for suboptimal printing of `use` groups in
`tests/ui/macros/stringify.rs` is fixed. And all other test output
changes result in pretty printed output being closer to the original
formatting in the source code.
2025-04-29 13:46:17 +10:00
Nicholas Nethercote
28236ab703 Move various token stream things from rustc_parse to rustc_ast.
Specifically: `TokenCursor`, `TokenTreeCursor`,
`LazyAttrTokenStreamImpl`, `FlatToken`, `make_attr_token_stream`,
`ParserRange`, `NodeRange`. `ParserReplacement`, and `NodeReplacement`.
These are all related to token streams, rather than actual parsing.

This will facilitate the simplifications in the next commit.
2025-04-29 12:14:27 +10:00
Chris Denton
bf37847434
Rollup merge of #140402 - lcnr:normalizes-to-certainty-yes, r=compiler-errors
only return nested goals for `Certainty::Yes`

Ambiguous `NormalizesTo` goals can otherwise repeatedly add the same nested goals to the parent.

r? ```@compiler-errors```
2025-04-28 23:29:19 +00:00
Chris Denton
e082bf341f
Rollup merge of #140323 - tgross35:cfg-unstable-float, r=Urgau
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)

---

The second commit makes use of this config to replace `cfg_{f16,f128}{,_math}` in `library/`. I omitted providing a `cfg(bootstrap)` configuration to keep things simpler since the next beta branch is in two weeks.

try-job: aarch64-gnu
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-ext2
2025-04-28 23:29:17 +00:00
Chris Denton
3f5406f5be
Rollup merge of #140302 - compiler-errors:inline_asm-bug, r=lcnr
Move inline asm check to typeck, properly handle aliases

Pull `InlineAsmCtxt` down to `rustc_hir_typeck`, and instead of using things like `Ty::is_copy`, use the `InferCtxt`-aware methods. To fix https://github.com/rust-lang/trait-system-refactor-initiative/issues/189, we also add a `try_structurally_resolve_*` call to `expr_ty`.

r? lcnr
2025-04-28 23:29:16 +00:00
Chris Denton
0bd531aaf2
Rollup merge of #140276 - compiler-errors:typeof-less-eagerly, r=lcnr
Do not compute type_of for impl item if impl where clauses are unsatisfied

Consider the following code:

```rust
trait Foo {
    fn call(self) -> impl Send;
}

trait Nested {}
impl<T> Foo for T
where
    T: Nested,
{
    fn call(self) -> impl Sized {
        NotSatisfied.call()
    }
}

struct NotSatisfied;
impl Foo for NotSatisfied {
    fn call(self) -> impl Sized {
        todo!()
    }
}
```

In `impl Foo for NotSatisfied`, we need to prove that the RPITIT is well formed. This requires proving the item bound `<NotSatisfied as Foo>::RPITIT: Send`. Normalizing `<NotSatisfied as Foo>::RPITIT: Send` assembles two impl candidates, via the `NotSatisfied` impl and the blanket `T` impl. We end up computing the `type_of` for the blanket impl even if `NotSatisfied: Nested` where clause does not hold.

This type_of query ends up needing to prove that its own `impl Sized` RPIT satisfies `Send`, which ends up needing to compute the hidden type of the RPIT, which is equal to the return type  of `NotSatisfied.call()`. That ends up in a query cycle, since we subsequently try normalizing that return type via the blanket impl again!

In the old solver, we don't end up computing the `type_of` an impl candidate if its where clauses don't hold, since this select call would fail before confirming the projection candidate:

d7ea436a02/compiler/rustc_trait_selection/src/traits/project.rs (L882)

This PR makes the new solver more consistent with the old solver by adding a call to `try_evaluate_added_goals` after regstering the impl predicates, which causes us to bail before computing the `type_of` for impls if the impl definitely doesn't apply.

r? lcnr

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/185
2025-04-28 23:29:16 +00:00
Chris Denton
8dd26cb195
Rollup merge of #140022 - dianne:box-deref-pats, r=Nadrieril
allow deref patterns to move out of boxes

This adds a case to lower deref patterns on boxes using a built-in deref instead of a `Deref::deref` or `DerefMut::deref_mut` call: if `deref!(inner): Box<T>` is matching on place `place`, the inner pattern `inner` now matches on `*place` rather than a temporary. No longer needing to call a method also means it won't borrow the scrutinee in match arms. This allows for bindings in `inner` to move out of `*place`.

For comparison with box patterns, this uses the same MIR lowering but different THIR. Consequently, deref patterns on boxes are treated the same as any other deref patterns in match exhaustiveness analysis. Box patterns can't quite be implemented in terms of deref patterns until exhaustiveness checking for deref patterns is implemented (I'll open a PR for exhaustiveness soon!).

Tracking issue: #87121

r? ``@Nadrieril``
2025-04-28 23:29:15 +00:00
Chris Denton
17495e0030
Rollup merge of #139656 - scottmcm:stabilize-slice-as-chunks, r=dtolnay
Stabilize `slice_as_chunks` library feature

~~Draft as this needs #139163 to land first.~~

FCP: https://github.com/rust-lang/rust/issues/74985#issuecomment-2769963395

Methods being stabilized are:
```rust
impl [T] {
    const fn as_chunks<const N: usize>(&self) -> (&[[T; N]], &[T]);
    const fn as_rchunks<const N: usize>(&self) -> (&[T], &[[T; N]]);
    const unsafe fn as_chunks_unchecked<const N: usize>(&self) -> &[[T; N]];
    const fn as_chunks_mut<const N: usize>(&mut self) -> (&mut [[T; N]], &mut [T]);
    const fn as_rchunks_mut<const N: usize>(&mut self) -> (&mut [T], &mut [[T; N]]);
    const unsafe fn as_chunks_unchecked_mut<const N: usize>(&mut self) -> &mut [[T; N]];
}
```

~~(FCP's not done quite yet, but will in another day if I'm counting right.)~~ FCP Complete: https://github.com/rust-lang/rust/issues/74985#issuecomment-2797951535
2025-04-28 23:29:15 +00:00