about summary refs log tree commit diff
path: root/tests/ui/structs
AgeCommit message (Collapse)AuthorLines
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.
2024-12-09Detect `struct S(ty = val);`Esteban Küber-2/+10
Emit a specific error for unsupported default field value syntax in tuple structs.
2024-12-09Introduce `default_field_values` featureEsteban Küber-0/+221
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-11-26tests: remove `//@ pretty-expanded` usages许杰友 Jieyou Xu (Joe)-1/+0
Done with ```bash sd '//@ pretty-expanded.*\n' '' tests/ui/**/*.rs ``` and ``` sd '//@pretty-expanded.*\n' '' tests/ui/**/*.rs ```
2024-10-24add third help hint to diagnostic error E0027Duncan Proctor-0/+28
2024-08-05Test more cases of WF-checking for fieldsNoah Lev-10/+151
2024-08-05WF-check struct field types at construction siteNoah Lev-1/+22
Rustc of course already WF-checked the field types at the definition site, but for error tainting of consts to work properly, there needs to be an error emitted at the use site. Previously, with no use-site error, we proceeded with CTFE and ran into ICEs since we are running code with type errors. Emitting use-site errors also brings struct-like constructors more in line with fn-like constructors since they already emit use-site errors for WF issues.
2024-08-05Add test for WF check of implied unsizing in struct fieldsNoah Lev-0/+33
Note that the test output is currently *incorrect*. We should be emitting an error at the use site too, not just at the definition. This is partly for UI reasons, but mainly to fix a related ICE where a const generic body is not tainted with an error since no usage error is reported.
2024-07-22Revert suggestion verbosity changeEsteban Küber-24/+12
2024-07-22Change suggestion message wordingEsteban Küber-4/+4
2024-07-22Use verbose suggestion for "wrong # of generics"Esteban Küber-12/+24
2024-07-12Make parse error suggestions verbose and fix spansEsteban Küber-6/+19
Go over all structured parser suggestions and make them verbose style. When suggesting to add or remove delimiters, turn them into multiple suggestion parts.
2024-07-04Use shorter span for float literal suggestionEsteban Küber-32/+48
2024-05-01Handle normalization failure in `struct_tail_erasing_lifetimes`Gurinder Singh-0/+36
Fixes an ICE that occurred when the struct in question has an error
2024-02-16[AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives许杰友 Jieyou Xu (Joe)-14/+14
2023-11-24Show number in error message even for one errorNilstrieb-17/+17
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-19Rollup merge of #117110 - estebank:deref-field-suggestion, r=b-naberTakayuki Maeda-7/+42
Suggest field typo through derefs Take into account implicit dereferences when suggesting fields. ``` error[E0609]: no field `longname` on type `Arc<S>` --> $DIR/suggest-field-through-deref.rs:10:15 | LL | let _ = x.longname; | ^^^^^^^^ help: a field with a similar name exists: `long_name` ``` CC https://github.com/rust-lang/rust/issues/78374#issuecomment-719564114
2023-11-18tweak logic of "unknown field" labelEsteban Küber-5/+30
2023-11-16recover primary span labelEsteban Küber-2/+2
2023-11-16Suggest `unwrap()` on field not found for `Result`/`Option`Esteban Küber-2/+12
When encountering a `Result<T, _>` or `Option<T>` where `T` has a field that's being accessed, suggest calling `.unwrap()` to get to the field.
2023-11-16Suggest replacing `Self` with the right type on type errorEsteban Küber-0/+4
When encountering a type error caused by the use of `Self`, suggest using the actual type name instead. ``` error[E0308]: mismatched types --> $DIR/struct-path-self-type-mismatch.rs:13:9 | LL | impl<T> Foo<T> { | - ------ this is the type of the `Self` literal | | | found type parameter LL | fn new<U>(u: U) -> Foo<U> { | - ------ expected `Foo<U>` because of return type | | | expected type parameter LL | / Self { LL | | LL | | inner: u LL | | LL | | } | |_________^ expected `Foo<U>`, found `Foo<T>` | = note: expected struct `Foo<U>` found struct `Foo<T>` = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters help: use the type name directly | LL | Foo::<U> { | ~~~~~~~~ ``` Fix #76086.
2023-11-16Point at impl self ty on type error involving `Self`Esteban Küber-1/+3
When encountering a type error involving a `Self` literal, point at the self type of the enclosing `impl`. CC #76086.
2023-11-10Recurse over the method chain and maintain a stack to peek at previous ↵Swapna Iyer-0/+46
receiver to align spans
2023-10-17Unify suggestion wordingEsteban Küber-3/+3
2023-06-22Tweak privacy errors to account for reachable itemsEsteban Küber-2/+6
Suggest publicly accessible paths for items in private mod: When encountering a path in non-import situations that are not reachable due to privacy constraints, search for any public re-exports that the user could use instead. Track whether an import suggestion is offering a re-export. When encountering a path with private segments, mention if the item at the final path segment is not publicly accessible at all. Add item visibility metadata to privacy errors from imports: On unreachable imports, record the item that was being imported in order to suggest publicly available re-exports or to be explicit that the item is not available publicly from any path. In order to allow this, we add a mode to `resolve_path` that will not add new privacy errors, nor return early if it encounters one. This way we can get the `Res` corresponding to the final item in the import, which is used in the privacy error machinery.
2023-06-05Don't mention already set fieldsMichael Goulet-3/+3
2023-04-12Tweak output for 'add line' suggestionEsteban Küber-1/+2
2023-03-30better diagnostics for pattern matching tuple structsMaciej Wasilewski-2/+21
Better diagnostic message when trying to pattern match a tuple struct with a struct pattern.
2023-02-23diagnostics: remove inconsistent English article "this" from E0107Michael Howell-8/+8
Consider `tests/ui/const-generics/generic_const_exprs/issue-102768.stderr`, the error message where it gives additional notes about where the associated type is defined, and how the dead code lint doesn't have an article, like in `tests/ui/lint/dead-code/issue-85255.stderr`. They don't have articles, so it seems unnecessary to have one here.
2023-01-30Modify primary span label for E0308Esteban Küber-9/+9
The previous output was unintuitive to users.
2023-01-11When suggesting writing a fully qualified path probe for appropriate typesEsteban Küber-3/+3
Fix #46585.
2023-01-11Move /src/test to /testsAlbert Larsan-0/+1699