about summary refs log tree commit diff
path: root/tests/ui/structs
AgeCommit message (Collapse)AuthorLines
2025-07-17Add test for `default_field_values` and `const_default`Esteban Küber-0/+37
Add a test showing `#![feature(default_field_values)]` using `#[const_trait] trait Default` (`#![feature(const_default)]` + `#![feature(const_trait_impl)]`).
2025-06-30cleaned up some testsKivooeo-11/+13
2025-06-29moved & deleted some testsKivooeo-0/+23
2025-06-17Reject union default field valuesJieyou Xu-3/+15
2025-06-16Add union with default field values case testJieyou Xu-8/+14
In particular, there should be no additional errors (default field values for `union` fields are currently erroneously accepted).
2025-06-07const-eval error: always say in which item the error occurredRalf Jung-1/+1
also adjust the wording a little so that we don't say "the error occurred here" for two different spans
2025-06-02Clarify why we are talking about a failed const eval at a random placeOli Scherer-4/+4
2025-06-02Use the informative error as the main const eval error messageOli Scherer-11/+11
2025-05-06Preserve generic args in suggestions for ambiguous associated itemsLeón Orell Valerian Liehr-3/+21
Most notably, this preserves the `(..)` of ambiguous RTN paths.
2025-04-30compiletest: Make diagnostic kind mandatory on line annotationsVadim Petrochenkov-39/+43
2025-04-08UI tests: add missing diagnostic kinds where possibleVadim Petrochenkov-3/+3
2025-04-08Rollup merge of #139024 - compiler-errors:tweak-default-value-err, r=lcnrStuart Cook-12/+19
Make error message for missing fields with `..` and without `..` more consistent When `..` is not present, we say "missing field `bar` in initializer", but when it is present we say "missing mandatory field `bar`". I don't see why the primary error message should change, b/c the root cause is the same. Let's harmonize these error messages and instead use a label to explain that `..` is required b/c it's not defaulted. r? estebank
2025-04-07Make error message for missing fields with .. and without .. more consistentMichael Goulet-12/+19
2025-03-27Improve suggest construct with literal syntax instead of callingxizheyin-2/+15
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-27Add ui test for struct construction by calling syntaxxizheyin-0/+70
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-14Do not suggest using `-Zmacro-backtrace` for builtin macrosEsteban Küber-3/+0
For macros that are implemented on the compiler, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros.
2025-03-06Rollup merge of #137565 - compiler-errors:macro-ex, r=estebankMichael Goulet-0/+33
Try to point of macro expansion from resolver and method errors if it involves macro var In the case that a macro caller passes an identifier into a macro generating a path or method expression, point out that identifier in the context of the *macro* so it's a bit more clear how the macro is involved in causing the error. r? ``````````@estebank`````````` or reassign
2025-03-04Rollup merge of #137913 - compiler-errors:struct-field-default-generic, ↵Jubilee-18/+107
r=BoxyUwU Allow struct field default values to reference struct's generics Right now, the default field value feature (https://github.com/rust-lang/rust/issues/132162) lowers anon consts whose types may reference ADT params that the const doesn't inherit. This PR fixes this, so that these defaults can reference ADTs' generics, and sets the `generics_of` parenting up correctly. There doesn't seem to be a good reason not to support this, since the anon const has a well-defined type from the field, and the anon const doesn't interact with the type system like generic parameter defaults do. r? `````@boxyuwu````` or reassign I could also make this into an error if this seems problematic (https://github.com/rust-lang/rust/compare/master...compiler-errors:rust:default-field-value-implicit-param?expand=1)...... but I'd rather make this work and register an open question on the tracking issue about validating that this is well-vetted. Fixes #137896
2025-03-04Allow struct field default values to reference struct's genericsMichael Goulet-18/+107
2025-03-04Also note struct access, and fix macro expansion from foreign cratesMichael Goulet-0/+33
2025-03-03Do not recover missing lifetime with random in-scope lifetimeMichael Goulet-12/+3
2025-02-28Shorten span of panic failures in const contextEsteban Küber-1/+1
Previously, we included a redundant prefix on the panic message and a postfix of the location of the panic. The prefix didn't carry any additional information beyond "something failed", and the location of the panic is redundant with the diagnostic's span, which gets printed out even if its code is not shown. ``` error[E0080]: evaluation of constant value failed --> $DIR/assert-type-intrinsics.rs:11:9 | LL | MaybeUninit::<!>::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: aborted execution: attempted to instantiate uninhabited type `!` ``` ``` error[E0080]: evaluation of `Fail::<i32>::C` failed --> $DIR/collect-in-dead-closure.rs:9:19 | LL | const C: () = panic!(); | ^^^^^^^^ evaluation panicked: explicit panic | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` ``` error[E0080]: evaluation of constant value failed --> $DIR/uninhabited.rs:41:9 | LL | assert!(false); | ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) ``` --- When the primary span for a const error is the same as the first frame in the const error report, skip it. ``` error[E0080]: evaluation of constant value failed --> $DIR/issue-88434-removal-index-should-be-less.rs:3:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^ evaluation panicked: explicit panic | note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>` --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ the failure occurred here = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` instead of ``` error[E0080]: evaluation of constant value failed --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ explicit panic | note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>` --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ note: inside `_CONST` --> $DIR/issue-88434-removal-index-should-be-less.rs:3:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` --- Revert order of constant evaluation errors Point at the code the user wrote first and std functions last. ``` error[E0080]: evaluation of constant value failed --> $DIR/const-errs-dont-conflict-103369.rs:5:25 | LL | impl ConstGenericTrait<{my_fn(1)}> for () {} | ^^^^^^^^ evaluation panicked: Some error occurred | note: called from `my_fn` --> $DIR/const-errs-dont-conflict-103369.rs:10:5 | LL | panic!("Some error occurred"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` instead of ``` error[E0080]: evaluation of constant value failed --> $DIR/const-errs-dont-conflict-103369.rs:10:5 | LL | panic!("Some error occurred"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred | note: called from `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}` --> $DIR/const-errs-dont-conflict-103369.rs:5:25 | LL | impl ConstGenericTrait<{my_fn(1)}> for () {} | ^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ```
2025-02-21More sophisticated span trimmingMichael Goulet-6/+4
2025-02-18Rollup merge of #135711 - estebank:issue-135649, r=davidtwcoMatthias Krüger-0/+29
Do not ICE on default_field_value const with lifetimes `#![feature(default_field_values)]` uses a `const` body that should be treated as inline `const`s, but is actually being detected otherwise. This is similar to the situation in #78174, so we take the same solution: we check if the const actually comes from a field, and if it does, we use that logic to get the appropriate lifetimes and not ICE during borrowck. Fix #135649.
2025-02-14Trim suggestion parts to the subset that is purely additiveMichael Goulet-19/+19
2025-02-14Consider add-prefix replacements tooMichael Goulet-54/+36
2025-02-14Use underline suggestions for purely 'additive' replacementsMichael Goulet-3/+2
2025-02-10Show diff suggestion format on verbose replacementEsteban Küber-66/+99
``` 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-01-27Add `TooGeneric` variant to `LayoutError` and emit `Unknown` oneFedericoBruzzone-1/+1
- `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-23tests: use `needs-subprocess` instead of `ignore-{wasm32,emscripten,sgx}`许杰友 Jieyou Xu (Joe)-1/+1
2025-01-21Detect missing fields with default values and suggest `..`Esteban Küber-0/+167
When a struct definition has default field values, and the use struct ctor has missing field, if all those missing fields have defaults suggest `..`: ``` error[E0063]: missing fields `field1` and `field2` in initializer of `S` --> $DIR/non-exhaustive-ctor.rs:16:13 | LL | let _ = S { field: () }; | ^ missing `field1` and `field2` | help: all remaining fields have defaults, use `..` | LL | let _ = S { field: (), .. }; | ++++ ```
2025-01-20Rollup merge of #135700 - estebank:priv-field-dfv, r=wesleywiser许杰友 Jieyou Xu (Joe)-0/+103
Emit single privacy error for struct literal with multiple private fields and add test for `default_field_values` privacy Add test ensuring that struct with default field values is not constructable if the fields are not accessible. Collect all unreachable fields in a single struct literal struct and emit a single error, instead of one error per private field. ``` error[E0451]: fields `beta` and `gamma` of struct `Alpha` are private --> $DIR/visibility.rs:18:13 | LL | let _x = Alpha { | ----- in this type LL | beta: 0, | ^^^^^^^ private field LL | .. | ^^ field `gamma` is private ```
2025-01-18Do not ICE on default_field_value const with lifetimesEsteban Küber-0/+29
Fix #135649.
2025-01-18Disallow `A { .. }` if `A` has no fieldsEsteban Küber-0/+47
``` error: `A` has no fields, `..` needs at least one default field in the struct definition --> $DIR/empty-struct.rs:16:17 | LL | let _ = A { .. }; | - ^^ | | | this type has no fields ```
2025-01-18Emit a single privacy error for multiple fields on the same struct expressionEsteban Küber-21/+64
Collect all unreachable fields in a single struct literal struct and emit a single error, instead of one error per private field. ``` error[E0451]: fields `beta` and `gamma` of struct `Alpha` are private --> $DIR/visibility.rs:18:13 | LL | let _x = Alpha { | ----- in this type LL | beta: 0, | ^^^^^^^ private field LL | .. | ^^ field `gamma` is private ```
2025-01-18Add context on private fields that are not on the same line as the struct nameEsteban Küber-0/+4
``` error[E0451]: field `x` of struct `S` is private --> $DIR/visibility.rs:24:9 | LL | let a = baz::S { | ------ in this type LL | .. | ^^ field `x` is private ```
2025-01-18Add test for construction of struct with private field with default valueEsteban Küber-0/+56
``` error[E0451]: field `beta` of struct `Alpha` is private --> $DIR/visibility.rs:11:37 | LL | let x = crate::foo::Alpha { .. }; | ^^ field `beta` is private ```
2025-01-14fix ICE with references to infinite structs in constsLukas Markeffsky-2/+12
2024-12-31Provide structured suggestion for `impl Default` of type where all fields ↵Esteban Küber-1/+4
have defaults ``` error: `Default` impl doesn't use the declared default field values --> $DIR/manual-default-impl-could-be-derived.rs:28:1 | LL | / impl Default for B { LL | | fn default() -> Self { LL | | B { LL | | x: s(), | | --- this field has a default value LL | | y: 0, | | - this field has a default value ... | LL | | } | |_^ | help: to avoid divergence in behavior between `Struct { .. }` and `<Struct as Default>::default()`, derive the `Default` | LL ~ #[derive(Default)] struct B { | ``` Note that above the structured suggestion also includes completely removing the manual `impl`, but the rendering doesn't.
2024-12-25Implement `default_overrides_default_fields` lintEsteban Küber-0/+338
Detect when a manual `Default` implementation isn't using the existing default field values and suggest using `..` instead: ``` error: `Default` impl doesn't use the declared default field values --> $DIR/manual-default-impl-could-be-derived.rs:14:1 | LL | / impl Default for A { LL | | fn default() -> Self { LL | | A { LL | | y: 0, | | - this field has a default value ... | LL | | } | |_^ | = help: use the default values in the `impl` with `Struct { mandatory_field, .. }` to avoid them diverging over time note: the lint level is defined here --> $DIR/manual-default-impl-could-be-derived.rs:5:9 | LL | #![deny(default_overrides_default_fields)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ```
2024-12-20Restrict `#[non_exaustive]` on structs with default field valuesEsteban Küber-0/+41
Do not allow users to apply `#[non_exaustive]` to a struct when they have also used default field values.
2024-12-14Make sure to use normalized ty for unevaluated const for default struct valueMichael Goulet-0/+17
2024-12-14Move default-field-values tests into a subdirectoryMichael Goulet-18/+18
2024-12-10Further document default field testEsteban Küber-7/+12
2024-12-10Excercise const trait interaction with default fieldsEsteban Küber-9/+30
Add a test case for using the result of a fn call of an associated function of a `const` trait in a struct default field. ```rust struct X; trait Trait { fn value() -> Self; } impl const Trait for X { fn value() -> Self { X } } struct S<T: const Trait> { a: T = T::value(), } ```
2024-12-09Support x-crate default fieldsEsteban Küber-0/+11
2024-12-09Unconditionally error at definition if default field value has const errorsEsteban Küber-41/+10
Emit E0080 always on struct definition with default fields that have unconditional const errors and remove `default_field_always_invalid_const` lint.
2024-12-09Disallow `#[default] Variant {}` regardless of feature flagEsteban Küber-8/+22
2024-12-09review comments: rewordingsEsteban Küber-2/+2
2024-12-09Provide diagnostic for `Struct(a, .., z)` expressionEsteban Küber-2/+73
People might extrapolate from `Struct { .. }` that `Struct(..)` would work, but it doesn't.