rust/tests/ui/malformed
许杰友 Jieyou Xu (Joe) 7b821d1752
Rollup merge of #151278 - estebank:issue-108894, r=davidtwco
Provide more context on trait bounds being unmet due to imperfect derive

When encountering a value that has a borrow checker error where the type was previously moved, when suggesting cloning verify that it is not already being derived. If it is, explain why the `derive(Clone)` doesn't apply:

```
note: if `TypedAddress<T>` implemented `Clone`, you could clone the value
  --> $DIR/derive-clone-implicit-bound.rs:6:1
   |
LL | #[derive(Clone, Copy)]
   |          ----- derived `Clone` adds implicit bounds on type parameters
LL | pub struct TypedAddress<T>{
   | ^^^^^^^^^^^^^^^^^^^^^^^^-^
   | |                       |
   | |                       introduces an implicit `T: Clone` bound
   | consider manually implementing `Clone` for this type
...
LL |         let old = self.return_value(offset);
   |                                     ------ you could clone this value
```

When encountering a bound coming from a derive macro, suggest manual impl of the trait.

Use the span for the specific param when adding bounds in builtin derive macros, so the diagnostic will point at them as well as the derive macro itself.

```
note: required for `Id<SomeNode>` to implement `PartialEq`
  --> $DIR/derive-implicit-bound.rs:5:10
   |
LL | #[derive(PartialEq, Eq)]
   |          ^^^^^^^^^
LL | pub struct Id<T>(PhantomData<T>);
   |               - unsatisfied trait bound introduced in this `derive` macro
   = help: consider manually implementing `PartialEq` to avoid undesired bounds
```

Mention that the trait could be manually implemented in E0599.

Fix rust-lang/rust#108894. Address rust-lang/rust#143714. Address #rust-lang/rust#146515 (but ideally would also suggest constraining the fn bound correctly as well).
2026-02-06 10:25:43 +08:00
..
do-not-ice-on-note_and_explain.rs Warn/error on self ctor from outer item in inner item 2024-05-18 13:08:34 -04:00
do-not-ice-on-note_and_explain.stderr Point at inner item on E0401 generated by hir_typeck 2025-11-01 19:09:56 +00:00
issue-69341-malformed-derive-inert.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-69341-malformed-derive-inert.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-107423-unused-delim-only-one-no-pair.rs compiletest: Require //~ annotations even if error-pattern is specified 2025-04-03 11:08:55 +03:00
issue-107423-unused-delim-only-one-no-pair.stderr compiletest: Require //~ annotations even if error-pattern is specified 2025-04-03 11:08:55 +03:00
malformed-derive-entry.rs Keep span of type in builtin derive macros expansions 2026-02-01 18:20:30 +00:00
malformed-derive-entry.stderr Keep span of type in builtin derive macros expansions 2026-02-01 18:20:30 +00:00
malformed-interpolated.rs Improve an error involving attribute values. 2023-12-12 15:54:25 +11:00
malformed-interpolated.stderr Improve an error involving attribute values. 2023-12-12 15:54:25 +11:00
malformed-meta-delim.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
malformed-meta-delim.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
malformed-regressions.rs Move remaining doc attribute parsing errors to warnings 2026-02-04 10:54:45 +01:00
malformed-regressions.stderr Move remaining doc attribute parsing errors to warnings 2026-02-04 10:54:45 +01:00
malformed-special-attrs.rs Move remaining doc attribute parsing errors to warnings 2026-02-04 10:54:45 +01:00
malformed-special-attrs.stderr Move remaining doc attribute parsing errors to warnings 2026-02-04 10:54:45 +01:00