Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ nightly_test_task:
- cargo +nightly update -p backtrace-sys --precise 0.1.20
- cargo +nightly update -p libc --precise 0.2.7
- cargo +nightly test
compatibility_test_script:
- cd compatibility-tests/nightly/
- rustc --version
- cargo test
before_cache_script: rm -rf $CARGO_HOME/registry/index

v1_30_test_task:
Expand Down
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
2 changes: 1 addition & 1 deletion compatibility-tests/compile-fail/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2018"

[dependencies]
compiletest_rs = { version = "0.3.18", features = ["stable", "tmp"] }
snafu = { path = "../..", features = ["unstable_display_attribute"] }
snafu = { path = "../.." }
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.

1 change: 0 additions & 1 deletion snafu-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ license = "MIT OR Apache-2.0"
[features]
backtraces = []
rust_1_30 = []
unstable_display_attribute = []

[lib]
proc-macro = true
Expand Down
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