309554 Commits

Author SHA1 Message Date
Brian Cain
71e599b91a Make named asm_labels lint not trigger on hexagon register spans 2025-11-05 16:24:30 -06:00
bors
b01cc1cf01 Auto merge of #148516 - bjorn3:target_feature_parsing_improvements, r=WaffleLapkin
Move warning reporting from flag_to_backend_features to cfg_target_feature

This way warnings are emitted even in a check build.
2025-11-05 17:56:16 +00:00
bors
1ef7943ee6 Auto merge of #148302 - folkertdev:non-rustic-unsized, r=bjorn3
error on non-rustic ABIs using unsized parameters

tracking issue: https://github.com/rust-lang/rust/issues/48055

This came up in https://github.com/rust-lang/rust/pull/144529#discussion_r2470214068.

The idea is that the layout of an unsized type is unstable (following the rust layout rules), and hence stable ABIs should not use unsized types. On stable, unsized types (or generics with a `?Sized` bound) are not accepted as parameters, so the errors introduced by this PR can only be observed when the unstable `unsized_fn_params` feature is enabled.

r? `@bjorn3`
cc `@RalfJung`
2025-11-05 14:07:06 +00:00
Folkert de Vries
8e44e3f6a9
error on non-rustic ABIs using unsized parameters 2025-11-05 12:12:10 +01:00
bors
53efb3d4f3 Auto merge of #148492 - pmur:murp/ppc-relax-r29-inlineasm, r=Amanieu
Relax r29 inline asm restriction on PowerPC64 targets

LLVM uses r29 to hold a base pointer for some PowerPC target configurations. It is usable on all 64 bit targets as a callee save register.

r? `@Amanieu`
2025-11-05 10:55:49 +00:00
bjorn3
1d34478147 Move warning reporting from flag_to_backend_features to cfg_target_feature
This way warnings are emitted even in a check build.
2025-11-05 10:48:29 +00:00
bors
8e0b68e63c Auto merge of #148507 - Zalathar:rollup-vvz4knr, r=Zalathar
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#147355 (Add alignment parameter to `simd_masked_{load,store}`)
 - rust-lang/rust#147925 (Fix tests for big-endian)
 - rust-lang/rust#148341 (compiler: Fix a couple issues around cargo feature unification)
 - rust-lang/rust#148371 (Dogfood `trim_{suffix|prefix}` in compiler)
 - rust-lang/rust#148495 (Implement Path::is_empty)
 - rust-lang/rust#148502 (rustc-dev-guide subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-05 07:25:39 +00:00
bors
c0ff72ffc4 Auto merge of #147645 - tamird:arch-enum, r=nnethercote
rustc_target: introduce Arch

Improve type safety by using an enum rather than strings.
2025-11-05 04:15:09 +00:00
Tamir Duberstein
26b0560b6d
rustc_target: allow unenumerated architectures 2025-11-04 21:28:28 -05:00
Tamir Duberstein
0c8533d690
compiler: intern architecture at compile time 2025-11-04 21:27:23 -05:00
Tamir Duberstein
270e49b307
rustc_target: introduce Arch
Improve type safety by using an enum rather than strings.
2025-11-04 21:27:22 -05:00
Tamir Duberstein
cf053b3774
rustc_target::spec::base:🍎 nix use Arch::*
This will reduce ambiguity with `rustc_target::spec::Arch`.
2025-11-04 21:20:22 -05:00
Tamir Duberstein
5e73e6593f
rename rustc_target::spec::abi_map::Arch{,Kind}
This makes way for `rustc_target::spec::Arch`.
2025-11-04 21:20:21 -05:00
Stuart Cook
41382a4bf0
Rollup merge of #148502 - tshepang:rdg-sync, r=tshepang
rustc-dev-guide subtree update

Subtree update of `rustc-dev-guide` to 1a96e5eb17.

Created using https://github.com/rust-lang/josh-sync.

r? `@ghost`
2025-11-05 10:59:21 +11:00
Stuart Cook
6e03719029
Rollup merge of #148495 - ChrisDenton:path_is_empty, r=workingjubilee
Implement Path::is_empty

This implements `Path::is_empty` which is simply a convenience wrapper for `path.as_os_str().is_empty()`.

Tracking issue: https://github.com/rust-lang/rust/issues/148494
ACP: https://github.com/rust-lang/libs-team/issues/687
2025-11-05 10:59:20 +11:00
Stuart Cook
21da1760da
Rollup merge of #148371 - yotamofek:pr/dogfood-trim-prefix-suffix, r=fee1-dead
Dogfood `trim_{suffix|prefix}` in compiler

cc rust-lang/rust#142312
2025-11-05 10:59:19 +11:00
Stuart Cook
cc1d776c1f
Rollup merge of #148341 - jyn514:feature-unification, r=BoxyUwU
compiler: Fix a couple issues around cargo feature unification

cc https://github.com/rust-lang/rust/issues/148266. this doesn't fix all the issues (`rustc_public` and `rustc_transmute` still emit warnings when tested individually), but it fixes all the simple ones.

To fix rustc_public I will probably need help from ````@AlexanderPortland```` or ````@makai410```` to make sure I am not accidentally cfg-ing out items that are meant to be public. To fix `rustc_transmute`, I will need to know (from ````@jswrenn```` ?) in what context the `rustc` cargo feature is disapled. To reproduce the issues, you can run `x test rustc_{transmute,public}` locally.

---

The first issue I fixed was a warning in `rustc_index`:
```
Testing stage2 {rustc_parse_format} (aarch64-apple-darwin)
   Compiling rustc_index v0.0.0 (/Users/ci/project/compiler/rustc_index)
error: extern crate `smallvec` is unused in crate `rustc_index`
 --> compiler/rustc_index/src/lib.rs:2:1
  |
2 | #![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
  | ^
  |
  = help: remove the dependency or add `use smallvec as _;` to the crate root
  = note: `-D unused-crate-dependencies` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(unused_crate_dependencies)]`

error: could not compile `rustc_index` (lib) due to 1 previous error
```

The second was that `type_ir_macros` didn't fully specify its dependencies:
```
Testing stage1 {rustc_type_ir_macros} (aarch64-apple-darwin)
   Compiling rustc_type_ir_macros v0.0.0 (/Users/jyn/src/ferrocene3/compiler/rustc_type_ir_macros)
error[E0432]: unresolved import `syn::visit_mut`
   --> compiler/rustc_type_ir_macros/src/lib.rs:2:10
    |
  2 | use syn::visit_mut::VisitMut;
    |          ^^^^^^^^^ could not find `visit_mut` in `syn`
    |
note: found an item that was configured out
   --> /Users/jyn/.local/lib/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.106/src/lib.rs:880:21
    |
878 | #[cfg(feature = "visit-mut")]
    |       --------------------- the item is gated behind the `visit-mut` feature
879 | #[cfg_attr(docsrs, doc(cfg(feature = "visit-mut")))]
880 | pub use crate::gen::visit_mut;
    |                     ^^^^^^^^^

error[E0433]: failed to resolve: could not find `visit_mut` in `syn`
   --> compiler/rustc_type_ir_macros/src/lib.rs:206:18
    |
206 |             syn::visit_mut::visit_type_path_mut(self, i);
    |                  ^^^^^^^^^ could not find `visit_mut` in `syn`
    |
note: found an item that was configured out
   --> /Users/jyn/.local/lib/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.106/src/lib.rs:880:21
    |
878 | #[cfg(feature = "visit-mut")]
    |       --------------------- the item is gated behind the `visit-mut` feature
879 | #[cfg_attr(docsrs, doc(cfg(feature = "visit-mut")))]
880 | pub use crate::gen::visit_mut;
    |                     ^^^^^^^^^
```
2025-11-05 10:59:19 +11:00
Stuart Cook
aa458ff6bc
Rollup merge of #147925 - fneddy:fix_big_endian_GVN_tests, r=saethlin
Fix tests for big-endian

The tests fail on s390x and presumably other big-endian systems, due to check of raw alloc values in the MIR output.

To fix the tests remove the raw bytes from the MIR output (via: compile-flags: -Zdump-mir-exclude-alloc-bytes) and update the matching diffs.
2025-11-05 10:59:18 +11:00
Stuart Cook
c33d51b9d8
Rollup merge of #147355 - sayantn:masked-loads, r=RalfJung,bjorn3
Add alignment parameter to `simd_masked_{load,store}`

This PR adds an alignment parameter in `simd_masked_load` and `simd_masked_store`, in the form of a const-generic enum `core::intrinsics::simd::SimdAlign`. This represents the alignment of the `ptr` argument in these intrinsics as follows

 - `SimdAlign::Unaligned` - `ptr` is unaligned/1-byte aligned
 - `SimdAlign::Element` - `ptr` is aligned to the element type of the SIMD vector (default behavior in the old signature)
 - `SimdAlign::Vector` - `ptr` is aligned to the SIMD vector type

The main motive for this is stdarch - most vector loads are either fully aligned (to the vector size) or unaligned (byte-aligned), so the previous signature doesn't cut it.

Now, stdarch will mostly use `SimdAlign::Unaligned` and `SimdAlign::Vector`, whereas portable-simd will use `SimdAlign::Element`.

 - [x] `cg_llvm`
 - [x] `cg_clif`
 - [x] `miri`/`const_eval`

## Alternatives

Using a const-generic/"const" `u32` parameter as alignment (and we error during codegen if this argument is not a power of two). This, although more flexible than this, has a few drawbacks

 - If we use an const-generic argument, then portable-simd somehow needs to pass `align_of::<T>()` as the alignment, which isn't possible without GCE
 - "const" function parameters are just an ugly hack, and a pain to deal with in non-LLVM backends

We can remedy the problem with the const-generic `u32` parameter by adding a special rule for the element alignment case (e.g. `0` can mean "use the alignment of the element type), but I feel like this is not as expressive as the enum approach, although I am open to suggestions

cc `@workingjubilee` `@RalfJung` `@BoxyUwU`
2025-11-05 10:59:18 +11:00
bors
6e41e61977 Auto merge of #145314 - estebank:issue-135589-all, r=Nadrieril
Tweak output of missing lifetime on associated type

Follow up to https://github.com/rust-lang/rust/pull/135602.

Previously we only showed the trait's assoc item if the trait was local, because we were looking for a small span only for the generics, which we don't have for foreign traits. We now use `def_span` for the item, so we at least provide some context, even if its span is too wide.

```
error[E0195]: lifetime parameters or bounds on type `IntoIter` do not match the trait declaration
   --> tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.rs:7:18
    |
7   |     type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
    |                  ^^^^ lifetimes do not match type in trait
    |
   ::: /home/gh-estebank/rust/library/core/src/iter/traits/collect.rs:292:5
    |
292 |     type IntoIter: Iterator<Item = Self::Item>;
    |     ------------------------------------------ lifetimes in impl do not match this type in trait
```

Given an associated item that needs a named lifetime, look at the enclosing `impl` item for one. If there is none, look at the self type and the implemented trait to see if either of those has an anonimous lifetime. If so, suggest adding a named lifetime.

```
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
  --> $DIR/missing-lifetime-in-assoc-type-2.rs:5:17
   |
LL |     type Item = &T;
   |                 ^ this lifetime must come from the implemented type
   |
help: add a lifetime to the impl block and use it in the self type and associated type
   |
LL ~ impl<'a> IntoIterator for &'a S {
LL ~     type Item = &'a T;
   |
```

Move the previous long message to a note and use a shorter primary message:

```
error: missing lifetime in associated type
  --> $DIR/missing-lifetime-in-assoc-type-1.rs:9:17
   |
LL | impl<'a> IntoIterator for &S {
   |     ---- there is a named lifetime specified on the impl block you could use
...
LL |     type Item = &T;
   |                 ^ this lifetime must come from the implemented type
   |
note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
  --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
help: consider using the lifetime from the impl block
   |
LL |     type Item = &'a T;
   |                  ++
```

r? `@Nadrieril`
2025-11-04 21:37:44 +00:00
Tshepang Mbambo
dca1727025
Merge pull request #2628 from rust-lang/tshepang/sembr
sembr src/contributing.md and improve it a bit
2025-11-04 23:35:45 +02:00
Tshepang Mbambo
743b803fae date-check src/contributing.md
Had a look due to reviewing sembr changes
2025-11-04 23:35:11 +02:00
Tshepang Mbambo
56757ab897 sembr: adjust after using src/contributing.md 2025-11-04 23:35:11 +02:00
Tshepang Mbambo
2dee8525ac misc improvents to src/contributing.md 2025-11-04 23:35:11 +02:00
Chris Denton
7e66d6c3b9
Implement Path::is_empty 2025-11-04 19:23:51 +00:00
Paul Murphy
5f6fa960c2 Relax r29 inline asm restriction on PowerPC64 targets
LLVM uses r29 to hold a base pointer for some PowerPC target
configurations. It is usable on all 64 bit targets as a callee
save register.
2025-11-04 12:08:19 -06:00
Tshepang Mbambo
b150b0eddb sembr src/contributing.md 2025-11-04 19:27:48 +02:00
bors
f15a7f3858 Auto merge of #148471 - lnicola:sync-from-ra, r=lnicola
`rust-analyzer` subtree update

Subtree update of `rust-analyzer` to 51af7a37c5.

Created using https://github.com/rust-lang/josh-sync.

r? `@ghost`
2025-11-04 17:23:40 +00:00
Tshepang Mbambo
18b1767286
Merge pull request #2627 from rust-lang/tshepang/sembr
sembr src/tests/minicore.md and bump freshness
2025-11-04 18:58:55 +02:00
Tshepang Mbambo
df4d8830bb date-check src/tests/minicore.md
This was updated recently.

Also, the annotation was broken, so would not appear in date-check issue.
2025-11-04 18:56:17 +02:00
Tshepang Mbambo
0588be0997 sembr src/tests/minicore.md 2025-11-04 18:47:40 +02:00
bors
e5efc33672 Auto merge of #148472 - Zalathar:rollup-zwlz09o, r=Zalathar
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#144529 (Add `#[rustc_pass_indirectly_in_non_rustic_abis]`)
 - rust-lang/rust#147017 (FCW for repr(C) enums whose discriminant values do not fit into a c_int or c_uint)
 - rust-lang/rust#148459 (bootstrap: Split out a separate `./x test bootstrap-py` step)
 - rust-lang/rust#148468 (add logging to `fudge_inference_if_ok`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-04 12:09:10 +00:00
Stuart Cook
4f3816be6f
Rollup merge of #148468 - lcnr:opaques-early-binder, r=lqd
add logging to `fudge_inference_if_ok`

it was useful when debugging https://github.com/rust-lang/trait-system-refactor-initiative/issues/252
2025-11-04 23:01:12 +11:00
Stuart Cook
07192879f4
Rollup merge of #148459 - Zalathar:bootstrap-py, r=Kobzol
bootstrap: Split out a separate `./x test bootstrap-py` step

While testing changes to bootstrap, I was annoyed by the fact that `./x test bootstrap` spams a bunch of mysterious output to the console.

That output turns out to come from `bootstrap_test.py`, which runs unit tests for the Python parts of bootstrap. Those tests are (presumably) useful, but they don't add value when working on the Rust parts of bootstrap.

This PR therefore pulls them out into a separate test step that can be run with `./x test bootstrap-py`.
2025-11-04 23:01:11 +11:00
Stuart Cook
b40a20f16d
Rollup merge of #147017 - RalfJung:repr-c-big-discriminant, r=davidtwco
FCW for repr(C) enums whose discriminant values do not fit into a c_int or c_uint

Context: https://github.com/rust-lang/rust/issues/124403

The current behavior of repr(C) enums is as follows:
- The discriminant values are interpreted as const expressions of type `isize`
- We compute the smallest size that can hold all discriminant values
- The target spec contains the smallest size for repr(C) enums
- We take the larger of these two sizes

Unfortunately, this doesn't always match what C compilers do. In particular, MSVC seems to *always* give enums a size of 4 bytes, whereas the algorithm above will give enums a size of up to 8 bytes on 64bit targets. Here's an example enum affected by this:
```
// We give this size 4 on 32bit targets (with a warning since the discriminant is wrapped to fit an isize)
// and size 8 on 64bit targets.
#[repr(C)]
enum OverflowingEnum {
    A = 9223372036854775807, // i64::MAX
}

// MSVC always gives this size 4 (without any warning).
// GCC always gives it size 8 (without any warning).
// Godbolt: https://godbolt.org/z/P49MaYvMd
enum overflowing_enum {
    OVERFLOWING_ENUM_A = 9223372036854775807,
};
```

If we look at the C standard, then up until C20, there was no official support enums without an explicit underlying type and with discriminants that do not fit an `int`. With C23, this has changed: now enums have to grow automatically if there is an integer type that can hold all their discriminants. MSVC does not implement this part of C23.

Furthermore, Rust fundamentally cannot implement this (without major changes)! Enum discriminants work fundamentally different in Rust and C:
- In Rust, every enum has a discriminant type entirely determined by its repr flags, and then the discriminant values must be const expressions of that type. For repr(C), that type is `isize`. So from the outset we interpret 9223372036854775807 as an isize literal and never give it a chance to be stored in a bigger type. If the discriminant is given as a literal without type annotation, it gets wrapped implicitly with a warning; otherwise the user has to write `as isize` explicitly and thus trigger the wrapping. Later, we can then decide to make the *tag* that stores the discriminant smaller than the discriminant type if all discriminant values fit into a smaller type, but those values have allready all been made to fit an `isize` so nothing bigger than `isize` could ever come out of this. That makes the behavior of 32bit GCC impossible for us to match.
-  In C, things flow the other way around: every discriminant value has a type determined entirely by its constant expression, and then the type for the enum is determined based on that. IOW, the expression can have *any type* a priori, different variants can even use a different type, and then the compiler is supposed to look at the resulting *values* (presumably as mathematical integers) and find a type that can hold them all. For the example above, 9223372036854775807 is a signed integer, so the compiler looks for the smallest signed type that can hold it, which is `long long`, and then uses that to compute the size of the enum (at least that's what C23 says should happen and GCC does this correctly).

Realistically I think the best we can do is to not attempt to support C23 enums, and to require repr(C) enums to satisfy the C20 requirements: all discriminants must fit into a c_int. So that's what this PR implements, by adding a FCW for enums with discriminants that do not fit into `c_int`. As a slight extension, we do *not* lint enums where all discriminants fit into a `c_uint` (i.e. `unsigned int`): while C20 does (in my reading) not allow this, and C23 does not prescribe the size of such an enum, this seems to behave consistently across compilers (giving the enum the size of an `unsigned int`). IOW, the lint fires whenever our layout algorithm would make the enum larger than an `int`, irrespective of whether we pick a signed or unsigned discriminant. This extension was added because [crater found](https://github.com/rust-lang/rust/pull/147017#issuecomment-3357077199) multiple cases of such enums across the ecosystem.

Note that it is impossible to trigger this FCW on targets where isize and c_int are the same size (i.e., the typical 32bit target): since we interpret discriminant values as isize, by the time we look at them, they have already been wrapped. However, we have an existing lint (overflowing_literals) that should notify people when this kind of wrapping occurs implicitly. Also, 64bit targets are much more common. On the other hand, even on 64bit targets it is possible to fall into the same trap by writing a literal that is so big that it does not fit into isize, gets wrapped (triggering overflowing_literals), and the wrapped value fits into c_int. Furthermore, overflowing_literals is just a lint, so if it occurs in a dependency you won't notice. (Arguably there is also a more general problem here: for literals of type `usize`/`isize`, it is fairly easy to write code that only triggers `overflowing_literals` on 32bit targets, and to never see that lint if one develops on a 64bit target.)

Specifically, the above example triggers the FCW on 64bit targets, but on 32bit targets we get this err-by-default lint instead (which will be hidden if it occurs in a dependency):
```
error: literal out of range for `isize`
  --> $DIR/repr-c-big-discriminant1.rs:16:9
   |
LL |     A = 9223372036854775807,
   |         ^^^^^^^^^^^^^^^^^^^
   |
   = note: the literal `9223372036854775807` does not fit into the type `isize` whose range is `-2147483648..=2147483647`
   = note: `#[deny(overflowing_literals)]` on by default
```
Also see the tests added by this PR.

This isn't perfect, but so far I don't think I have seen a better option. In https://github.com/rust-lang/rust/pull/146504 I tried adjusting our enum logic to make the size of the example enum above actually match what C compilers do, but that's a massive breaking change since we have to change the expected type of the discriminant expression from `isize` to `i64` or even `i128` -- so that seems like a no-go. To improve the lint we could analyze things on the HIR level and specifically catch "repr(C) enums with discriminants defined as literals that are too big", but that would have to be on top of the lint in this PR I think since we'd still want to also always check the actually evaluated value (which we can't always determined on the HIR level).

Cc `@workingjubilee` `@CAD97`
2025-11-04 23:01:10 +11:00
Stuart Cook
fa9ea6d918
Rollup merge of #144529 - beetrees:pass-indirectly-attr, r=bjorn3
Add `#[rustc_pass_indirectly_in_non_rustic_abis]`

This PR adds an internal `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute that can be applied to structs. Structs marked with this attribute will always be passed using `PassMode::Indirect { on_stack: false, .. }` when being passed by value to functions with non-Rustic calling conventions. This is needed by rust-lang/rust#141980; see that PR for further details.

cc `@joshtriplett`
2025-11-04 23:01:10 +11:00
lcnr
5f312079f2 add logging to fudge_inference_if_ok 2025-11-04 12:03:19 +01:00
Ralf Jung
a92bae0b1c do not complain about enums where all discriminants fit into a c_uint 2025-11-04 11:44:55 +01:00
Ralf Jung
8b96fbecb6 FCW for repr(C) enums whose discriminant values do not fit into a c_int 2025-11-04 11:44:55 +01:00
Ralf Jung
add37c0c25 extend some comments and clarify some names around enum tag type computation 2025-11-04 11:32:16 +01:00
Folkert de Vries
7be6d6f2e8
additional tests for pass_indirectly_in_non_rustic_abis
Also emit an error when `rustc_pass_indirectly_in_non_rustic_abis` is
used in combination with `repr(transparent)`.
2025-11-04 10:05:02 +01:00
Folkert de Vries
1866b3a8cf
assert that #[rustc_pass_indirectly_in_non_rustic_abis] is respected 2025-11-04 09:56:21 +01:00
beetrees
7354d3d9c2
Add #[rustc_pass_indirectly_in_non_rustic_abis] 2025-11-04 09:56:17 +01:00
Laurențiu Nicola
5873327cd4
Merge pull request #20960 from rust-lang/rustc-pull
minor: Rustc pull update
2025-11-04 08:18:22 +00:00
Laurențiu Nicola
d81d5f0b70 Fix test URL 2025-11-04 10:09:45 +02:00
Chayim Refael Friedman
934b58eecc
Merge pull request #20966 from ChayimFriedman2/fix-test-name
minor: Fix test name
2025-11-04 08:07:36 +00:00
Chayim Refael Friedman
fe6abc79d2 Fix test name 2025-11-04 09:58:29 +02:00
Shoyu Vanilla (Flint)
9cec4316c0
Merge pull request #20565 from A4-Tacks/conv-range-for-to-while
Add ide-assist: convert_range_for_to_while
2025-11-04 05:59:34 +00:00
A4-Tacks
a925768250
Add dynamic assistant description 2025-11-04 13:50:09 +08:00
A4-Tacks
9e9ea26d64
Add ide-assist: convert_range_for_to_while
Convert for each range into while loop.

```rust
fn foo() {
    $0for i in 3..7 {
        foo(i);
    }
}
```
->
```rust
fn foo() {
    let mut i = 3;
    while i < 7 {
        foo(i);
        i += 1;
    }
}
```
2025-11-04 13:31:41 +08:00