From 010c2d81e9930b21d9ea1d4807a6da4f7edac66e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 24 Oct 2024 17:43:57 -0700 Subject: [PATCH 1/7] Seal the private AsDisplay trait --- src/display.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/display.rs b/src/display.rs index 3c43216a..7a62ae20 100644 --- a/src/display.rs +++ b/src/display.rs @@ -2,7 +2,7 @@ use core::fmt::Display; use std::path::{self, Path, PathBuf}; #[doc(hidden)] -pub trait AsDisplay<'a> { +pub trait AsDisplay<'a>: Sealed { // TODO: convert to generic associated type. // https://github.com/dtolnay/thiserror/pull/253 type Target: Display; @@ -38,3 +38,9 @@ impl<'a> AsDisplay<'a> for PathBuf { self.display() } } + +#[doc(hidden)] +pub trait Sealed {} +impl Sealed for &T {} +impl Sealed for Path {} +impl Sealed for PathBuf {} From 5d3edf9d7e57f8a3080b12f96ab7f1f6e491061e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 31 Oct 2024 14:25:18 -0700 Subject: [PATCH 2/7] Improve error on malformed format attribute --- impl/src/attr.rs | 12 ++++++++---- tests/ui/concat-display.stderr | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/impl/src/attr.rs b/impl/src/attr.rs index e0ac02b1..e59b5191 100644 --- a/impl/src/attr.rs +++ b/impl/src/attr.rs @@ -91,7 +91,11 @@ fn parse_error_attribute<'a>(attrs: &mut Attrs<'a>, attr: &'a Attribute) -> Resu syn::custom_keyword!(transparent); attr.parse_args_with(|input: ParseStream| { - if let Some(kw) = input.parse::>()? { + let lookahead = input.lookahead1(); + let fmt = if lookahead.peek(LitStr) { + input.parse::()? + } else if lookahead.peek(transparent) { + let kw: transparent = input.parse()?; if attrs.transparent.is_some() { return Err(Error::new_spanned( attr, @@ -103,9 +107,9 @@ fn parse_error_attribute<'a>(attrs: &mut Attrs<'a>, attr: &'a Attribute) -> Resu span: kw.span, }); return Ok(()); - } - - let fmt: LitStr = input.parse()?; + } else { + return Err(lookahead.error()); + }; let ahead = input.fork(); ahead.parse::>()?; diff --git a/tests/ui/concat-display.stderr b/tests/ui/concat-display.stderr index dbecd69f..d92e635a 100644 --- a/tests/ui/concat-display.stderr +++ b/tests/ui/concat-display.stderr @@ -1,4 +1,4 @@ -error: expected string literal +error: expected string literal or `transparent` --> tests/ui/concat-display.rs:8:17 | 8 | #[error(concat!("invalid ", $what))] From 0e2bef9ff16420f81c55a3eacda91a9992a1f526 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 31 Oct 2024 16:42:50 -0700 Subject: [PATCH 3/7] Raise required compiler to rust 1.61 --- .github/workflows/ci.yml | 2 +- Cargo.toml | 2 +- README.md | 2 +- impl/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65a20f51..773ca17f 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.61.0] timeout-minutes: 45 steps: - uses: actions/checkout@v4 diff --git a/Cargo.toml b/Cargo.toml index 4ed21739..bc505433 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.61" [dependencies] thiserror-impl = { version = "=1.0.65", path = "impl" } diff --git a/README.md b/README.md index 3b7d7437..54e736d3 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.61+*
diff --git a/impl/Cargo.toml b/impl/Cargo.toml index fc0a53be..563271aa 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.61" [lib] proc-macro = true From 8fb92ff3f0c93d08fe2a38fc657649ebfc2b5754 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 31 Oct 2024 16:43:53 -0700 Subject: [PATCH 4/7] Resolve uninlined_format_args pedantic clippy lint in build script warning: variables can be used directly in the `format!` string --> build.rs:140:9 | 140 | / eprintln!( 141 | | "Environment variable ${} is not set during execution of build script", 142 | | key, 143 | | ); | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args = note: `-W clippy::uninlined-format-args` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::uninlined_format_args)]` --- build.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 51ac436e..4b40e9dd 100644 --- a/build.rs +++ b/build.rs @@ -137,10 +137,7 @@ fn compile_probe(rustc_bootstrap: bool) -> bool { fn cargo_env_var(key: &str) -> OsString { env::var_os(key).unwrap_or_else(|| { - eprintln!( - "Environment variable ${} is not set during execution of build script", - key, - ); + eprintln!("Environment variable ${key} is not set during execution of build script"); process::exit(1); }) } From 51a5e4cbfedf77915db3e7e23abfd6e5b75d3b05 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 31 Oct 2024 16:48:51 -0700 Subject: [PATCH 5/7] Raise minimum compiler for test suite to rust 1.70 With 1.61: error: package `indexmap v2.6.0` cannot be built because it requires rustc 1.63 or newer, while the currently active rustc version is 1.61.0 With 1.63: error: package `toml_datetime v0.6.8` cannot be built because it requires rustc 1.65 or newer, while the currently active rustc version is 1.63.0 With 1.65: error: package `trybuild v1.0.101` cannot be built because it requires rustc 1.70 or newer, while the currently active rustc version is 1.65.0 Either upgrade to rustc 1.70 or newer, or use cargo update -p trybuild@1.0.101 --precise ver where `ver` is the latest version of `trybuild` supporting rustc 1.65.0 --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 773ca17f..5dd92eba 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.61.0] + rust: [nightly, beta, stable, 1.70.0, 1.61.0] timeout-minutes: 45 steps: - uses: actions/checkout@v4 @@ -39,6 +39,7 @@ jobs: run: echo RUSTFLAGS=${RUSTFLAGS}\ --cfg=thiserror_nightly_testing >> $GITHUB_ENV if: matrix.rust == 'nightly' - run: cargo test --all + if: matrix.rust != '1.61.0' - uses: actions/upload-artifact@v4 if: matrix.rust == 'nightly' && always() with: From 3d79a908aca69e2ea80ed51905de8ca9fdf971e5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 31 Oct 2024 16:38:58 -0700 Subject: [PATCH 6/7] Use peek2(End) instead of fork/advance_to --- impl/Cargo.toml | 2 +- impl/src/attr.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/impl/Cargo.toml b/impl/Cargo.toml index 563271aa..a768f966 100644 --- a/impl/Cargo.toml +++ b/impl/Cargo.toml @@ -14,7 +14,7 @@ proc-macro = true [dependencies] proc-macro2 = "1.0.74" quote = "1.0.35" -syn = "2.0.46" +syn = "2.0.86" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/impl/src/attr.rs b/impl/src/attr.rs index e59b5191..a3746b03 100644 --- a/impl/src/attr.rs +++ b/impl/src/attr.rs @@ -2,7 +2,7 @@ use proc_macro2::{Delimiter, Group, Literal, Punct, Spacing, Span, TokenStream, use quote::{format_ident, quote, ToTokens}; use std::collections::BTreeSet as Set; use syn::parse::discouraged::Speculative; -use syn::parse::ParseStream; +use syn::parse::{End, ParseStream}; use syn::{ braced, bracketed, parenthesized, token, Attribute, Error, Ident, Index, LitFloat, LitInt, LitStr, Meta, Result, Token, @@ -111,10 +111,8 @@ fn parse_error_attribute<'a>(attrs: &mut Attrs<'a>, attr: &'a Attribute) -> Resu return Err(lookahead.error()); }; - let ahead = input.fork(); - ahead.parse::>()?; - let args = if ahead.is_empty() { - input.advance_to(&ahead); + let args = if input.is_empty() || input.peek(Token![,]) && input.peek2(End) { + input.parse::>()?; TokenStream::new() } else { parse_token_expr(input, false)? From d1a8254ee5f7ed833f21972ca0f15a6b266614a5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 31 Oct 2024 16:54:13 -0700 Subject: [PATCH 7/7] Release 1.0.66 --- Cargo.toml | 4 ++-- impl/Cargo.toml | 2 +- src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bc505433..96a87e85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thiserror" -version = "1.0.65" +version = "1.0.66" authors = ["David Tolnay "] categories = ["rust-patterns"] description = "derive(Error)" @@ -12,7 +12,7 @@ repository = "https://github.com/dtolnay/thiserror" rust-version = "1.61" [dependencies] -thiserror-impl = { version = "=1.0.65", path = "impl" } +thiserror-impl = { version = "=1.0.66", path = "impl" } [dev-dependencies] anyhow = "1.0.73" diff --git a/impl/Cargo.toml b/impl/Cargo.toml index a768f966..5acbe8f4 100644 --- a/impl/Cargo.toml +++ b/impl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thiserror-impl" -version = "1.0.65" +version = "1.0.66" authors = ["David Tolnay "] description = "Implementation detail of the `thiserror` crate" edition = "2021" diff --git a/src/lib.rs b/src/lib.rs index 15872e3a..b7afdb7b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,7 +258,7 @@ //! //! [`anyhow`]: https://github.com/dtolnay/anyhow -#![doc(html_root_url = "https://docs.rs/thiserror/1.0.65")] +#![doc(html_root_url = "https://docs.rs/thiserror/1.0.66")] #![allow( clippy::module_name_repetitions, clippy::needless_lifetimes,