diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65a20f51..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.56.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: diff --git a/Cargo.toml b/Cargo.toml index 4ed21739..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)" @@ -9,10 +9,10 @@ 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" } +thiserror-impl = { version = "=1.0.66", path = "impl" } [dev-dependencies] anyhow = "1.0.73" 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/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); }) } diff --git a/impl/Cargo.toml b/impl/Cargo.toml index fc0a53be..5acbe8f4 100644 --- a/impl/Cargo.toml +++ b/impl/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "thiserror-impl" -version = "1.0.65" +version = "1.0.66" authors = ["David Tolnay "] 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 @@ -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 e0ac02b1..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, @@ -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,14 +107,12 @@ 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::>()?; - 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)? 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 {} 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, 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))]