Skip to content

Commit 126ec98

Browse files
committed
Remove the unstable snafu::display attribute
Turns out, this was never supposed to be supported in the first place. - rust-lang/rust#58899
1 parent 0229ec4 commit 126ec98

File tree

9 files changed

+2
-113
lines changed

9 files changed

+2
-113
lines changed

Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@ backtraces = ["snafu-derive/backtraces", "backtrace"]
2828
# New methods on `Error`; re-export of proc-macro
2929
rust_1_30 = ["snafu-derive/rust_1_30"]
3030

31-
# The `snafu::display` attribute
32-
unstable_display_attribute = ["snafu-derive/unstable_display_attribute"]
33-
3431
[workspace]
3532
# The compatibility tests each set feature flags for the library and
3633
# cannot be in the same crate graph.
3734
exclude = [
3835
"compatibility-tests/compile-fail",
39-
"compatibility-tests/nightly",
4036
"compatibility-tests/v1_30",
4137
"compatibility-tests/v1_18",
4238
"compatibility-tests/without-backtrace",

compatibility-tests/compile-fail/tests/compile-fail/error-reporting.rs

-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ enum TupleEnumVariant {
2323
//~^ ERROR Only struct-like and unit enum variants are supported
2424
}
2525

26-
#[derive(Snafu)]
27-
enum SnafuDisplayWrongKindOfExpression {
28-
#[snafu::display {}]
29-
//~^ ERROR A parenthesized format string with optional values is expected
30-
//~^^ expected one of `(` or `=`
31-
Alpha(i32),
32-
}
33-
3426
#[derive(Snafu)]
3527
enum OldSnafuDisplayWithoutArgument {
3628
#[snafu_display]

compatibility-tests/nightly/.gitignore

-3
This file was deleted.

compatibility-tests/nightly/Cargo.toml

-8
This file was deleted.

compatibility-tests/nightly/rust-toolchain

-1
This file was deleted.

compatibility-tests/nightly/src/lib.rs

Whitespace-only changes.

compatibility-tests/nightly/tests/unstable_attributes.rs

-40
This file was deleted.

snafu-derive/src/lib.rs

+2-41
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ use syn::parse::{Error as SynError, Result as SynResult};
1111
/// See the crate-level documentation for SNAFU which contains tested
1212
/// examples of this macro.
1313
14-
#[cfg_attr(
15-
not(feature = "unstable_display_attribute"),
16-
proc_macro_derive(Snafu, attributes(snafu_visibility, snafu_display))
17-
)]
18-
#[cfg_attr(
19-
feature = "unstable_display_attribute",
20-
proc_macro_derive(Snafu, attributes(snafu_visibility, snafu::display, snafu_display))
21-
)]
14+
#[proc_macro_derive(Snafu, attributes(snafu_visibility, snafu_display))]
2215
pub fn snafu_derive(input: TokenStream) -> TokenStream {
2316
let ast = syn::parse(input).expect("Could not parse type to derive Error for");
2417

@@ -144,18 +137,6 @@ fn parse_snafu_information(ty: syn::DeriveInput) -> SynResult<EnumInfo> {
144137
})
145138
}
146139

147-
fn is_snafu_display(p: &syn::Path) -> bool {
148-
is_path(p, &["snafu", "display"])
149-
}
150-
151-
fn is_path(p: &syn::Path, parts: &[&str]) -> bool {
152-
p.segments
153-
.iter()
154-
.zip(parts)
155-
.map(|(a, b)| a.ident == b)
156-
.all(|b| b)
157-
}
158-
159140
fn parse_snafu_visibility(attrs: &[syn::Attribute]) -> SynResult<Option<Box<quote::ToTokens>>> {
160141
use syn::spanned::Spanned;
161142
use syn::Meta;
@@ -206,9 +187,7 @@ fn parse_snafu_display(attrs: &[syn::Attribute]) -> SynResult<Option<DisplayForm
206187
attrs
207188
.into_iter()
208189
.flat_map(|attr| {
209-
if is_snafu_display(&attr.path) {
210-
Some(parse_snafu_display_beautiful(attr))
211-
} else if attr.path.is_ident("snafu_display") {
190+
if attr.path.is_ident("snafu_display") {
212191
let meta = match attr.parse_meta() {
213192
Ok(meta) => meta,
214193
Err(e) => return Some(Err(e)),
@@ -231,24 +210,6 @@ fn parse_snafu_display(attrs: &[syn::Attribute]) -> SynResult<Option<DisplayForm
231210
.my_transpose()
232211
}
233212

234-
fn parse_snafu_display_beautiful(attr: &syn::Attribute) -> SynResult<DisplayFormat> {
235-
use syn::spanned::Spanned;
236-
use syn::Expr;
237-
238-
let expr: Expr = syn::parse2(attr.tts.clone())?;
239-
let expr: Box<quote::ToTokens> = match expr {
240-
Expr::Tuple(expr_tuple) => Box::new(expr_tuple.elems),
241-
Expr::Paren(expr_paren) => Box::new(expr_paren.expr),
242-
_ => {
243-
return Err(SynError::new(
244-
expr.span(),
245-
"A parenthesized format string with optional values is expected",
246-
));
247-
}
248-
};
249-
Ok(DisplayFormat::Direct(expr))
250-
}
251-
252213
fn parse_snafu_display_nested(meta: syn::MetaList) -> SynResult<DisplayFormat> {
253214
use syn::spanned::Spanned;
254215
use syn::{Expr, Lit, NestedMeta};

src/lib.rs

-8
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@
146146
//! you can specify how the `Display` trait will be implemented for
147147
//! each variant:
148148
//!
149-
//! - `#[snafu::display("a format string with arguments: {}", info)]`
150-
//!
151-
//! No special escaping is needed; this looks just like the arguments to a call to `println!`.
152-
//!
153149
//! - `#[snafu_display("a format string with arguments: {}", "info")]`
154150
//!
155151
//! Every argument is quoted as a string literal separately.
@@ -215,10 +211,6 @@
215211
//! - Adds support for re-exporting the `Snafu` macro directly from
216212
//! the `snafu` crate.
217213
//!
218-
//! ### `unstable_display_attribute` - supports Rust Nightly
219-
//!
220-
//! - Adds support for the `snafu::display` attribute.
221-
//!
222214
//! ## Other feature flags
223215
//!
224216
//! ### `backtraces`

0 commit comments

Comments
 (0)