about summary refs log tree commit diff
path: root/tests/ui/deriving
AgeCommit message (Collapse)AuthorLines
2025-06-03Rollup merge of #141724 - Sol-Ell:issue-141141-fix, r=nnethercoteMatthias Krüger-0/+195
fix(#141141): When expanding `PartialEq`, check equality of scalar types first. Fixes rust-lang/rust#141141. Now, `cs_eq` function of `partial_eq.rs` compares [scalar types](https://doc.rust-lang.org/rust-by-example/primitives.html#scalar-types) first. - Add `is_scalar` field to `FieldInfo`. - Add `is_scalar` method to `TyKind`. - Pass `FieldInfo` via `CsFold::Combine` and refactor code relying on it. - Implement `TryFrom<&str>` and `TryFrom<Symbol>` for FloatTy. - Implement `TryFrom<&str>` and `TryFrom<Symbol>` for IntTy. - Implement `TryFrom<&str>` and `TryFrom<Symbol>` for UintTy.
2025-06-02Separately check equality of the scalar types and compound types in the ↵Ell-0/+195
order of declaration.
2025-05-27Refactor the two-phase check for impls and impl itemsMu001999-1/+2
2025-04-18Remove let_chains feature gate from even more testsest31-1/+1
2025-04-16Explicitly annotate edition for `unpretty=expanded` and `unpretty=hir` testsLukas Wirth-0/+6
These emit prelude imports which means they are always edition dependent
2025-03-14Do not suggest using `-Zmacro-backtrace` for builtin macrosEsteban Küber-20/+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-24tests: use minicore moreDavid Wood-3/+4
minicore makes it much easier to add new language items to all of the existing `no_core` tests.
2025-02-24Deduplicate CoerceUnsized and DispatchFromDyn impl errorsMichael Goulet-46/+6
2025-02-24Simplify trait error message for CoercePointee validationMichael Goulet-3/+114
2025-02-09move repr(transparent) checks to coherenceDing Xiang Fei-9/+7
2025-02-09rename the trait to validity and place a feature gate afrontDing Xiang Fei-9/+6
2025-02-09introduce CoercePointeeWellformed for coherence checks at typeck stageDing Xiang Fei-26/+93
2025-01-24Skip suggestions in `derive`d codeEsteban Küber-0/+22
Do not suggest ``` help: use parentheses to call these | 5 | (callback: Rc<dyn Fn()>)(), | + +++ ``` Skip all "call function for this binop" suggestions when in a derive context. Fix #135989.
2024-12-04make CoercePointee errors translatableDing Xiang Fei-7/+7
2024-11-27Update tests to use new proc-macro headerEric Huss-8/+4
2024-11-26tests: remove `//@ pretty-expanded` usages许杰友 Jieyou Xu (Joe)-13/+0
Done with ```bash sd '//@ pretty-expanded.*\n' '' tests/ui/**/*.rs ``` and ``` sd '//@pretty-expanded.*\n' '' tests/ui/**/*.rs ```
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-24s/SmartPointer/CoerceReferent/gDing Xiang Fei-183/+199
move derive_smart_pointer into removed set
2024-10-06Check that `#[pointee]` is applied only to generic argumentsBrezak-1/+58
2024-08-29derive(SmartPointer): assume pointee from the single generic and better ↵Ding Xiang Fei-16/+61
error messages
2024-08-13derive(SmartPointer): register helper attributesDing Xiang Fei-0/+163
2024-08-05Rollup merge of #127907 - RalfJung:byte_slice_in_packed_struct_with_derive, ↵Matthias Krüger-93/+0
r=nnethercote built-in derive: remove BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE hack and lint Fixes https://github.com/rust-lang/rust/issues/107457 by turning the lint into a hard error. The lint has been shown in future breakage reports since Rust 1.69 (released in April 2023). Let's see (via crater) if enough time has passed since https://github.com/rust-lang/rust/pull/104429, and https://github.com/unicode-org/icu4x/pull/2834 has propagated far enough to let us make this a hard error. Cc ``@nnethercote`` ``@Manishearth``
2024-08-01reject pointee without ?SizedDing Xiang Fei-10/+46
2024-07-30derive(SmartPointer): rewrite bounds in where and generic boundsDing Xiang Fei-0/+144
2024-07-27built-in derive: remove BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE hack and lintRalf Jung-93/+0
2024-07-06Mark format! with must_use hintlukas-1/+1
2024-07-04reject SmartPointer constructions not serving the purposeDing Xiang Fei-0/+121
2024-06-25Rollup merge of #126302 - mu001999-contrib:ignore/default, r=michaelwoeristerMatthias Krüger-1/+1
Detect unused structs which derived Default <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> Fixes #98871
2024-06-25Detect unused structs which derived Defaultmu001999-1/+1
2024-06-24SmartPointer derive-macroXiangfei Ding-0/+55
Co-authored-by: Wedson Almeida Filho <walmeida@microsoft.com>
2024-04-23Do not add leading asterisk in the `PartialEq`Daniel Sedlak-8/+46
Adding leading asterisk can cause compilation failure for the _types_ that don't implement the `Copy`.
2024-04-14builtin-derive: tag → discriminantRalf Jung-47/+47
2024-03-27Use `TraitRef::to_string` sorting in favor of `TraitRef::ord`, as the latter ↵Oli Scherer-5/+5
compares `DefId`s which we need to avoid
2024-03-03Move testsCaio-0/+17
2024-02-16[AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives许杰友 Jieyou Xu (Joe)-71/+71
2024-02-07Update testsr0cky-1/+1
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-24remove StructuralEq traitRalf Jung-28/+0
2024-01-02Adjust compiler tests for unused_tuple_struct_fields -> dead_codeJake Goulding-3/+3
2023-11-24Show number in error message even for one errorNilstrieb-1/+1
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-21improve help for multiple `#[default]` variantsLukas Markeffsky-38/+103
2023-11-09Emit #[inline] on derive(Debug)Ben Kimock-0/+15
2023-09-08Rework no_coverage to coverage(off)Andy Caldwell-14/+14
2023-07-16Generate safe stable code for derives on empty enumsDavid Tolnay-9/+5
Generate `match *self {}` instead of `unsafe { core::intrinsics::unreachable() }`. This is: 1. safe 2. stable for the benefit of everyone looking at these derived impls through `cargo expand`. Both expansions compile to the same code at all optimization levels (including `0`).
2023-06-27Don't sort strings right after we just sorted by typesMichael Goulet-5/+5
2023-05-26Inline derived `hash` function.Nicholas Nethercote-0/+15
Because most of the other derived functions are inlined: `clone`, `default`, `eq`, `partial_cmp`, `cmp`. The exception is `fmt`, but it tends to not be on hot paths as much.
2023-05-08Move testsCaio-0/+20
2023-02-02Don't generate unecessary `&&self.field` in deriving Debugclubby789-7/+7
2023-02-01Fix syntax in `-Zunpretty-expanded` output for derived `PartialEq`.Nicholas Nethercote-3/+3
If you do `derive(PartialEq)` on a packed struct, the output shown by `-Zunpretty=expanded` includes expressions like this: ``` { self.x } == { other.x } ``` This is invalid syntax. This doesn't break compilation, because the AST nodes are constructed within the compiler. But it does mean anyone using `-Zunpretty=expanded` output as a guide for hand-written impls could get a nasty surprise. This commit fixes things by instead using this form: ``` ({ self.x }) == ({ other.x }) ```
2023-01-30Allow more deriving on packed structs.Nicholas Nethercote-81/+580
Currently, deriving on packed structs has some non-trivial limitations, related to the fact that taking references on unaligned fields is UB. The current approach to field accesses in derived code: - Normal case: `&self.0` - In a packed struct that derives `Copy`: `&{self.0}` - In a packed struct that doesn't derive `Copy`: `&self.0` Plus, we disallow deriving any builtin traits other than `Default` for any packed generic type, because it's possible that there might be misaligned fields. This is a fairly broad restriction. Plus, we disallow deriving any builtin traits other than `Default` for most packed types that don't derive `Copy`. (The exceptions are those where the alignments inherently satisfy the packing, e.g. in a type with `repr(packed(N))` where all the fields have alignments of `N` or less anyway. Such types are pretty strange, because the `packed` attribute is not having any effect.) This commit introduces a new, simpler approach to field accesses: - Normal case: `&self.0` - In a packed struct: `&{self.0}` In the latter case, this requires that all fields impl `Copy`, which is a new restriction. This means that the following example compiles under the old approach and doesn't compile under the new approach. ``` #[derive(Debug)] struct NonCopy(u8); #[derive(Debug) #[repr(packed)] struct MyType(NonCopy); ``` (Note that the old approach's support for cases like this was brittle. Changing the `u8` to a `u16` would be enough to stop it working. So not much capability is lost here.) However, the other constraints from the old rules are removed. We can now derive builtin traits for packed generic structs like this: ``` trait Trait { type A; } #[derive(Hash)] #[repr(packed)] pub struct Foo<T: Trait>(T, T::A); ``` To allow this, we add a `T: Copy` bound in the derived impl and a `T::A: Copy` bound in where clauses. So `T` and `T::A` must impl `Copy`. We can now also derive builtin traits for packed structs that don't derive `Copy`, so long as the fields impl `Copy`: ``` #[derive(Hash)] #[repr(packed)] pub struct Foo(u32); ``` This includes types that hand-impl `Copy` rather than deriving it, such as the following, that show up in winapi-0.2: ``` #[derive(Clone)] #[repr(packed)] struct MyType(i32); impl Copy for MyType {} ``` The new approach is simpler to understand and implement, and it avoids the need for the `unsafe_derive_on_repr_packed` check. One exception is required for backwards-compatibility: we allow `[u8]` fields for now. There is a new lint for this, `byte_slice_in_packed_struct_with_derive`.