diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 0a22c02520939..0f5f4f3c60f25 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -536,6 +536,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ); self.note_version_mismatch(&mut err, &trait_ref); self.suggest_remove_await(&obligation, &mut err); + self.suggest_derive(&obligation, &mut err, trait_predicate); if Some(trait_ref.def_id()) == tcx.lang_items().try_trait() { self.suggest_await_before_try( diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 105e338048680..c2193bbeec49e 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -189,6 +189,13 @@ pub trait InferCtxtExt<'tcx> { err: &mut Diagnostic, trait_ref: &ty::PolyTraitRef<'tcx>, ); + + fn suggest_derive( + &self, + obligation: &PredicateObligation<'tcx>, + err: &mut Diagnostic, + trait_pred: ty::PolyTraitPredicate<'tcx>, + ); } fn predicate_constraint(generics: &hir::Generics<'_>, pred: String) -> (Span, String) { @@ -2589,6 +2596,68 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { _ => {} } } + + fn suggest_derive( + &self, + obligation: &PredicateObligation<'tcx>, + err: &mut Diagnostic, + trait_pred: ty::PolyTraitPredicate<'tcx>, + ) { + let Some(diagnostic_name) = self.tcx.get_diagnostic_name(trait_pred.def_id()) else { + return; + }; + let (adt, substs) = match trait_pred.skip_binder().self_ty().kind() { + ty::Adt(adt, substs) if adt.did().is_local() => (adt, substs), + _ => return, + }; + let can_derive = { + let is_derivable_trait = match diagnostic_name { + sym::Default => !adt.is_enum(), + sym::PartialEq | sym::PartialOrd => { + let rhs_ty = trait_pred.skip_binder().trait_ref.substs.type_at(1); + trait_pred.skip_binder().self_ty() == rhs_ty + } + sym::Eq | sym::Ord | sym::Clone | sym::Copy | sym::Hash | sym::Debug => true, + _ => false, + }; + is_derivable_trait && + // Ensure all fields impl the trait. + adt.all_fields().all(|field| { + let field_ty = field.ty(self.tcx, substs); + let trait_substs = match diagnostic_name { + sym::PartialEq | sym::PartialOrd => { + self.tcx.mk_substs_trait(field_ty, &[field_ty.into()]) + } + _ => self.tcx.mk_substs_trait(field_ty, &[]), + }; + let trait_pred = trait_pred.map_bound_ref(|tr| ty::TraitPredicate { + trait_ref: ty::TraitRef { + substs: trait_substs, + ..trait_pred.skip_binder().trait_ref + }, + ..*tr + }); + let field_obl = Obligation::new( + obligation.cause.clone(), + obligation.param_env, + trait_pred.to_predicate(self.tcx), + ); + self.predicate_must_hold_modulo_regions(&field_obl) + }) + }; + if can_derive { + err.span_suggestion_verbose( + self.tcx.def_span(adt.did()).shrink_to_lo(), + &format!( + "consider annotating `{}` with `#[derive({})]`", + trait_pred.skip_binder().self_ty(), + diagnostic_name.to_string(), + ), + format!("#[derive({})]\n", diagnostic_name.to_string()), + Applicability::MaybeIncorrect, + ); + } + } } /// Collect all the returned expressions within the input expression. diff --git a/src/test/ui/array-slice-vec/repeat_empty_ok.stderr b/src/test/ui/array-slice-vec/repeat_empty_ok.stderr index 85baa1268bf04..eba1a8e2278b7 100644 --- a/src/test/ui/array-slice-vec/repeat_empty_ok.stderr +++ b/src/test/ui/array-slice-vec/repeat_empty_ok.stderr @@ -5,6 +5,10 @@ LL | let headers = [Header{value: &[]}; 128]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>` | = note: the `Copy` trait is required because the repeated element will be copied +help: consider annotating `Header<'_>` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied --> $DIR/repeat_empty_ok.rs:13:19 @@ -13,6 +17,10 @@ LL | let headers = [Header{value: &[0]}; 128]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>` | = note: the `Copy` trait is required because the repeated element will be copied +help: consider annotating `Header<'_>` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 2 previous errors diff --git a/src/test/ui/associated-types/defaults-suitability.stderr b/src/test/ui/associated-types/defaults-suitability.stderr index 6c63c01e2c2f7..43541c5dfbcb5 100644 --- a/src/test/ui/associated-types/defaults-suitability.stderr +++ b/src/test/ui/associated-types/defaults-suitability.stderr @@ -9,6 +9,10 @@ note: required by a bound in `Tr::Ty` | LL | type Ty: Clone = NotClone; | ^^^^^ required by this bound in `Tr::Ty` +help: consider annotating `NotClone` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error[E0277]: the trait bound `NotClone: Clone` is not satisfied --> $DIR/defaults-suitability.rs:22:15 @@ -24,6 +28,10 @@ LL | Self::Ty: Clone, LL | { LL | type Ty = NotClone; | -- required by a bound in this +help: consider annotating `NotClone` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error[E0277]: the trait bound `T: Clone` is not satisfied --> $DIR/defaults-suitability.rs:28:23 diff --git a/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr index cc874576cb7b9..7326324b03cca 100644 --- a/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Clone` is not implemented for `Error` | = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Clone-enum.stderr b/src/test/ui/derives/derives-span-Clone-enum.stderr index a4870635de870..229a4f7d9ff94 100644 --- a/src/test/ui/derives/derives-span-Clone-enum.stderr +++ b/src/test/ui/derives/derives-span-Clone-enum.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Clone` is not implemented for `Error` | = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Clone-struct.stderr b/src/test/ui/derives/derives-span-Clone-struct.stderr index 4507eeccc3aee..96bad9edad94c 100644 --- a/src/test/ui/derives/derives-span-Clone-struct.stderr +++ b/src/test/ui/derives/derives-span-Clone-struct.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Clone` is not implemented for `Error` | = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr b/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr index a79be7f574d6f..b61341e57e671 100644 --- a/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Clone` is not implemented for `Error` | = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Debug-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Debug-enum-struct-variant.stderr index bdcbbf0c75787..58a64a4f53bfc 100644 --- a/src/test/ui/derives/derives-span-Debug-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Debug-enum-struct-variant.stderr @@ -10,6 +10,10 @@ LL | x: Error = help: the trait `Debug` is not implemented for `Error` = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Debug-enum.stderr b/src/test/ui/derives/derives-span-Debug-enum.stderr index 4ffb75935af9b..e9bb5f960b04a 100644 --- a/src/test/ui/derives/derives-span-Debug-enum.stderr +++ b/src/test/ui/derives/derives-span-Debug-enum.stderr @@ -10,6 +10,10 @@ LL | Error = help: the trait `Debug` is not implemented for `Error` = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Debug-struct.stderr b/src/test/ui/derives/derives-span-Debug-struct.stderr index 74d2460bb6906..0a117c060ff38 100644 --- a/src/test/ui/derives/derives-span-Debug-struct.stderr +++ b/src/test/ui/derives/derives-span-Debug-struct.stderr @@ -10,6 +10,10 @@ LL | x: Error = help: the trait `Debug` is not implemented for `Error` = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Debug-tuple-struct.stderr b/src/test/ui/derives/derives-span-Debug-tuple-struct.stderr index 34ddb4e594377..f2e90a418455f 100644 --- a/src/test/ui/derives/derives-span-Debug-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Debug-tuple-struct.stderr @@ -10,6 +10,10 @@ LL | Error = help: the trait `Debug` is not implemented for `Error` = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Default-struct.stderr b/src/test/ui/derives/derives-span-Default-struct.stderr index dd2cfaf89bb8f..d4affd535eef4 100644 --- a/src/test/ui/derives/derives-span-Default-struct.stderr +++ b/src/test/ui/derives/derives-span-Default-struct.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Default` is not implemented for `Error` | = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Default)]` + | +LL | #[derive(Default)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Default-tuple-struct.stderr b/src/test/ui/derives/derives-span-Default-tuple-struct.stderr index 0674d635d3d0e..129351f599899 100644 --- a/src/test/ui/derives/derives-span-Default-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Default-tuple-struct.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Default` is not implemented for `Error` | = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Default)]` + | +LL | #[derive(Default)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Eq-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Eq-enum-struct-variant.stderr index 277454a1140e6..e3fb234b96e41 100644 --- a/src/test/ui/derives/derives-span-Eq-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Eq-enum-struct-variant.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Eq-enum.stderr b/src/test/ui/derives/derives-span-Eq-enum.stderr index 6a48ad24561ec..4e10c3f69e735 100644 --- a/src/test/ui/derives/derives-span-Eq-enum.stderr +++ b/src/test/ui/derives/derives-span-Eq-enum.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Eq-struct.stderr b/src/test/ui/derives/derives-span-Eq-struct.stderr index 7bf83e8eae2d3..bfdab052a2ed4 100644 --- a/src/test/ui/derives/derives-span-Eq-struct.stderr +++ b/src/test/ui/derives/derives-span-Eq-struct.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Eq-tuple-struct.stderr b/src/test/ui/derives/derives-span-Eq-tuple-struct.stderr index 13e2a55319eb5..26b8be343336b 100644 --- a/src/test/ui/derives/derives-span-Eq-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Eq-tuple-struct.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr index 7f24be959f019..fe5e0e96ac7af 100644 --- a/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Hash` is not implemented for `Error` | = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Hash-enum.stderr b/src/test/ui/derives/derives-span-Hash-enum.stderr index ae2921a16b315..99785b87ca83e 100644 --- a/src/test/ui/derives/derives-span-Hash-enum.stderr +++ b/src/test/ui/derives/derives-span-Hash-enum.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Hash` is not implemented for `Error` | = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Hash-struct.stderr b/src/test/ui/derives/derives-span-Hash-struct.stderr index 37b3af702a0c1..4db83dd130010 100644 --- a/src/test/ui/derives/derives-span-Hash-struct.stderr +++ b/src/test/ui/derives/derives-span-Hash-struct.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Hash` is not implemented for `Error` | = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr b/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr index 18624667d25ee..8660c97e69e1c 100644 --- a/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Hash` is not implemented for `Error` | = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Ord-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Ord-enum-struct-variant.stderr index b52c5a0d6a504..6e48332c25067 100644 --- a/src/test/ui/derives/derives-span-Ord-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Ord-enum-struct-variant.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Ord` is not implemented for `Error` | = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Ord-enum.stderr b/src/test/ui/derives/derives-span-Ord-enum.stderr index 2ea0496ea0db7..b05cf0a057b23 100644 --- a/src/test/ui/derives/derives-span-Ord-enum.stderr +++ b/src/test/ui/derives/derives-span-Ord-enum.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Ord` is not implemented for `Error` | = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Ord-struct.stderr b/src/test/ui/derives/derives-span-Ord-struct.stderr index 52cf0cf8cd75d..c4def34a83dad 100644 --- a/src/test/ui/derives/derives-span-Ord-struct.stderr +++ b/src/test/ui/derives/derives-span-Ord-struct.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Ord` is not implemented for `Error` | = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Ord-tuple-struct.stderr b/src/test/ui/derives/derives-span-Ord-tuple-struct.stderr index ecdf8d8cb5931..a3b288d0fb9cc 100644 --- a/src/test/ui/derives/derives-span-Ord-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Ord-tuple-struct.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Ord` is not implemented for `Error` | = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr index fc8eb1ebfd3e2..2d19aaf68afb1 100644 --- a/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr @@ -9,6 +9,10 @@ LL | x: Error | = help: the trait `PartialOrd` is not implemented for `Error` = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-PartialOrd-enum.stderr b/src/test/ui/derives/derives-span-PartialOrd-enum.stderr index 38053495a0572..dfbb8060ffa12 100644 --- a/src/test/ui/derives/derives-span-PartialOrd-enum.stderr +++ b/src/test/ui/derives/derives-span-PartialOrd-enum.stderr @@ -9,6 +9,10 @@ LL | Error | = help: the trait `PartialOrd` is not implemented for `Error` = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-PartialOrd-struct.stderr b/src/test/ui/derives/derives-span-PartialOrd-struct.stderr index 1c07b98f983de..ba63d86e8e46c 100644 --- a/src/test/ui/derives/derives-span-PartialOrd-struct.stderr +++ b/src/test/ui/derives/derives-span-PartialOrd-struct.stderr @@ -9,6 +9,10 @@ LL | x: Error | = help: the trait `PartialOrd` is not implemented for `Error` = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.stderr b/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.stderr index bf01252b07b8d..7686ed8064e79 100644 --- a/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.stderr @@ -9,6 +9,10 @@ LL | Error | = help: the trait `PartialOrd` is not implemented for `Error` = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr b/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr index d64b4509b260b..451058cd0ee01 100644 --- a/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr +++ b/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr @@ -48,6 +48,10 @@ LL | x: NoCloneOrEq | ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NoCloneOrEq` | = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `NoCloneOrEq` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to 3 previous errors diff --git a/src/test/ui/error-codes/E0277-3.rs b/src/test/ui/error-codes/E0277-3.rs new file mode 100644 index 0000000000000..428be79617d7f --- /dev/null +++ b/src/test/ui/error-codes/E0277-3.rs @@ -0,0 +1,8 @@ +fn foo(_: T) {} + +struct S; + +fn main() { + foo(S); + //~^ ERROR can't compare `S` with `S` +} diff --git a/src/test/ui/error-codes/E0277-3.stderr b/src/test/ui/error-codes/E0277-3.stderr new file mode 100644 index 0000000000000..0127e1ccc81ec --- /dev/null +++ b/src/test/ui/error-codes/E0277-3.stderr @@ -0,0 +1,22 @@ +error[E0277]: can't compare `S` with `S` + --> $DIR/E0277-3.rs:6:9 + | +LL | foo(S); + | --- ^ no implementation for `S == S` + | | + | required by a bound introduced by this call + | + = help: the trait `PartialEq` is not implemented for `S` +note: required by a bound in `foo` + --> $DIR/E0277-3.rs:1:11 + | +LL | fn foo(_: T) {} + | ^^^^^^^^^ required by this bound in `foo` +help: consider annotating `S` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr b/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr index e5db2f1b7c35b..c6fa02cb9a6b4 100644 --- a/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr +++ b/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr @@ -10,6 +10,10 @@ note: required by a bound in `Family2::Member` | LL | type Member<'a>: for<'b> PartialEq> = Foo; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Family2::Member` +help: consider annotating `Foo` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | error: aborting due to previous error diff --git a/src/test/ui/generic-associated-types/issue-87429-specialization.stderr b/src/test/ui/generic-associated-types/issue-87429-specialization.stderr index ca44ecfdb537d..015e0c7792fec 100644 --- a/src/test/ui/generic-associated-types/issue-87429-specialization.stderr +++ b/src/test/ui/generic-associated-types/issue-87429-specialization.stderr @@ -20,6 +20,10 @@ note: required by a bound in `Family::Member` | LL | type Member<'a>: for<'b> PartialEq>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Family::Member` +help: consider annotating `Foo` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/issues/issue-20162.stderr b/src/test/ui/issues/issue-20162.stderr index 6848c3f0d8a54..d70bf6e1d921c 100644 --- a/src/test/ui/issues/issue-20162.stderr +++ b/src/test/ui/issues/issue-20162.stderr @@ -9,6 +9,10 @@ note: required by a bound in `slice::::sort` | LL | T: Ord, | ^^^ required by this bound in `slice::::sort` +help: consider annotating `X` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | error: aborting due to previous error diff --git a/src/test/ui/issues/issue-21160.stderr b/src/test/ui/issues/issue-21160.stderr index 300c1272ef6c0..266749376eb05 100644 --- a/src/test/ui/issues/issue-21160.stderr +++ b/src/test/ui/issues/issue-21160.stderr @@ -7,6 +7,10 @@ LL | struct Foo(Bar); | ^^^ the trait `Hash` is not implemented for `Bar` | = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Bar` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | error: aborting due to previous error diff --git a/src/test/ui/issues/issue-34229.stderr b/src/test/ui/issues/issue-34229.stderr index 71e02f2fd86cc..69ef876d25502 100644 --- a/src/test/ui/issues/issue-34229.stderr +++ b/src/test/ui/issues/issue-34229.stderr @@ -8,6 +8,10 @@ LL | #[derive(PartialEq, PartialOrd)] struct Nope(Comparable); | = help: the trait `PartialOrd` is not implemented for `Comparable` = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Comparable` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialEq)] #[derive(PartialOrd)] + | +++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/kindck/kindck-impl-type-params.nll.stderr b/src/test/ui/kindck/kindck-impl-type-params.nll.stderr index 7129bad8a978a..84e02a24964ef 100644 --- a/src/test/ui/kindck/kindck-impl-type-params.nll.stderr +++ b/src/test/ui/kindck/kindck-impl-type-params.nll.stderr @@ -91,6 +91,10 @@ note: required because of the requirements on the impl of `Gettable` for `S LL | impl Gettable for S {} | ^^^^^^^^^^^ ^^^^ = note: required for the cast to the object type `dyn Gettable` +help: consider annotating `Foo` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 6 previous errors diff --git a/src/test/ui/kindck/kindck-impl-type-params.stderr b/src/test/ui/kindck/kindck-impl-type-params.stderr index 3558f0c9e6294..22e0988ebd408 100644 --- a/src/test/ui/kindck/kindck-impl-type-params.stderr +++ b/src/test/ui/kindck/kindck-impl-type-params.stderr @@ -99,6 +99,10 @@ note: required because of the requirements on the impl of `Gettable` for `S LL | impl Gettable for S {} | ^^^^^^^^^^^ ^^^^ = note: required for the cast to the object type `dyn Gettable` +help: consider annotating `Foo` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 7 previous errors diff --git a/src/test/ui/malformed/malformed-derive-entry.stderr b/src/test/ui/malformed/malformed-derive-entry.stderr index 0ddce1be476c3..803883460f08f 100644 --- a/src/test/ui/malformed/malformed-derive-entry.stderr +++ b/src/test/ui/malformed/malformed-derive-entry.stderr @@ -28,6 +28,10 @@ note: required by a bound in `Copy` LL | pub trait Copy: Clone { | ^^^^^ required by this bound in `Copy` = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Test1` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error[E0277]: the trait bound `Test2: Clone` is not satisfied --> $DIR/malformed-derive-entry.rs:6:10 @@ -41,6 +45,10 @@ note: required by a bound in `Copy` LL | pub trait Copy: Clone { | ^^^^^ required by this bound in `Copy` = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Test2` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to 5 previous errors diff --git a/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr b/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr index dc73bcd6e4d05..c2515c40b1d77 100644 --- a/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr +++ b/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr @@ -11,6 +11,10 @@ note: required by a bound in `Result::::unwrap` | LL | E: fmt::Debug, | ^^^^^^^^^^ required by this bound in `Result::::unwrap` +help: consider annotating `Foo` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/not-clone-closure.stderr b/src/test/ui/not-clone-closure.stderr index a62c21f2ee971..92909797c9679 100644 --- a/src/test/ui/not-clone-closure.stderr +++ b/src/test/ui/not-clone-closure.stderr @@ -11,6 +11,10 @@ LL | let hello = hello.clone(); | ^^^^^ within `[closure@$DIR/not-clone-closure.rs:7:17: 9:6]`, the trait `Clone` is not implemented for `S` | = note: required because it appears within the type `[closure@$DIR/not-clone-closure.rs:7:17: 9:6]` +help: consider annotating `S` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/on-unimplemented/no-debug.stderr b/src/test/ui/on-unimplemented/no-debug.stderr index b17c1d4c25208..417e01e491b47 100644 --- a/src/test/ui/on-unimplemented/no-debug.stderr +++ b/src/test/ui/on-unimplemented/no-debug.stderr @@ -7,6 +7,10 @@ LL | println!("{:?} {:?}", Foo, Bar); = help: the trait `Debug` is not implemented for `Foo` = note: add `#[derive(Debug)]` to `Foo` or manually `impl Debug for Foo` = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Foo` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error[E0277]: `Bar` doesn't implement `Debug` --> $DIR/no-debug.rs:10:32 diff --git a/src/test/ui/repeat-to-run-dtor-twice.stderr b/src/test/ui/repeat-to-run-dtor-twice.stderr index f07bbe3b9f3f6..904413712cde1 100644 --- a/src/test/ui/repeat-to-run-dtor-twice.stderr +++ b/src/test/ui/repeat-to-run-dtor-twice.stderr @@ -5,6 +5,10 @@ LL | let _ = [ a; 5 ]; | ^^^^^^^^ the trait `Copy` is not implemented for `Foo` | = note: the `Copy` trait is required because the repeated element will be copied +help: consider annotating `Foo` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to previous error diff --git a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr index 3cdab6541e7d1..ea1f66d78a378 100644 --- a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr +++ b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr @@ -7,6 +7,10 @@ LL | let _: NotDebug = dbg!(NotDebug); = help: the trait `Debug` is not implemented for `NotDebug` = note: add `#[derive(Debug)]` to `NotDebug` or manually `impl Debug for NotDebug` = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `NotDebug` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr index b0af45acda1ed..0a2a5f0f24578 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr @@ -17,6 +17,10 @@ note: required by a bound in `equals_self` | LL | const fn equals_self(t: &T) -> bool { | ^^^^^^^^^^^^^^^^ required by this bound in `equals_self` +help: consider annotating `S` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | error: aborting due to previous error diff --git a/src/test/ui/specialization/issue-59435.stderr b/src/test/ui/specialization/issue-59435.stderr index bb5d90f001ee7..2114594066861 100644 --- a/src/test/ui/specialization/issue-59435.stderr +++ b/src/test/ui/specialization/issue-59435.stderr @@ -9,6 +9,10 @@ note: required by a bound in `MyTrait::MyType` | LL | type MyType: Default; | ^^^^^^^ required by this bound in `MyTrait::MyType` +help: consider annotating `MyStruct` with `#[derive(Default)]` + | +LL | #[derive(Default)] + | error: aborting due to previous error diff --git a/src/test/ui/structs/struct-path-alias-bounds.stderr b/src/test/ui/structs/struct-path-alias-bounds.stderr index 7a80e7270ba36..266291f62b45d 100644 --- a/src/test/ui/structs/struct-path-alias-bounds.stderr +++ b/src/test/ui/structs/struct-path-alias-bounds.stderr @@ -9,6 +9,10 @@ note: required by a bound in `S` | LL | struct S { a: T } | ^^^^^ required by this bound in `S` +help: consider annotating `NoClone` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/suggestions/derive-macro-missing-bounds.stderr b/src/test/ui/suggestions/derive-macro-missing-bounds.stderr index 7a4f7e209c195..75658f58c8a1b 100644 --- a/src/test/ui/suggestions/derive-macro-missing-bounds.stderr +++ b/src/test/ui/suggestions/derive-macro-missing-bounds.stderr @@ -9,6 +9,10 @@ LL | struct Outer(Inner); = help: the trait `Debug` is not implemented for `a::Inner` = note: add `#[derive(Debug)]` to `a::Inner` or manually `impl Debug for a::Inner` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `a::Inner` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement | LL | struct Outer(Inner) where a::Inner: Debug; diff --git a/src/test/ui/suggestions/issue-84973-blacklist.stderr b/src/test/ui/suggestions/issue-84973-blacklist.stderr index ae55c96702ada..5d8d688a073ca 100644 --- a/src/test/ui/suggestions/issue-84973-blacklist.stderr +++ b/src/test/ui/suggestions/issue-84973-blacklist.stderr @@ -25,6 +25,10 @@ note: required by a bound in `f_clone` | LL | fn f_clone(t: T) {} | ^^^^^ required by this bound in `f_clone` +help: consider annotating `S` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error[E0277]: `[static generator@$DIR/issue-84973-blacklist.rs:17:13: 17:33]` cannot be unpinned --> $DIR/issue-84973-blacklist.rs:17:5 diff --git a/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr b/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr index 9ceeea4872fbb..d7697dcc6405b 100644 --- a/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr +++ b/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr @@ -24,6 +24,10 @@ note: required by a bound in `copy` | LL | fn copy(x: T) -> (T, T) { (x, x) } | ^^^^^ required by this bound in `copy` +help: consider annotating `NoClone` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 2 previous errors diff --git a/src/test/ui/traits/issue-71136.stderr b/src/test/ui/traits/issue-71136.stderr index 45b1e1095c7d8..62a2a64ed142c 100644 --- a/src/test/ui/traits/issue-71136.stderr +++ b/src/test/ui/traits/issue-71136.stderr @@ -9,6 +9,10 @@ LL | the_foos: Vec, | = note: required because of the requirements on the impl of `Clone` for `Vec` = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Foo` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/union/union-derive-clone.mirunsafeck.stderr b/src/test/ui/union/union-derive-clone.mirunsafeck.stderr index de0bc7830b73a..c242a7de7abfb 100644 --- a/src/test/ui/union/union-derive-clone.mirunsafeck.stderr +++ b/src/test/ui/union/union-derive-clone.mirunsafeck.stderr @@ -38,6 +38,10 @@ note: required by a bound in `AssertParamIsCopy` LL | pub struct AssertParamIsCopy { | ^^^^ required by this bound in `AssertParamIsCopy` = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `U1` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 2 previous errors diff --git a/src/test/ui/union/union-derive-clone.thirunsafeck.stderr b/src/test/ui/union/union-derive-clone.thirunsafeck.stderr index de0bc7830b73a..c242a7de7abfb 100644 --- a/src/test/ui/union/union-derive-clone.thirunsafeck.stderr +++ b/src/test/ui/union/union-derive-clone.thirunsafeck.stderr @@ -38,6 +38,10 @@ note: required by a bound in `AssertParamIsCopy` LL | pub struct AssertParamIsCopy { | ^^^^ required by this bound in `AssertParamIsCopy` = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `U1` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 2 previous errors diff --git a/src/test/ui/union/union-derive-eq.mirunsafeck.stderr b/src/test/ui/union/union-derive-eq.mirunsafeck.stderr index ff4dfcd291760..99505f3163968 100644 --- a/src/test/ui/union/union-derive-eq.mirunsafeck.stderr +++ b/src/test/ui/union/union-derive-eq.mirunsafeck.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `PartialEqNotEq` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/union/union-derive-eq.thirunsafeck.stderr b/src/test/ui/union/union-derive-eq.thirunsafeck.stderr index ff4dfcd291760..99505f3163968 100644 --- a/src/test/ui/union/union-derive-eq.thirunsafeck.stderr +++ b/src/test/ui/union/union-derive-eq.thirunsafeck.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `PartialEqNotEq` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/wf/wf-const-type.stderr b/src/test/ui/wf/wf-const-type.stderr index 5a6d66ee7fa7c..e47920d3dfcf8 100644 --- a/src/test/ui/wf/wf-const-type.stderr +++ b/src/test/ui/wf/wf-const-type.stderr @@ -10,6 +10,10 @@ note: required by a bound in `IsCopy` | LL | struct IsCopy { t: T } | ^^^^ required by this bound in `IsCopy` +help: consider annotating `NotCopy` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to previous error diff --git a/src/test/ui/wf/wf-static-type.stderr b/src/test/ui/wf/wf-static-type.stderr index c45bd5777620c..4ae69cf2e1ff8 100644 --- a/src/test/ui/wf/wf-static-type.stderr +++ b/src/test/ui/wf/wf-static-type.stderr @@ -10,6 +10,10 @@ note: required by a bound in `IsCopy` | LL | struct IsCopy { t: T } | ^^^^ required by this bound in `IsCopy` +help: consider annotating `NotCopy` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to previous error diff --git a/src/test/ui/where-clauses/where-clauses-method-unsatisfied.stderr b/src/test/ui/where-clauses/where-clauses-method-unsatisfied.stderr index 3a4cbb62d5597..c13552bc26eee 100644 --- a/src/test/ui/where-clauses/where-clauses-method-unsatisfied.stderr +++ b/src/test/ui/where-clauses/where-clauses-method-unsatisfied.stderr @@ -11,6 +11,10 @@ note: required by a bound in `Foo::::equals` | LL | fn equals(&self, u: &Foo) -> bool where T : Eq { | ^^ required by this bound in `Foo::::equals` +help: consider annotating `Bar` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/where-clauses/where-clauses-unsatisfied.stderr b/src/test/ui/where-clauses/where-clauses-unsatisfied.stderr index ba18119ff1b4f..b1805a4522f4d 100644 --- a/src/test/ui/where-clauses/where-clauses-unsatisfied.stderr +++ b/src/test/ui/where-clauses/where-clauses-unsatisfied.stderr @@ -9,6 +9,10 @@ note: required by a bound in `equal` | LL | fn equal(a: &T, b: &T) -> bool where T : Eq { a == b } | ^^ required by this bound in `equal` +help: consider annotating `Struct` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error