Skip to content

Commit

Permalink
Remove the unstable snafu::display attribute
Browse files Browse the repository at this point in the history
Turns out, this was never supposed to be supported in the first place.

- rust-lang/rust#58899
  • Loading branch information
shepmaster committed Mar 23, 2019
1 parent 0229ec4 commit 126ec98
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 113 deletions.
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 0 additions & 3 deletions compatibility-tests/nightly/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions compatibility-tests/nightly/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion compatibility-tests/nightly/rust-toolchain

This file was deleted.

Empty file.
40 changes: 0 additions & 40 deletions compatibility-tests/nightly/tests/unstable_attributes.rs

This file was deleted.

43 changes: 2 additions & 41 deletions snafu-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -144,18 +137,6 @@ fn parse_snafu_information(ty: syn::DeriveInput) -> SynResult<EnumInfo> {
})
}

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<Option<Box<quote::ToTokens>>> {
use syn::spanned::Spanned;
use syn::Meta;
Expand Down Expand Up @@ -206,9 +187,7 @@ fn parse_snafu_display(attrs: &[syn::Attribute]) -> SynResult<Option<DisplayForm
attrs
.into_iter()
.flat_map(|attr| {
if is_snafu_display(&attr.path) {
Some(parse_snafu_display_beautiful(attr))
} else if attr.path.is_ident("snafu_display") {
if attr.path.is_ident("snafu_display") {
let meta = match attr.parse_meta() {
Ok(meta) => meta,
Err(e) => return Some(Err(e)),
Expand All @@ -231,24 +210,6 @@ fn parse_snafu_display(attrs: &[syn::Attribute]) -> SynResult<Option<DisplayForm
.my_transpose()
}

fn parse_snafu_display_beautiful(attr: &syn::Attribute) -> SynResult<DisplayFormat> {
use syn::spanned::Spanned;
use syn::Expr;

let expr: Expr = syn::parse2(attr.tts.clone())?;
let expr: Box<quote::ToTokens> = 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<DisplayFormat> {
use syn::spanned::Spanned;
use syn::{Expr, Lit, NestedMeta};
Expand Down
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit 126ec98

Please sign in to comment.