From a19952435bada35dbffd8b219211ecacfcaa6754 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 2 Sep 2023 13:09:52 -0700 Subject: [PATCH] Implement AsDisplay using GAT --- .github/workflows/ci.yml | 2 +- Cargo.toml | 2 +- README.md | 2 +- impl/Cargo.toml | 2 +- src/display.rs | 30 +++++++++++++++++------------- tests/ui/no-display.stderr | 2 +- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b56868ec..cd685a24 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: strategy: fail-fast: false matrix: - rust: [nightly, beta, stable, 1.56.0] + rust: [nightly, beta, stable, 1.65.0] timeout-minutes: 45 steps: - uses: actions/checkout@v3 diff --git a/Cargo.toml b/Cargo.toml index 0a8526cb..07d6ced9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" keywords = ["error", "error-handling", "derive"] license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/thiserror" -rust-version = "1.56" +rust-version = "1.65" [dependencies] thiserror-impl = { version = "=1.0.47", path = "impl" } diff --git a/README.md b/README.md index 9de063c3..1bae0383 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This library provides a convenient derive macro for the standard library's thiserror = "1.0" ``` -*Compiler support: requires rustc 1.56+* +*Compiler support: requires rustc 1.65+*
diff --git a/impl/Cargo.toml b/impl/Cargo.toml index 091be615..4aaacae3 100644 --- a/impl/Cargo.toml +++ b/impl/Cargo.toml @@ -6,7 +6,7 @@ description = "Implementation detail of the `thiserror` crate" edition = "2021" license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/thiserror" -rust-version = "1.56" +rust-version = "1.65" [lib] proc-macro = true diff --git a/src/display.rs b/src/display.rs index 58d11e45..38ae9e86 100644 --- a/src/display.rs +++ b/src/display.rs @@ -2,37 +2,41 @@ use std::fmt::Display; use std::path::{self, Path, PathBuf}; #[doc(hidden)] -pub trait AsDisplay<'a> { - type Target: Display; +pub trait AsDisplay { + type Target<'a>: Display + where + Self: 'a; - fn as_display(&'a self) -> Self::Target; + fn as_display<'a>(&'a self) -> Self::Target<'a>; } -impl<'a, T> AsDisplay<'a> for &T +impl AsDisplay for &T where - T: Display + 'a, + T: Display, { - type Target = &'a T; + type Target<'a> = &'a T + where + Self: 'a; - fn as_display(&'a self) -> Self::Target { + fn as_display<'a>(&'a self) -> Self::Target<'a> { *self } } -impl<'a> AsDisplay<'a> for Path { - type Target = path::Display<'a>; +impl AsDisplay for Path { + type Target<'a> = path::Display<'a>; #[inline] - fn as_display(&'a self) -> Self::Target { + fn as_display<'a>(&'a self) -> Self::Target<'a> { self.display() } } -impl<'a> AsDisplay<'a> for PathBuf { - type Target = path::Display<'a>; +impl AsDisplay for PathBuf { + type Target<'a> = path::Display<'a>; #[inline] - fn as_display(&'a self) -> Self::Target { + fn as_display<'a>(&'a self) -> Self::Target<'a> { self.display() } } diff --git a/tests/ui/no-display.stderr b/tests/ui/no-display.stderr index 0f47c24b..26dc8429 100644 --- a/tests/ui/no-display.stderr +++ b/tests/ui/no-display.stderr @@ -9,7 +9,7 @@ error[E0599]: the method `as_display` exists for reference `&NoDisplay`, but its | = note: the following trait bounds were not satisfied: `NoDisplay: std::fmt::Display` - which is required by `&NoDisplay: AsDisplay<'_>` + which is required by `&NoDisplay: AsDisplay` note: the trait `std::fmt::Display` must be implemented --> $RUST/core/src/fmt/mod.rs |