Commit Graph

2726 Commits

Author SHA1 Message Date
mejrs
6c0f3aacde macro_metavar_expr_concat: support concatenating into string literals 2026-09-22 17:57:52 +02:00
Jonathan Brouwer
e1b8be29ff Rollup merge of #160859 - Jamesbarford:feat/fb16-pt1, r=folkertdev,tgross35
`core::num::f16b` Rust's 16bit Brain Float

Implements the [RFC: f16b type](https://github.com/rust-lang/rfcs/pull/3983). Best reviewed commit by commit, happy to split into separate PRs if that is deemed easier to review. However the line count and surface area is, in my opinion, reasonably small.

Adds;
- ABI plumbing for the `f16b` along with `bfloat` lang item to work with LLVM, GCC is explicitly `unimplemented!(...)`
- `f16b` feature gate, page for `f16b` on libruscdoc and a `struct bf16` in `core::num`
- Tests
- Treat `f16b` as a scalar primitive for scalable vectors

Issues;
- [Tracking Issue](https://github.com/rust-lang/rust/issues/160630)
- [RFC](https://github.com/rust-lang/rfcs/pull/3983)
2026-09-21 15:19:23 +02:00
James Barford-Evans
df1b5c9671 f16b Implementation and documentation 2026-09-21 08:57:51 +01:00
Zalathar
07f15ab580 Use the full path of bug_impl to avoid bogus errors in rust-analyzer
For whatever reason, rust-analyzer doesn't understand hygienic macros well
enough to properly resolve this function call, which leads to bogus type errors
appearing in rust-analyzer because it doesn't know that the function returns
`!` and therefore must diverge.

(For example, if `bug!(..);` with a trailing semicolon is used in the else
block of a let-else statement, rust-analyzer will complain about it even though
rustc is happy.)

If we specify the full path to the function, both rustc and rust-analyzer agree
that it diverges.
2026-09-20 17:36:53 +10:00
Nicholas Nethercote
0e617d448a Adjust bug!/span_bug! emission
PR #161873 moved these macros from `rustc_middle` to `rustc_span`. In
doing so it made some undesirable changes.

- The internal `emit_producing_nothing` became public.

- It gave the macros different behaviour to function-based ICEs like
  `dcx.bug(..)` or `dcx.struct_bug(..).emit()`.

- `ExplicitBug` is not used, so `report_ice` prints an extraneous,
  unintended "the compiler unexpectedly panicked" message.

- It broke the interaction between `span_bug!` and
  `-Ztrack-diagnostics`.

This commit adjusts things to avoid the undesirable changes. It required
moving `ExplicitBug` to `rustc_span`. Setting `diag.emitted_at` fixed
the `-Ztrack-diagnostics` problem, seen in the change from `callback.rs`
to `validate.rs` in `track7.stderr`.

`Box<dyn Any>` output now occurs again in a few tests because the panic
payload is `ExplicitBug` (which std doesn't know about) rather than
`String`. That might be worth addressing in the future but it would
require a different/additional mechanism and is beyond the scope of this
PR.
2026-09-18 15:44:23 +10:00
bors
28e8a8c81b Auto merge of #162827 - JonathanBrouwer:rollup-JmKukFg, r=JonathanBrouwer
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#161873 (move bug and span_bug macros to rustc_span)
 - rust-lang/rust#162584 (Use File::*lock*() in rustc_data_structures::flock when possible)
 - rust-lang/rust#162704 (Parser: Uninterpolate when checking for const closures, try bikeshed blocks & in relevant diagnostic code)
 - rust-lang/rust#162787 (Fix suggestions for names captured by formatting macros)
 - rust-lang/rust#159562 (Windows: cache the stdio write mode for the duration of a lock session)
 - rust-lang/rust#162813 (Pre lint port cleanups)
 - rust-lang/rust#162822 (PassWrapper: adapt for removal of EABIVersion arg in LLVM 24)
2026-09-16 01:22:39 +00:00
bors
2b9a7be855 Auto merge of #161450 - aerooneqq:syntax-ctxt-non-deterministic-encoding, r=petrochenkov
Fix non-deterministic encoding of syntax contexts



Reiteration of rust-lang/rust#157409. Explanation can be found in comment for `encoding_indices` and in the issue.

Fixes rust-lang/rust#129094. Blocked by rust-lang/rust#161353.

r? @petrochenkov

_No llms used._
2026-09-15 22:12:23 +00:00
Jonathan Brouwer
354f732b7a Rollup merge of #162813 - mejrs:pre_lint_cleanups, r=JonathanBrouwer,petrochenkov
Pre lint port cleanups

Some minor changes split off from https://github.com/rust-lang/rust/pull/162811, to make that a bit easier to review.

cc @JonathanBrouwer
2026-09-15 23:26:58 +02:00
Jonathan Brouwer
2cb8b18100 Rollup merge of #162787 - chenyukang:yukang-fix-105520-format-captured-fields, r=estebank
Fix suggestions for names captured by formatting macros

Fixes rust-lang/rust#105520

also improve rust-lang/rust#141136.
but still can not handle rust-lang/rust#96999.

r? @ghost
2026-09-15 23:26:57 +02:00
mejrs
575aae6559 fix span_delayed_bug doc links 2026-09-15 18:00:42 +02:00
aerooneqq
2e35677688 Fix non-deterministic encoding of syntax contexts 2026-09-15 17:50:04 +03:00
mejrs
7cf2239e14 use span_bug in Ident::new 2026-09-15 16:20:17 +02:00
mejrs
784649bf5f use rustc_interface callback to emit span_bug diagnostic 2026-09-15 16:20:16 +02:00
mejrs
6d505c673b check_unused_attribute: handle crate level only attrs via config, and drop dead default_method_body_is_const lint 2026-09-15 15:55:25 +02:00
Yukang
047c8bb949 Fix suggestions for names captured by formatting macros 2026-09-15 07:23:30 +08:00
bors
24d4720274 Auto merge of #162571 - xmakro:perf-review-20260907/26-hygiene-hash-single-access, r=petrochenkov
perf: Read hygiene data once when hashing syntax contexts
2026-09-13 14:21:46 +00:00
xmakro
544e17bece Read hygiene data once when hashing syntax contexts
[skip ci]
2026-09-12 20:25:20 -07:00
khyperia
f5eb9e4005 yeet mgca_type_const_syntax 2026-09-11 17:08:12 +02:00
khyperia
5c5de6eae5 implement #[rustc_always_gca] 2026-09-11 17:08:12 +02:00
Jonathan Brouwer
84f09c7144 Rollup merge of #162541 - BoxyUwU:twos_a_crowd, r=khyperia
split `macroless_generic_const_args` in two

Two's a crowd! But One's a lonely.

Having `macroless_generic_const_args` apply to const items was quite annoying for users especially as we moved away from `type const` to just regular const items. We would quite commonly be "guessing wrong" with no easy way for users to opt out of `const ASSOC: usize = ...` being represented directly instead of an opaque body

I just swapped any failing tests over to using macroless_const_item_generic_const_args, didnt look through the whole set :>

We should probably bikeshed the feature name rn because it's currently inconsistent with what we wanted to rename all of the other gca features too :> Maybe this should be `gca_macroless_const_items`

cc rust-lang/rust#162540

r? khyperia
2026-09-11 12:45:06 +02:00
Jonathan Brouwer
9e9dc37b47 Rollup merge of #160860 - maxdexh:custom-mir-casts, r=oli-obk
Implement arbitrary casts in custom mir

[See zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/extending.20custom.20MIR/with/613727602)

Implement custom casts using an enum in `intrinsics::mir` that closely matches the `CastKind` enum in the compiler.

We have 5 different ways to cast in custom MIR, 3 with functions (which hard code a cast kind), 1 implicit coerce (which only does subtyping i think), 1 with `as` (which does a few more). They are all different and the error messages don't tell you what to do. Some are (i think) not possible at all.

This came up [while testing miri](https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/Valdity.20checks.20for.20references/near/613662285). We currently have to guess the casting syntax until we find the one that generates the MIR we want. This PR changes that by adding a custom mir operation that allows picking an arbitrary cast.

r? RalfJung
2026-09-11 12:45:03 +02:00
Jonathan Brouwer
70410fe0ac Rollup merge of #162520 - aerooneqq:hygiene-perf, r=petrochenkov
Refactor `HygieneEncodeContext`

Some refactorings around `HygieneEncodeContext` with minor perf improvements, the most notable thing is that `Lock`s were removed.

First part for rust-lang/rust#161450.

r? @petrochenkov
2026-09-11 12:45:00 +02:00
aerooneqq
69afc99f50 Refactor HygieneEncodeContext
* Refactor `HygieneEncodeContext`
* Review: remove comment outdated part
* Review: return `raw_encode_syntax_context` as a free function
* Review: small cleanups
* Review: add comment about expansions data `Option`
* Review: don't set explicit capacity
* Review: return `queued` -> `latest`
* Remove not needed changes
* Fix `Rc` cloning
* Return comment
2026-09-11 08:18:39 +00:00
Boxy Uwu
15d08109c4 split macroless_generic_const_args in two 2026-09-10 19:47:14 +01:00
Max Dexheimer
225a061aa5 Implement arbitrary casts in custom mir 2026-09-10 17:56:57 +02:00
Stuart Cook
467fe699f7 Rollup merge of #162122 - malezjaa:gate-enzyme-intrinsics, r=bjorn3
Put manual calls of Enzyme intrinsics behind a feature gate

r? bjorn3

fixes rust-lang/rust#161820

I created the internal feature gate without a tracking issue. `autodiff` didn’t seem like it was the right one.
2026-09-10 14:06:09 +10:00
malezjaa
4a17c03d39 Put manual calls of Enzyme intrinsics behind a feature gate 2026-09-09 22:24:54 +02:00
Jonathan Brouwer
501a26cc6a Rollup merge of #161896 - yara-blue:reflection-refactor-array-slice, r=oli-obk
Remove fields from TypeKind: Array, Slice

Tracking issue rust-lang/rust#146922

Part of the [Refactoring to many methods](https://rust-lang.zulipchat.com/#narrow/channel/572285-goals.2Freflection/topic/Refactoring.20to.20many.20methods/with/592226560) reflection subgoal. See that for the full context. In short for various reasons we are moving from an enum `TypeKind` where the variants hold the types information to one that just tells you the type kind. Separate methods on `TypeId` provide a way to get to the data that used to be in the variant.

r? @oli-obk
2026-09-07 21:27:59 +02:00
Jonathan Brouwer
ea913e9a58 Rollup merge of #162436 - beetrees:rfcs-link-to-book, r=mejrs
Replace links to `github.com/rust-lang/rfcs` with links to the Rust RFC Book

I noticed many error codes link to Rust RFCs via the [source GitHub `.md` files](https://github.com/rust-lang/rfcs/tree/master/text) instead of linking to the [RFC Book](https://rust-lang.github.io/rfcs/). This PR updates those links to point to the RFC book - I also updated any other links to RFCs in the repo (not including subtrees) while I was at it.
2026-09-07 21:27:57 +02:00
Yara
ed8f8b6025 reflection: replace TypeKind::Array field with methods 2026-09-07 21:23:19 +02:00
Yara
2edd31488a reflection: replace TypeKind::Slice's field with TypeId::element_ty 2026-09-07 20:58:18 +02:00
Jonathan Brouwer
706214d854 Rollup merge of #162294 - yara-blue:reflection-refactor-ptrs, r=oli-obk
Reflection refactor ptrs

Tracking issue rust-lang/rust#146922

Part of the [Refactoring to many methods](https://rust-lang.zulipchat.com/#narrow/channel/572285-goals.2Freflection/topic/Refactoring.20to.20many.20methods/with/592226560) reflection subgoal. See that for the full context. In short for various reasons we are moving from an enum `TypeKind` where the variants hold the types information to one that just tells you the type kind. Separate methods on `TypeId` provide a way to get to the data that used to be in the variant.

Since function pointers have a lot of fields it felt better to keep the `FnPtr` struct we have now then add an intrinsic for each field.

r? @oli-obk
2026-09-07 17:08:09 +02:00
beetrees
ac599d4e90 Replace links to github.com/rust-lang/rfcs with links to the Rust RFC Book 2026-09-07 16:07:24 +01:00
Yara
06fa642f23 reflection: remove field from TypeKind::FnPtr 2026-09-04 19:28:09 +02:00
Yara
98d68aa8ce reflection: adds TypeId::function_ptr returning FnPtr 2026-09-04 19:27:24 +02:00
Yara
f123df5b07 reflection: adds TypeId::points_to and TypeId::is_mutable_pointer 2026-09-04 19:26:30 +02:00
Amanieu d'Antras
51b3f52eab Merge zreg into vreg and keep ffr in a clobber-only class 2026-09-04 13:29:17 +00:00
Reuben Cruise
7b2bfecd72 Adds support for AArch64 SVE to inline assembly
Adds new `zreg` register type and `SveVec*` variants to `InlineAsmType`
2026-09-04 13:29:17 +00:00
Nicholas Nethercote
f91c12f29e Revert "Implement Debug for C-like enums with a concatenated string"
From #155452.

Fixes #162124.
2026-09-02 11:05:02 +10:00
N1ark
edcae4441d Make sin, cos, exp, exp2, log, log2, log10 generic 2026-08-31 18:57:54 +01:00
bors
be4b6a99a3 Auto merge of #161081 - scottmcm:min-max-intrinsics, r=clarfonthey
Add intrinsics for integer minimum and maximum



I got inspired to do this when looking at `SliceOrd::compare` where I was reminded that `if a < b { a } else { b }` isn't great in MIR since it takes 4 BBs.  Looking at the codegen side, it turns out we currently emit [42 lines of LLVM-IR including 4 `alloca`s](https://rust.godbolt.org/z/ha4h4nT3r) for `u16::max` (pre-optimization), which is also unnecessarily bad†.

But both LLVM and Cranelift have dedicated things for min & max:

- https://llvm.org/docs/LangRef.html#llvm-umax-intrinsic
- https://docs.rs/cranelift-codegen/latest/cranelift_codegen/ir/trait.InstBuilder.html#method.smin

so let's just use those directly!

This actually wouldn't have been worth doing originally, but a couple of things have happened to change that:

- Back in 1.0 there was only `cmp::min` & `cmp::max`, so there was no place to actually do this at all, but in 2017 they were added to `Ord` as overridable things https://github.com/rust-lang/rust/issues/25663#issuecomment-325799662
- LLVM originally used icmp+select for these, not a dedicated construct, but then added one and as of 2022 the intrinsic is fully usable https://www.npopov.com/2022/12/20/This-year-in-LLVM-2022.html#integer-minmax-intrinsics
- Before we had intrinsic fallback this would have been more annoying to support everywhere -- GCC, [128-bit numbers on cg_clif](https://github.com/bytecodealliance/wasmtime/issues/13790), CTFE, anything out-of-tree -- but now that we can write the obvious fallback we don't need to worry about that.
- The intrinsic would have helped less when it forced extra BBs and `alloca`s in codegen anyway, but [now](https://github.com/rust-lang/compiler-team/issues/970) we can keep the result in SSA without needing to make it a primitive.

† Admittedly we could clean up the gratuitous badness there without needing an intrinsic, but I like doing the intrinsic anyway because that's the only way to avoid it always being stuck in the non-SSA path from the multi-BB assignments.  Even if we made it inlineable, GVN and such will still just give up on seeing the `x = if a < b { a } else { b }` because it's multiple assignments to the same Local, which is non-ideal for something primitive-like.
2026-08-31 04:41:43 +00:00
Jonathan Brouwer
e36bc49e98 Rollup merge of #161931 - JonathanBrouwer:revert-test-entry-point, r=mejrs
Revert "Add rustc_test_entrypoint_marker"

Reverts https://github.com/rust-lang/rust/pull/158854 because it caused two beta regressions
Revert required some minor solving of conflicts
We can think about re-landing it after

Fixes https://github.com/rust-lang/rust/issues/161920
Fixes https://github.com/rust-lang/rust/issues/161917

cc: @Nadrieril @N1ark @aDotInTheVoid @jdonszelmann
2026-08-30 21:48:06 +02:00
Jonathan Brouwer
9b70ab051c Revert "Add rustc_test_entrypoint_marker" 2026-08-30 19:18:27 +02:00
Scott McMurray
7519f42401 Add intrinsics for integer minimum and maximum 2026-08-30 00:48:34 -07:00
Guillaume Gomez
188f0986cd Rollup merge of #161974 - matthiaskrgr:never_attr_rm, r=mejrs
remove rustc_never_type_options attr remnants

While fuzzing I noticed we would now ICE in two places when encountering an empty or filled `#![rustc_never_type_options()]` attr:

compiler/rustc_passes/src/check_attr.rs:160:33: builtin attribute "rustc_never_type_options" not handled by `CheckAttrVisitor`
compiler/rustc_attr_parsing/src/validate_attr.rs:42:17: assertion failed: lint_attrs.contains(name)

So remove these two entries after which we will just error with `error: cannot find attribute`

r? @WaffleLapkin
2026-08-29 22:46:04 +02:00
bors
bdf8733e40 Auto merge of #161979 - JonathanBrouwer:rollup-IymjmDu, r=JonathanBrouwer
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#160851 (Add MSA and `f16` inline ASM support for MIPS)
 - rust-lang/rust#161960 (std::sys::sgx::tls: fix TLS destructor pointer provenance)
 - rust-lang/rust#161976 (Improve rustdoc macro expansion code)
2026-08-29 14:44:37 +00:00
Jonathan Brouwer
9dd88ffd5a Rollup merge of #160851 - beetrees:f16-inline-asm-mips, r=folkertdev
Add MSA and `f16` inline ASM support for MIPS

This PR adds vector register support for MIPS inline ASM when using the MSA extension ([MSA specification](https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00868-1D-MSA64-AFP-01.12.pdf)), as well as adding support for the `f16` type.

Ping target maintainers of MIPS targets: @Itus-Shield @Gelbpunkt @ayrtonm @LukasWoodtli @wzssyqa @chenx97 @709924470 @Cyanoxygen @Fearyncess

Tracking issues:
`f16` inline ASM: rust-lang/rust#125398 (part of rust-lang/rust#116909)
MIPS inline ASM: rust-lang/rust#93335
MIPS target features: rust-lang/rust#150253
2026-08-29 16:13:30 +02:00
Matthias Krüger
28182a7e29 remove rustc_never_type_options attr remnants
While fuzzing I noticed we would now ICE in two places when encountering an empty or filled `#![rustc_never_type_options()]` attr:

compiler/rustc_passes/src/check_attr.rs:160:33: builtin attribute "rustc_never_type_options" not handled by `CheckAttrVisitor`
compiler/rustc_attr_parsing/src/validate_attr.rs:42:17: assertion failed: lint_attrs.contains(name)

So remove these two entries after which we will just error with `error: cannot find attribute`
2026-08-29 14:36:32 +02:00
Jonathan Brouwer
3a93a22480 Rollup merge of #161794 - fmease:fix-weak-pin, r=adwinwhite
Fix handling of weak keyword `pin`

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

On main, we use `is_ident_named` to detect weak keyword `pin` which is incorrect since it doesn't account for whether the identifier in question is raw (`r#`) or not. Namely, `r#pin` should *never* be considered (yes, even if it's followed by the disambiguator `const` or `mut`). As it stands, (1) we accept more code than we should (2) we're prone to rightfully triggering internal assertions thus ICE'ing.

Just use `is_keyword`&co which do those checks (indeed, it's also used for weak keywords). Furthermore, move `Symbol` `sym::pin` to `kw::Pin` and officially mark it as weak. This doesn't have any semantic effect, it's still a `Symbol`, but it's more conventional.

For reference, on main we ICE with `assertion failed: self.eat_keyword(expr!(Pin))` on inputs like the following:

* `type X = &r#pin const ();` (type)
* `fn scope() { let _ = &r#pin mut (); }` (expr)
* `fn scope() { let &r#pin const (); }` (pat)

Moreover, on main we wrongfully accept code like `trait Trait { fn f(&r#pin mut self); }` (assuming the feature is enabled).

<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
2026-08-29 13:28:13 +02:00
Jonathan Brouwer
2b902cde7d Rollup merge of #159988 - chrisnc:arm-inline-asm-fpregs, r=folkertdev
On arm, only require fpregs instead of vfp2 to allow s0-s15, s0-s31, and d0-15 register classes

Add vfp2sp and fp64 unstable target features for arm as implied features of vfp2.

Fixes rust-lang/rust#159976

Fixes rust-lang/rust#161826
2026-08-29 13:28:13 +02:00