about summary refs log tree commit diff
path: root/tests/ui/union
AgeCommit message (Collapse)AuthorLines
2025-08-31allow taking address to union fieldKivooeo-11/+116
2025-07-25Mention type that could be `Clone` but isn't in more casesEsteban Küber-0/+18
When encountering a moved value of a type that isn't `Clone` because of unmet obligations, but where all the unmet predicates reference crate-local types, mention them and suggest cloning, as we do in other cases already: ``` error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure --> f111.rs:14:25 | 13 | fn do_stuff(foo: Option<Foo>) { | --- captured outer variable 14 | require_fn_trait(|| async { | -- ^^^^^ `foo` is moved here | | | captured by this `Fn` closure 15 | if foo.map_or(false, |f| f.foo()) { | --- | | | variable moved due to use in coroutine | move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait | note: if `Foo` implemented `Clone`, you could clone the value --> f111.rs:4:1 | 4 | struct Foo; | ^^^^^^^^^^ consider implementing `Clone` for this type ... 15 | if foo.map_or(false, |f| f.foo()) { | --- you could clone this value ```
2025-06-30Unconditionally run `check_item_type` on all itemsOli Scherer-27/+27
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-02-10Show diff suggestion format on verbose replacementEsteban Küber-4/+6
``` 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-31Manually walk into WF obligations in BestObligation proof tree visitorMichael Goulet-0/+2
2025-01-22Don't pick `T: FnPtr` nested goalsBoxy-3/+34
2024-12-07Mention type parameter in more cases and don't suggest ~const bound already ↵Esteban Küber-1/+1
there
2024-12-07reword trait bound suggestion message to include the boundsEsteban Küber-1/+1
2024-12-04Tweak output of some const pattern errorsEsteban Küber-1/+1
- Add primary span labels. - Point at const generic parameter used as pattern. - Point at statics used as pattern. - Point at let bindings used in const pattern.
2024-12-04On `const` pattern errors, point at the `const` item definitionEsteban Küber-0/+3
Centralize emitting an error in `const_to_pat` so that all errors from that evaluating a `const` in a pattern can add addditional information. With this, now point at the `const` item's definition: ``` error[E0158]: constant pattern depends on a generic parameter --> $DIR/associated-const-type-parameter-pattern.rs:20:9 | LL | pub trait Foo { | ------------- LL | const X: EFoo; | ------------- constant defined here ... LL | A::X => println!("A::X"), | ^^^^ ```
2024-10-29Remove detail from label/note that is already available in other noteEsteban Küber-1/+1
Remove the "which is required by `{root_obligation}`" post-script in "the trait `X` is not implemented for `Y`" explanation in E0277. This information is already conveyed in the notes explaining requirements, making it redundant while making the text (particularly in labels) harder to read. ``` error[E0277]: the trait bound `NotCopy: Copy` is not satisfied --> $DIR/wf-static-type.rs:10:13 | LL | static FOO: IsCopy<Option<NotCopy>> = IsCopy { t: None }; | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopy` | = note: required for `Option<NotCopy>` to implement `Copy` note: required by a bound in `IsCopy` --> $DIR/wf-static-type.rs:7:17 | LL | struct IsCopy<T:Copy> { t: T } | ^^^^ required by this bound in `IsCopy` ``` vs the prior ``` error[E0277]: the trait bound `NotCopy: Copy` is not satisfied --> $DIR/wf-static-type.rs:10:13 | LL | static FOO: IsCopy<Option<NotCopy>> = IsCopy { t: None }; | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopy`, which is required by `Option<NotCopy>: Copy` | = note: required for `Option<NotCopy>` to implement `Copy` note: required by a bound in `IsCopy` --> $DIR/wf-static-type.rs:7:17 | LL | struct IsCopy<T:Copy> { t: T } | ^^^^ required by this bound in `IsCopy` ```
2024-10-01Remove unnamed field featureMichael Goulet-2673/+0
2024-09-13Update tests for hidden references to mutable staticObei Sideg-0/+5
2024-04-24Mention when type parameter could be `Clone`Esteban Küber-3/+12
``` error[E0382]: use of moved value: `t` --> $DIR/use_of_moved_value_copy_suggestions.rs:7:9 | LL | fn duplicate_t<T>(t: T) -> (T, T) { | - move occurs because `t` has type `T`, which does not implement the `Copy` trait ... LL | (t, t) | - ^ value used here after move | | | value moved here | help: if `T` implemented `Clone`, you could clone the value --> $DIR/use_of_moved_value_copy_suggestions.rs:4:16 | LL | fn duplicate_t<T>(t: T) -> (T, T) { | ^ consider constraining this type parameter with `Clone` ... LL | (t, t) | - you could clone this value help: consider restricting type parameter `T` | LL | fn duplicate_t<T: Copy>(t: T) -> (T, T) { | ++++++ ``` The `help` is new. On ADTs, we also extend the output with span labels: ``` error[E0507]: cannot move out of static item `FOO` --> $DIR/issue-17718-static-move.rs:6:14 | LL | let _a = FOO; | ^^^ move occurs because `FOO` has type `Foo`, which does not implement the `Copy` trait | note: if `Foo` implemented `Clone`, you could clone the value --> $DIR/issue-17718-static-move.rs:1:1 | LL | struct Foo; | ^^^^^^^^^^ consider implementing `Clone` for this type ... LL | let _a = FOO; | --- you could clone this value help: consider borrowing here | LL | let _a = &FOO; | + ```
2024-04-11Mention when the type of the moved value doesn't implement `Clone`Esteban Küber-0/+15
2024-04-11Suggest `.clone()` in some move errorsEsteban Küber-0/+5
``` error[E0507]: cannot move out of `*x` which is behind a shared reference --> $DIR/borrowck-fn-in-const-a.rs:6:16 | LL | return *x | ^^ move occurs because `*x` has type `String`, which does not implement the `Copy` trait | help: consider cloning the value if the performance cost is acceptable | LL - return *x LL + return x.clone() | ```
2024-03-12Allow unused fields in some testsArthur Carcano-0/+1
The dead_code lint was previously eroneously missing those. Since this lint bug has been fixed, the unused fields warnings need to be fixed. Most of them are marked as `#[allow(dead_code)]`. Other warnings are fixed by changing visibility of modules.
2024-03-04hir_analysis: enums return `None` in `find_field`David Wood-0/+70
Unnamed union fields with enums are checked for, but if `find_field` causes an ICE then the compiler won't get to that point. Signed-off-by: David Wood <david@davidtw.co>
2024-02-23Don't ICE on anonymous struct in enum variantclubby789-0/+27
2024-02-17Add more checks for `unnamed_field` during HIR analysisclubby789-0/+124
2024-02-16[AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives许杰友 Jieyou Xu (Joe)-23/+23
2024-02-12Improve some codes according to the reviewsFrank King-0/+494
- improve diagnostics of field uniqueness check and representation check - simplify the implementation of field uniqueness check - remove some useless codes and improvement neatness
2024-02-12Add `#[derive(Clone, Copy)]` to anonymous adtsFrank King-175/+184
Fix the `AssertBoundIsClone` error for anonymous adts.
2024-02-12Check representation of unnamed fieldsFrank King-0/+177
2024-02-12check uniqueness of nested fieldsFrank King-20/+1632
2024-02-12Lower anonymous structs or unions to HIRFrank King-84/+14
2024-02-05Rollup merge of #116284 - RalfJung:no-nan-match, r=cjgillotMatthias Krüger-1/+0
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error. This is part of implementing https://github.com/rust-lang/rfcs/pull/3535. Closes https://github.com/rust-lang/rust/issues/41620 by removing the lint. https://github.com/rust-lang/reference/pull/1456 updates the reference to match.
2024-01-30Provide more context on derived obligation error primary labelEsteban Küber-1/+1
Expand the primary span of E0277 when the immediate unmet bound is not what the user wrote: ``` error[E0277]: the trait bound `i32: Bar` is not satisfied --> f100.rs:6:6 | 6 | <i32 as Foo>::foo(); | ^^^ the trait `Bar` is not implemented for `i32`, which is required by `i32: Foo` | help: this trait has no implementations, consider adding one --> f100.rs:2:1 | 2 | trait Bar {} | ^^^^^^^^^ note: required for `i32` to implement `Foo` --> f100.rs:3:14 | 3 | impl<T: Bar> Foo for T {} | --- ^^^ ^ | | | unsatisfied trait bound introduced here ``` Fix #40120.
2024-01-30Rollup merge of #120424 - RalfJung:raw-ptr-meta, r=NilstriebGuillaume Gomez-1/+1
raw pointer metadata API: data address -> data pointer A pointer consists of [more than just an address](https://github.com/rust-lang/rfcs/pull/3559), so let's not equate "pointer" and "address" in these docs.
2024-01-29raw pointer metadata API: data address -> data pointerRalf Jung-1/+1
2024-01-26Use single label for method not found due to unmet boundEsteban Küber-4/+1
2024-01-26remove illegal_floating_point_literal_pattern lintRalf Jung-1/+0
2024-01-05Stabilize THIR unsafeckMatthew Jasper-19/+7
2024-01-05Remove revisions for THIR unsafeckMatthew Jasper-802/+93
This is to make the diff when stabilizing it easier to review.
2024-01-02Reorder `check_item_type` diagnostics so they occur next to the ↵Oli Scherer-24/+24
corresponding `check_well_formed` diagnostics
2023-11-24Show number in error message even for one errorNilstrieb-13/+13
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-18tweak logic of "unknown field" labelEsteban Küber-2/+12
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-06Visit patterns in THIR let expressionsMatthew Jasper-27/+45
This fixes some THIR unsafety checking errors not being emitted for let expressions in these situations.
2023-10-25Work around the fact that `check_mod_type_wf` may spuriously return ↵Oli Scherer-9/+75
`ErrorGuaranteed`, even if that error is only emitted by `check_modwitem_types`
2023-09-10Point out if a local trait has no implementationsMichael Goulet-0/+11
2023-08-24Parse unnamed fields and anonymous structs or unionsFrank King-0/+230
Anonymous structs or unions are only allowed in struct field definitions. Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
2023-06-15change `std::marker::Sized` to just `Sized`Lukas Markeffsky-3/+3
2023-06-05Don't mention already set fieldsMichael Goulet-2/+2
2023-05-03rustc_middle: Fix `opt_item_ident` for non-local def idsVadim Petrochenkov-3/+6
2023-04-12Tweak output for 'add line' suggestionEsteban Küber-6/+12
2023-03-09Auto merge of #108920 - matthiaskrgr:rollup-qrr9a0u, r=matthiaskrgrbors-45/+62
Rollup of 8 pull requests Successful merges: - #108754 (Retry `pred_known_to_hold_modulo_regions` with fulfillment if ambiguous) - #108759 (1.41.1 supported 32-bit Apple targets) - #108839 (Canonicalize root var when making response from new solver) - #108856 (Remove DropAndReplace terminator) - #108882 (Tweak E0740) - #108898 (Set `LIBC_CHECK_CFG=1` when building Rust code in bootstrap) - #108911 (Improve rustdoc-gui/tester.js code a bit) - #108916 (Remove an unused return value in `rustc_hir_typeck`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-08Tweak E0740Michael Goulet-45/+45