Commit Graph

55 Commits

Author SHA1 Message Date
Moulins 75015f405a Remove per-variant alignment in VariantLayout
Reusing the alignment of the enclosing enum in `LayoutData::for_variant`
doesn't appear to cause any issues.
2026-05-15 04:34:51 +02:00
Moulins 3459964408 Remove unused VariantLayout.randomization_seed field
This field is only used during layout calculations, so re-synthetized
`LayoutData`s for enum variants can use a dummy value instead.
2026-05-15 04:34:51 +02:00
Moulins 0569574938 Store FieldsShape::Arbitrary fields directly in VariantLayout
Enum variants always have `Arbitrary` layout, so the enum isn't needed.
2026-05-15 04:34:51 +02:00
Moulins 1162bdc1f3 Remove redundant VariantLayout.variants field
It was always set to `Variants::Single`.
2026-05-15 04:34:48 +02:00
Moulins 464dc07de2 Introduce VariantLayout struct
For now, this is a 1-to-1 copy of `LayoutData`, but this will change.
2026-05-15 04:34:17 +02:00
Oli Scherer 11d88ee42b Rip out rustc_layout_scalar_valid_range_* attribute support 2026-05-03 10:59:52 +02:00
bors bd1e7c7948 Auto merge of #153815 - GokhanKabar:fix-ice-enum-discr-generic-self, r=BoxyUwU
Fix ICE when Self is used in enum discriminant of a generic enum



Fixes rust-lang/rust#153756
Let discriminant AnonConst inherit parent generics via Node::Variant in generics_of, and emit a proper error instead of span_bug! for the TooGeneric case in wfcheck.
2026-04-15 01:58:56 +00:00
GokhanKabar aacac7e2e3 Fix ICE when Self is used in enum discriminant of a generic enum
* Fix ICE when Self is used in enum discriminant of a generic enum

Move the validation into the existing `check_param_uses_if_mcg` machinery
in HIR ty lowering instead of adding a new check in wfcheck. After the
`AnonConstKind` refactoring, `ForbidMCGParamUsesFolder` was only gated on
`AnonConstKind::MCG`, causing discriminant anon consts (`NonTypeSystem`) to
bypass it entirely.

Add `anon_const_forbids_generic_params()` which returns the appropriate
`ForbidParamContext` for both MCG and enum discriminant contexts. Wire it
into `check_param_uses_if_mcg` so that `Self` aliasing a generic type is
caught before reaching `const_eval_poly`. Convert the `TooGeneric` span_bug
into a proper diagnostic as a fallback for anything slipping through
type-dependent path resolution.
* Address review comments

- Rename `ForbidMCGParamUsesFolder` to `ForbidParamUsesFolder`
- Rename `MinConstGenerics` variant to `ConstArgument` with updated doc
- Simplify doc comment on `anon_const_forbids_generic_params`
- Make match on `AnonConstKind` exhaustive
- Move `anon_const_def_id` inside the `if let` in `check_param_uses_if_mcg`
- Remove now-unreachable `TooGeneric` span_err in wfcheck
* Revert TooGeneric arm back to span_bug! as requested by reviewer
* Use generics_of to determine if NonTypeSystem anon consts allow generic params
* Also check InlineConst and Closure defs nested in enum discriminants
* Simplify logic for determining anonymous constant parent in generic contexts
* add test
2026-04-14 14:32:11 +00:00
León Orell Valerian Liehr 357f670fde Rename #[rustc_layout] to #[rustc_dump_layout] 2026-04-10 12:13:48 +02:00
Esteban Küber 87d8f5885b Provide more context on type errors in const context
- On `const` and `static` point at the type (like we do for let bindings)
- On fn calls, point at const parameter in fn definition
- On type, point at const parameter in type definition
- On array type lengths, explain that array length is always `usize`
- On enum variant discriminant, mention `repr`
2026-03-14 20:13:43 +00:00
Guillaume Gomez e1ee66935e Remove TyCtxt::node_span_lint usage from rustc_hir_analysis 2026-03-05 23:53:54 +01:00
Nicholas Nethercote 52b4de34ec Abort after printing infinite type errors.
Currently, `Representability::from_cycle_error` prints an "infinite
size" error and then returns `Representability::Infinite`, which lets
analysis continue. This commit changes it so it just aborts after
printing the error. This has two benefits.

First, the error messages are better. The error messages we get after
continuing are mostly bad -- we usually get another cycle error, e.g.
about drop checking or layout, which is not much use to the user, and
then abort after that. The only exception is `issue-105231.rs` where a
"conflicting implementations" error is now omitted, but there are three
other errors before that one so it's no great loss.

Second, it allows some simplifications: see the next commit.
2026-03-04 07:02:36 +11:00
cyrgani 28fc413c8f remove #![allow(stable_features)] from most tests 2026-02-17 08:45:08 +00:00
Moulins b31ee3af9c layout: Store inverse memory index in FieldsShape::Arbitrary
All usages of `memory_index` start by calling `invert_bijective_mapping`, so
storing the inverted mapping directly saves some work and simplifies the code.
2025-12-18 22:25:34 +01:00
Matthias Krüger 02434fe718 Rollup merge of #148678 - xonx4l:EO412_replacement_with_EO425, r=Kivooeo
Merge E0412 into E0425

This PR merge E0412 into E0425  as both mean the same thing to users.

This fixes https://github.com/rust-lang/rust/issues/148558.
2025-12-02 22:02:30 +01:00
xonx4l 4b000cfacd Merge E0412 into E0425 2025-12-02 18:25:13 +00:00
Scott McMurray 673be1b82a Use a delayed bug for this layout ICE
Fixes 144501
2025-11-28 14:49:42 -08:00
yukang eaf979e8dd Fix ICE from lit_to_mir_constant caused by type error 2025-11-05 20:26:43 +08: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
Camille GILLOT 5620c82e53 Report uninhabited call return types on MIR. 2025-10-11 20:50:20 +00:00
Jacob Pratt 5bd4e832d3 Rollup merge of #144553 - Oneirical:uncountable-integer-4, r=jieyouxu
Rehome 32 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`

rust-lang/rust#143902 divided into smaller, easier to review chunks.

Part of rust-lang/rust#133895

Methodology:

1. Refer to the previously written `tests/ui/SUMMARY.md`
2. Find an appropriate category for the test, using the original issue thread and the test contents.
3. Add the issue URL at the bottom (not at the top, as that would mess up stderr line numbers)
4. Rename the tests to make their purpose clearer

Inspired by the methodology that `@Kivooeo` was using.

r? `@jieyouxu`
2025-08-10 15:43:52 -04:00
Oneirical aa543963c6 Rehome tests/ui/issues/ tests [4/?] 2025-08-10 11:54:15 -04:00
Oli Scherer 75bdbf25e3 Pick the largest niche even if the largest niche is wrapped around 2025-07-29 14:08:15 +00:00
Oli Scherer 45b0c8d03e Add regression test 2025-07-28 10:29:02 +00:00
Oli Scherer e44a7386c2 Remove dead code and extend test coverage and diagnostics around it
We lost the following comment during refactorings:

The current code for niche-filling relies on variant indices instead of actual discriminants, so enums with explicit discriminants (RFC 2363) would misbehave.
2025-07-24 10:21:20 +00:00
Oli Scherer 9b5d57d0a9 Unconditionally run check_item_type on all items 2025-06-30 08:06:08 +00:00
Ralf Jung 17946c22b1 const-eval error: always say in which item the error occurred
also adjust the wording a little so that we don't say "the error occurred here" for two different spans
2025-06-07 13:42:30 +02:00
Oli Scherer 020216c31c Clarify why we are talking about a failed const eval at a random place 2025-06-02 15:37:15 +00:00
Oli Scherer b331b8b96d Use the informative error as the main const eval error message 2025-06-02 15:37:15 +00:00
beetrees 467eeabbb5 Stabilise repr128 2025-05-28 15:14:34 +01:00
Vadim Petrochenkov 20faf8532b compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
Vadim Petrochenkov b3f75353a2 UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
Esteban Küber f0845adb0c Show diff suggestion format on verbose replacement
```
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
  --> $DIR/attempted-access-non-fatal.rs:7:15
   |
LL |     let _ = 2.l;
   |               ^
   |
help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix
   |
LL -     let _ = 2.l;
LL +     let _ = 2.0f64;
   |
```
2025-02-10 20:21:39 +00:00
FedericoBruzzone cef97bce7b Add TooGeneric variant to LayoutError and emit Unknown one
- `check-pass` test for a MRE of #135020
- fail test for #135138
- switch to `TooGeneric` for checking CMSE fn signatures
- switch to `TooGeneric` for compute `SizeSkeleton` (for transmute)
- fix broken tests
2025-01-27 00:37:34 +01:00
Michael Goulet b89a6e4932 Consider more erroneous layouts as LayoutError::ReferencesError to suppress spurious errors 2025-01-14 19:07:37 +00:00
Ralf Jung ed8ee39930 fix ICE on type error in promoted 2024-12-09 15:17:26 +01:00
Ralf Jung a17294dc0f fix ICE when promoted has layout size overflow 2024-12-01 19:52:27 +01:00
The 8472 97b84e40cb add tests for niches in pointers 2024-11-30 16:00:55 +01:00
Nadrieril 99468bb760 Update tests 2024-08-10 12:07:17 +02:00
许杰友 Jieyou Xu (Joe) ec2cc761bc [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
León Orell Valerian Liehr 02320b502d Improve the diagnostics for unused generic parameters 2024-02-01 16:18:03 +01:00
Oli Scherer db7cd57091 Remove track_errors entirely 2024-01-23 15:23:22 +00:00
Jake Goulding 53eca9fa87 Adjust compiler tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
Nilstrieb 41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Maybe Waffle 70f28a9110 Move tests from ui/discrim dir 2023-06-08 12:33:17 +00:00
Caio c62d49e75e Address comment 2023-05-29 12:07:41 -03:00
Caio 41d414e3f4 Address comments 2023-05-24 19:54:13 -03:00
Caio 25e395653d Move tests 2023-05-24 19:35:59 -03:00
Tomasz Miąsko 67f455afe1 Suppress "erroneous constant used" for constants tainted by errors
When constant evaluation fails because its MIR is tainted by errors,
suppress note indicating that erroneous constant was used, since those
errors have to be fixed regardless of the constant being used or not.
2023-05-15 00:00:00 +00:00