Add `core::num::Complex`
tracking issue: https://github.com/rust-lang/rust/issues/154023
See also [#t-compiler > representing `_Complex`](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/representing.20.60_Complex.60/with/608308993). The RFC states that the `Complex` type should match the ABI of `_Complex` in C, but provides little detail on how to actually achieve this. We concluded that `repr(complex)` is probably the best approach. Like clang, that means we "desugar" the representation early: `_Complex` is not natively represented in LLVM IR.
I've derived the ABI from `clang` for 28 targets, a decent sample of what we actually support. For now I'm only actually testing `x86_64` because (as you'll see) updating the tests is quite labor-intensive. If we're happy with this direction I can fill more of them in, likely in a separate PR.
The libs side of the type is very bare-bones: I'm not as interested in that part. Others can fill in the various instances, methods, write tests for those, and improve the docs.
r? workingjubilee
dogfood `#[diagnostic::unknown]` in the compiler
This makes the error for not-found symbols a lot nicer :)
```
error[E0425]: cannot find value `better_rust` in module `sym`
--> compiler\rustc_feature\src\unstable.rs:799:16
|
157 | name: sym::$feature,
| -------- due to this macro variable
...
799 | (unstable, better_rust, "2.0.0", Some(42)),
| ^^^^^^^^^^^ `better_rust` is not a pre-interned symbol
|
= note: consider adding `better_rust` to the `symbols!` invocation in compiler/rustc_span/src/symbol.rs
```
(only works when building stage 2 for now, the necessary changes haven't landed in beta yet)
Implement derives for Reborrow and CoerceShared
This adds built-in derive support for the experimental `Reborrow` and `CoerceShared` marker traits behind `#![feature(reborrow)]`.
The derives generate the same marker impls users would write manually, while preserving the existing coherence and structural validation path for the experimental reborrow traits.
## Please note this impl:
- Preserves generics, lifetimes, const params, and where clauses in generated impls.
- Preserves multiple lifetime parameters in generated impls instead of duplicating the current experimental one-lifetime limitation in the derive layer.
- Requires an explicit `CoerceShared` target type through the derive helper attribute.
- Adds UI coverage for valid derives, feature gating, malformed helper attributes, unsupported item kinds, validation failures, and multiple-lifetime derive behavior.
- Makes the derive layer future-proof for multiple lifetimes: it preserves all lifetime parameters and generates the same impl shape as a manual impl.
@rustbot label F-reborrow
Tracking: https://github.com/rust-lang/rust/issues/145612
rustc_attr_ir: fix up `lang_items` imports
Cleanup after splitting attributes from rustc_hir.
It's a big one and maybe annoying to merge without conflicts but I figured it's best to just get it done and over with. If it turns out to be too big to merge at once it should be possible to split it up tho :>
r? @JonathanBrouwer
Initial implementation of named `Fn` trait parameters
This is an initial implementation of the feature `named_fn_trait_parameters`.
This implementation is incomplete (and also marked as such) , and needs significant further changes to be implemented correctly. To keep the size of this PR managable, I propose we do this in follow-up PRs.
I've added a test that shows the current behaviour, with `FIXME` comments where the test output is currently incorrect.
Tracking issue: https://github.com/rust-lang/rust/issues/158499
Accepted RFC: https://github.com/rust-lang/rfcs/pull/3955
Account for desugaring in method call move errors
When encountering a move error caused by a desugared method call, talk about the user-facing feature (`await`/`?`/`for`-loop), instead of only the internal API it got desugared to.
```
error[E0382]: use of moved value: `entry`
--> $DIR/moved-into-question-mark.rs:11:18
|
LL | for entry in fs::read_dir(".")? {
| ----- move occurs because `entry` has type `Result<DirEntry, std::io::Error>`, which does not implement the `Copy` trait
LL |
LL | let file_type = entry?.file_type()?;
| ------ `entry` moved due to usage in the question mark operator
...
LL | dbg!(entry?.file_name());
| ^^^^^ value used here after move
|
note: the question mark operator is expanded into a call to `branch`, which takes ownership of the receiver `self`, which moves `entry`
--> $SRC_DIR/core/src/ops/try_trait.rs:LL:COL
help: you could `clone` the value and consume it, if the following trait bounds could be satisfied: `DirEntry: Clone` and `std::io::Error: Clone`
|
LL | let file_type = entry.clone()?.file_type()?;
| ++++++++
```
Fixrust-lang/rust#89567.
Mitigation for [RUST-159429].
The recurring problem is that built-in attributes are treated
differently compared to ordinary prelude attributes, built-in
attributes, even while unstable, can name-collide with stable macro
re-exports of the same name (and proc-macro helper attributes of the
same name), which can break stable code. See [RUST-134964].
[RUST-159429]: https://github.com/rust-lang/rust/issues/159429
[RUST-134963]: https://github.com/rust-lang/rust/issues/134963
perf: Lock-free root fast paths for hygiene queries
`normalize_to_macros_2_0`, `normalize_to_macro_rules` and `outer_expn_is_descendant_of` take the `HygieneData` lock even for the root syntax context, the common case, where the answer is fixed: the root normalizes to itself, and everything descends from the root expansion. This PR avoids the lock, like the existing fast paths in `ExpnId::is_descendant_of`.
Rename splat to avoid stable name collisions
Tracking issue: rust-lang/rust#153629
This PR renames `#[splat]` to `#[rustc_splat]`, in a mostly automated way (using `fastmod`).
The rename commands I used were:
```sh
fastmod --fixed-strings '#[splat]' '#[rustc_splat]'
fastmod --fixed-strings '`splat` attribute' '`rustc_splat` attribute'
# I'm pretty sure the symbol demangling commands are no-ops on beta
# Legacy symbol demangling
fastmod --fixed-strings '$splat$' '$rustc_splat$'
# Revert some changes that aren't in rustc_demangle yet
fastmod 'v0(.*)#\[rustc_splat\]' 'v0${1}#[splat]' tests/ui/splat/splat-mangling.rs
```
Part of rust-lang/rust#159428
#### Backport Advice
Cherry-pick the first commit to the beta branch, then run the fastmod commands above.
I've tested this locally (with a slightly different name), and it works, see my [`splat-rename-beta` branch](https://github.com/teor2345/rust/tree/splat-rename-beta).
#### Remaining Work
rustc_demangle needs an update to the attribute name, a release, and then a version bump in rust-lang/rust. I'll do that separately. It doesn't need to be backported, because the last version bump was after beta branched.
There's also some external code that needs updates, the full list is in the ticket: https://github.com/rust-lang/rust/issues/159428#issuecomment-5040163201
@rustbot label +beta-nominated +A-attributes +A-macros +A-resolve +C-bug +F-splat +P-high +T-compiler
Remove unused `va_start` intrinsic
The `va_start` intrinsic isn't declared in `core::intrinsics` or used to implement Rust `VaList` support ([the compiler calls `bx.va_start` directly in `rustc_codegen_ssa`](b5be620d5a/compiler/rustc_codegen_ssa/src/mir/mod.rs (L523))), therefore this PR removes it.
Generate `valid_range`s for enums sign-agnostically
Prompted by https://github.com/rust-lang/rust/issues/159438#issuecomment-5007170897, this reworks the generation of the tag layout information for enums.
Having gone down the wrong path at first here, I think the core trouble this is having is that the current calculation is trying to serve two incompatible desires:
- When picking the `value: Primitive`, we need to respect the signedness of the original *discriminant* numbers as typed in Rust.
- When picking the `valid_range: WrappingRange`, we want to *ignore* the signedness (and size!) of the discriminants and look only at the bit values (and size) of the *tags* themselves.
This thus splits the handling in `layout_of_enum` into those two parts, handled differently.
- When looking at *discriminants* (to eventually call [`discr_range_of_repr`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/layout/trait.IntegerExt.html#tymethod.discr_range_of_repr)), we obey the signedness of the inputs to find the smallest negative discriminant and largest positive discriminant -- notably *without* any wraparound logic.
- Then after having used the discriminants to pick a *tag* size, then we run a wrapping-aware check to pick the best `WrappingRange` to represent those tags (which can be a different range than we'd have picked on the discriminants, especially for `repr(Rust)` where the discriminants are `isize`).
With apologies for sending this when you'd said you'd look at it, but I got inspired 😅
r? @oli-obk
Fixesrust-lang/rust#159438
---
I have a bunch of commits in here; it's probably best reviewed one at a time.
1. Just moving `WrappingRange` to its own file, since the `lib.rs` is over 2000 lines already so if I was going to add stuff I figured some reorganizing could help.
2. Adding a new constructor to `WrappingRange` that takes an iterator of values and returns a range containing those values. Dealing just in `u128` + `Size`, like `WrappingRange` does in other places, it doesn't even *have* signedness information so structurally is prevented from having any "why are `repr(u8)` and `repr(i8) picking different ranges?" issues. I found it helpful to have this split out from the layout code, for example that it let me put some examples on the doc-comment. Nothing actually *uses* the new function in this commit though.
3. Stop giving layout discriminants as `i128` since <https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/util/struct.Discr.html#structfield.val> points out that they're generated as `u128` in the same way that `WrappingRange` uses already -- even with the field doc that `-1_i8` is generated as `255_u128`, so the `as i128`ing was probably just making everything more confusing here than it needed to be.
4. Adding some tests looking at the generated `Primitive` and `valid_range`, along with rustc support for `#[rustc_dump_layout(largest_niche)]` to help have these tests include specific ERROR annotations rather than just the stderr. The tests pass at this point, so the next commit can update them to show the change.
5. This one actually updates layout code, including using the `WrappingRange` constructor added earlier.
Split register_tool into register_attribute_tool and register_lint_tool
Tracking issue: rust-lang/rust#66079
This implements the attribute parsing part of RFC 3808. The resolution part is yet to be implemented.
cc @jyn514
Lint against iterator functions that panic when `N` is zero
This PR extends the deny-by-default `unconditional_panic` lint, by linting on iterator functions that panics when `N` (chunks/windows size) is zero[^attr].
Those methods are [documented](https://doc.rust-lang.org/std/primitive.slice.html#panics-11) to panic if `N` is zero.
```
error: this operation will panic at runtime
--> $DIR/const-n-is-zero.rs:11:13
|
LL | let _ = s.array_windows::<0>();
| ^^^^^^^^^^^^^^^^^^^^^^ const parameter `N` is zero
|
= note: `#[deny(unconditional_panic)]` on by default
```
cc @rust-lang/libs-api
[^attr]: this is done by introducing a new internal attribute on the const parameter: `#[rustc_panics_when_zero]`
This splits the functionality to two parts per RFC. The `#![register_tool]`
attribute registers the tool in both ways.
Semantics remain unchanged and will be adjusted in later commit.
Support using const pointers in asm `const` operand
Implements [RFC#3848](https://github.com/rust-lang/rfcs/pull/3848) with tracking issue rust-lang/rust#128464
This adds support of const pointers for asm `const` in addition to plain integers.
The inline `asm!` support is implemented using `i` constraint, and the `global_asm!` and `naked_asm!` support is implemented by inserting `symbol + offset` and make `symbol` compiler-used. For unnamed consts, it will create additional internal & hidden symbols so that they can be referenced by global_asm.
~~The feature is also implemented for GCC backend but it's untested.~~ Tested now.
implement #![feature(macroless_generic_const_args)]
tracking issue: https://github.com/rust-lang/rust/issues/159006
lots of description of what is happening here in the tracking issue, not gonna copypaste it into here :)
the test situation is that after discussion with boxy of whether our mgca tests should be:
- keep them under only `min_generic_const_args`, and add `direct_const_arg!()` where it's needed
- keep the code contents as-is, and add `#![feature(macroless_generic_const_args)]` where it's needed
the second seems more desirable, so that's what I did. There are still quite a few tests that only have `min_generic_const_args` without `macroless_generic_const_args` (140 of them, to be exact - `rg --files-without-match macroless_generic_const_args $(rg -g '*.rs' --files-with-matches min_generic_const_args tests) | wc -l`, and now 90 with `macroless_generic_const_args`)
r? @BoxyUwU