From e8d60cf0e5c4ef21ffb96617b5be160990c56741 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio Date: Mon, 5 Aug 2024 12:28:14 +0200 Subject: [PATCH] Add compile_fail test for on purpose limited bounds (#393, #392) Resolves #392 Related to #371 ## Synopsis Before #371 this code would compile without any issues, but that would actually hide the problem that the resulting `Debug` implementation was never applicable, because the bounds could not be satisfied. ## Solution This problem was already solved by #371, but this adds a test case to ensure that we don't regress here again. --- tests/compile_fail/debug/lifetime_no_debug.rs | 10 ++++++++++ .../compile_fail/debug/lifetime_no_debug.stderr | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/compile_fail/debug/lifetime_no_debug.rs create mode 100644 tests/compile_fail/debug/lifetime_no_debug.stderr diff --git a/tests/compile_fail/debug/lifetime_no_debug.rs b/tests/compile_fail/debug/lifetime_no_debug.rs new file mode 100644 index 00000000..46e7382d --- /dev/null +++ b/tests/compile_fail/debug/lifetime_no_debug.rs @@ -0,0 +1,10 @@ +struct NoDebug<'a> { + a: &'a f64, +} + +#[derive(derive_more::Debug)] +struct SomeType<'a> { + no_debug: NoDebug<'a>, +} + +fn main() {} diff --git a/tests/compile_fail/debug/lifetime_no_debug.stderr b/tests/compile_fail/debug/lifetime_no_debug.stderr new file mode 100644 index 00000000..66d02bba --- /dev/null +++ b/tests/compile_fail/debug/lifetime_no_debug.stderr @@ -0,0 +1,16 @@ +error[E0277]: `NoDebug<'_>` doesn't implement `Debug` + --> tests/compile_fail/debug/lifetime_no_debug.rs:5:10 + | +5 | #[derive(derive_more::Debug)] + | ^^^^^^^^^^^^^^^^^^ `NoDebug<'_>` cannot be formatted using `{:?}` + | + = help: the trait `Debug` is not implemented for `NoDebug<'_>`, which is required by `&NoDebug<'_>: Debug` + = note: add `#[derive(Debug)]` to `NoDebug<'_>` or manually `impl Debug for NoDebug<'_>` + = note: required for `&NoDebug<'_>` to implement `Debug` + = note: required for the cast from `&&NoDebug<'_>` to `&dyn Debug` + = note: this error originates in the derive macro `derive_more::Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `NoDebug<'_>` with `#[derive(Debug)]` + | +1 + #[derive(Debug)] +2 | struct NoDebug<'a> { + |