Skip to content

Commit

Permalink
builder_field_attr, builder_setter_attr: switch to ( ) syntx
Browse files Browse the repository at this point in the history
  • Loading branch information
ijackson committed Mar 15, 2022
1 parent d49e469 commit f207dba
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
4 changes: 1 addition & 3 deletions derive_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,7 @@
//! #[derive(Builder)]
//! #[builder(derive(serde::Serialize))]
//! struct Lorem {
//! #[builder_field_attrs(
//! #[serde(rename="dolor")]
//! )]
//! #[builder_field_attrs(serde(rename="dolor"))]
//! ipsum: String,
//! }
//!
Expand Down
4 changes: 1 addition & 3 deletions derive_builder/tests/compile-fail/builder_field_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ pub struct Lorem {
ok: String,

// This foolish repr() attribute generates an unused attribute warning
#[builder_field_attrs(
#[no_such_attribute]
)]
#[builder_field_attrs(no_such_attribute)]
broken: String,
}

Expand Down
8 changes: 4 additions & 4 deletions derive_builder/tests/compile-fail/builder_field_attrs.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: cannot find attribute `no_such_attribute` in this scope
--> tests/compile-fail/builder_field_attrs.rs:10:11
|
10 | #[no_such_attribute]
| ^^^^^^^^^^^^^^^^^
--> tests/compile-fail/builder_field_attrs.rs:9:27
|
9 | #[builder_field_attrs(no_such_attribute)]
| ^^^^^^^^^^^^^^^^^
4 changes: 1 addition & 3 deletions derive_builder/tests/compile-fail/builder_setter_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ pub struct Lorem {
ok: String,

// This foolish repr() attribute generates an unused attribute warning
#[builder_setter_attrs(
#[must_use]
)]
#[builder_setter_attrs(must_use)]
broken: usize,
}

Expand Down
4 changes: 2 additions & 2 deletions derive_builder/tests/compile-fail/builder_setter_attrs.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: unused return value of `LoremBuilder::broken` that must be used
--> tests/compile-fail/builder_setter_attrs.rs:18:5
--> tests/compile-fail/builder_setter_attrs.rs:16:5
|
18 | LoremBuilder::default().broken(42);
16 | LoremBuilder::default().broken(42);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
Expand Down
17 changes: 13 additions & 4 deletions derive_builder_core/src/macro_options/darling_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::BuildMethod;

use darling::util::{Flag, PathList};
use darling::{self, FromMeta};
use proc_macro2::Span;
use syn::parse::ParseStream;
use proc_macro2::{Span, TokenStream};
use syn::parse::{ParseStream, Parser};
use syn::Meta;
use syn::{self, spanned::Spanned, Attribute, Generics, Ident, Path, Visibility};

Expand Down Expand Up @@ -303,9 +303,18 @@ fn unnest_from_one_attribute(attr: syn::Attribute) -> darling::Result<Vec<Attrib
struct ContainedAttributes(Vec<syn::Attribute>);
impl syn::parse::Parse for ContainedAttributes {
fn parse(input: ParseStream) -> syn::Result<Self> {
// Strip parentheses, and save the span of the parenthesis token
let content;
let _paren_token = parenthesized!(content in input);
let attrs = content.call(syn::Attribute::parse_outer)?;
let paren_token = parenthesized!(content in input);
let wrap_span = paren_token.span;

// Wrap up in #[ ] instead.
let pound = Token![#](wrap_span); // We can't write a literal # inside quote
let content: TokenStream = content.parse()?;
let content = quote_spanned!(wrap_span=> #pound [ #content ]);

let parser = syn::Attribute::parse_outer;
let attrs = parser.parse2(content)?;
Ok(Self(attrs))
}
}
Expand Down

0 comments on commit f207dba

Please sign in to comment.