From b94add8c9ba7c01c5c109413cc3fb00021a66792 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 15 Dec 2023 14:06:41 -0800 Subject: [PATCH] Add ui test where fallback impl conflicts with handwritten Display --- tests/ui/fallback-impl-with-display.rs | 14 ++++++++++++++ tests/ui/fallback-impl-with-display.stderr | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/ui/fallback-impl-with-display.rs create mode 100644 tests/ui/fallback-impl-with-display.stderr diff --git a/tests/ui/fallback-impl-with-display.rs b/tests/ui/fallback-impl-with-display.rs new file mode 100644 index 0000000..3341187 --- /dev/null +++ b/tests/ui/fallback-impl-with-display.rs @@ -0,0 +1,14 @@ +use std::fmt::{self, Display}; +use thiserror::Error; + +#[derive(Error, Debug)] +#[error] +pub struct MyError; + +impl Display for MyError { + fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { + unimplemented!() + } +} + +fn main() {} diff --git a/tests/ui/fallback-impl-with-display.stderr b/tests/ui/fallback-impl-with-display.stderr new file mode 100644 index 0000000..6bd3730 --- /dev/null +++ b/tests/ui/fallback-impl-with-display.stderr @@ -0,0 +1,16 @@ +error: expected attribute arguments in parentheses: #[error(...)] + --> tests/ui/fallback-impl-with-display.rs:5:3 + | +5 | #[error] + | ^^^^^ + +error[E0119]: conflicting implementations of trait `std::fmt::Display` for type `MyError` + --> tests/ui/fallback-impl-with-display.rs:4:10 + | +4 | #[derive(Error, Debug)] + | ^^^^^ conflicting implementation for `MyError` +... +8 | impl Display for MyError { + | ------------------------ first implementation here + | + = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)