From 126ec98a33a5074f4d5e1bd6b309ac5669f3637a Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Fri, 22 Mar 2019 22:28:31 -0400 Subject: [PATCH] Remove the unstable `snafu::display` attribute Turns out, this was never supposed to be supported in the first place. - https://github.com/rust-lang/rust/pull/58899 --- Cargo.toml | 4 -- .../tests/compile-fail/error-reporting.rs | 8 ---- compatibility-tests/nightly/.gitignore | 3 -- compatibility-tests/nightly/Cargo.toml | 8 ---- compatibility-tests/nightly/rust-toolchain | 1 - compatibility-tests/nightly/src/lib.rs | 0 .../nightly/tests/unstable_attributes.rs | 40 ----------------- snafu-derive/src/lib.rs | 43 +------------------ src/lib.rs | 8 ---- 9 files changed, 2 insertions(+), 113 deletions(-) delete mode 100644 compatibility-tests/nightly/.gitignore delete mode 100644 compatibility-tests/nightly/Cargo.toml delete mode 100644 compatibility-tests/nightly/rust-toolchain delete mode 100644 compatibility-tests/nightly/src/lib.rs delete mode 100644 compatibility-tests/nightly/tests/unstable_attributes.rs diff --git a/Cargo.toml b/Cargo.toml index 87405b6f..e2d90763 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,15 +28,11 @@ backtraces = ["snafu-derive/backtraces", "backtrace"] # New methods on `Error`; re-export of proc-macro rust_1_30 = ["snafu-derive/rust_1_30"] -# The `snafu::display` attribute -unstable_display_attribute = ["snafu-derive/unstable_display_attribute"] - [workspace] # The compatibility tests each set feature flags for the library and # cannot be in the same crate graph. exclude = [ "compatibility-tests/compile-fail", - "compatibility-tests/nightly", "compatibility-tests/v1_30", "compatibility-tests/v1_18", "compatibility-tests/without-backtrace", diff --git a/compatibility-tests/compile-fail/tests/compile-fail/error-reporting.rs b/compatibility-tests/compile-fail/tests/compile-fail/error-reporting.rs index fc7dcc27..b56d3be2 100644 --- a/compatibility-tests/compile-fail/tests/compile-fail/error-reporting.rs +++ b/compatibility-tests/compile-fail/tests/compile-fail/error-reporting.rs @@ -23,14 +23,6 @@ enum TupleEnumVariant { //~^ ERROR Only struct-like and unit enum variants are supported } -#[derive(Snafu)] -enum SnafuDisplayWrongKindOfExpression { - #[snafu::display {}] - //~^ ERROR A parenthesized format string with optional values is expected - //~^^ expected one of `(` or `=` - Alpha(i32), -} - #[derive(Snafu)] enum OldSnafuDisplayWithoutArgument { #[snafu_display] diff --git a/compatibility-tests/nightly/.gitignore b/compatibility-tests/nightly/.gitignore deleted file mode 100644 index 69369904..00000000 --- a/compatibility-tests/nightly/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/target -**/*.rs.bk -Cargo.lock diff --git a/compatibility-tests/nightly/Cargo.toml b/compatibility-tests/nightly/Cargo.toml deleted file mode 100644 index 4abf1f2d..00000000 --- a/compatibility-tests/nightly/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "nightly" -version = "0.1.0" -authors = ["Jake Goulding "] -edition = "2018" - -[dependencies] -snafu = { path = "../..", features = ["unstable_display_attribute"] } diff --git a/compatibility-tests/nightly/rust-toolchain b/compatibility-tests/nightly/rust-toolchain deleted file mode 100644 index bf867e0a..00000000 --- a/compatibility-tests/nightly/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly diff --git a/compatibility-tests/nightly/src/lib.rs b/compatibility-tests/nightly/src/lib.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/compatibility-tests/nightly/tests/unstable_attributes.rs b/compatibility-tests/nightly/tests/unstable_attributes.rs deleted file mode 100644 index f217e913..00000000 --- a/compatibility-tests/nightly/tests/unstable_attributes.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![feature(unrestricted_attribute_tokens)] - -use snafu::{Snafu, ResultExt}; -use std::{fs, io, path::{Path, PathBuf}}; - -#[derive(Debug, Snafu)] -enum Error { - #[snafu::display("Could not open config file at {}: {}", filename.display(), source)] - OpenConfig { filename: PathBuf, source: io::Error }, - #[snafu::display("Could not open config file at {}", source)] - SaveConfig { source: io::Error }, - #[snafu::display("No user available")] - MissingUser, -} - -type Result = std::result::Result; - -const CONFIG_FILENAME: &str = "/tmp/config"; - -fn example(root: impl AsRef, username: &str) -> Result<()> { - let root = root.as_ref(); - let filename = &root.join(CONFIG_FILENAME); - - let config = fs::read(filename).context(OpenConfig { filename })?; - - if username.is_empty() { - MissingUser.fail()?; - } - - fs::write(filename, config).context(SaveConfig)?; - - Ok(()) -} - -#[test] -fn implements_error() { - fn check() {} - check::(); - example("/some/directory/that/does/not/exist", "").unwrap_err(); -} diff --git a/snafu-derive/src/lib.rs b/snafu-derive/src/lib.rs index 6d7845cb..359d749f 100644 --- a/snafu-derive/src/lib.rs +++ b/snafu-derive/src/lib.rs @@ -11,14 +11,7 @@ use syn::parse::{Error as SynError, Result as SynResult}; /// See the crate-level documentation for SNAFU which contains tested /// examples of this macro. -#[cfg_attr( - not(feature = "unstable_display_attribute"), - proc_macro_derive(Snafu, attributes(snafu_visibility, snafu_display)) -)] -#[cfg_attr( - feature = "unstable_display_attribute", - proc_macro_derive(Snafu, attributes(snafu_visibility, snafu::display, snafu_display)) -)] +#[proc_macro_derive(Snafu, attributes(snafu_visibility, snafu_display))] pub fn snafu_derive(input: TokenStream) -> TokenStream { let ast = syn::parse(input).expect("Could not parse type to derive Error for"); @@ -144,18 +137,6 @@ fn parse_snafu_information(ty: syn::DeriveInput) -> SynResult { }) } -fn is_snafu_display(p: &syn::Path) -> bool { - is_path(p, &["snafu", "display"]) -} - -fn is_path(p: &syn::Path, parts: &[&str]) -> bool { - p.segments - .iter() - .zip(parts) - .map(|(a, b)| a.ident == b) - .all(|b| b) -} - fn parse_snafu_visibility(attrs: &[syn::Attribute]) -> SynResult>> { use syn::spanned::Spanned; use syn::Meta; @@ -206,9 +187,7 @@ fn parse_snafu_display(attrs: &[syn::Attribute]) -> SynResult meta, Err(e) => return Some(Err(e)), @@ -231,24 +210,6 @@ fn parse_snafu_display(attrs: &[syn::Attribute]) -> SynResult SynResult { - use syn::spanned::Spanned; - use syn::Expr; - - let expr: Expr = syn::parse2(attr.tts.clone())?; - let expr: Box = match expr { - Expr::Tuple(expr_tuple) => Box::new(expr_tuple.elems), - Expr::Paren(expr_paren) => Box::new(expr_paren.expr), - _ => { - return Err(SynError::new( - expr.span(), - "A parenthesized format string with optional values is expected", - )); - } - }; - Ok(DisplayFormat::Direct(expr)) -} - fn parse_snafu_display_nested(meta: syn::MetaList) -> SynResult { use syn::spanned::Spanned; use syn::{Expr, Lit, NestedMeta}; diff --git a/src/lib.rs b/src/lib.rs index e237cc4d..b3011591 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -146,10 +146,6 @@ //! you can specify how the `Display` trait will be implemented for //! each variant: //! -//! - `#[snafu::display("a format string with arguments: {}", info)]` -//! -//! No special escaping is needed; this looks just like the arguments to a call to `println!`. -//! //! - `#[snafu_display("a format string with arguments: {}", "info")]` //! //! Every argument is quoted as a string literal separately. @@ -215,10 +211,6 @@ //! - Adds support for re-exporting the `Snafu` macro directly from //! the `snafu` crate. //! -//! ### `unstable_display_attribute` - supports Rust Nightly -//! -//! - Adds support for the `snafu::display` attribute. -//! //! ## Other feature flags //! //! ### `backtraces`