Skip to content

Commit

Permalink
Merge pull request #2398 from dtolnay/borrow
Browse files Browse the repository at this point in the history
Treat field-level borrow attr as duplicate of variant-level borrow attr
  • Loading branch information
dtolnay authored Mar 11, 2023
2 parents 183b917 + b7b636a commit 696f6f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions serde_derive/src/internals/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,13 +1114,13 @@ impl Field {
.and_then(|variant| variant.borrow.as_ref())
.map(|borrow| Meta(borrow.clone()));

for meta_item in field
.attrs
.iter()
.flat_map(|attr| get_serde_meta_items(cx, attr))
.flatten()
.chain(variant_borrow)
{
for meta_item in variant_borrow.into_iter().chain(
field
.attrs
.iter()
.flat_map(|attr| get_serde_meta_items(cx, attr))
.flatten(),
) {
match &meta_item {
// Parse `#[serde(rename = "foo")]`
Meta(NameValue(m)) if m.path == RENAME => {
Expand Down
6 changes: 3 additions & 3 deletions test_suite/tests/ui/borrow/duplicate_variant.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: duplicate serde attribute `borrow`
--> tests/ui/borrow/duplicate_variant.rs:8:13
--> tests/ui/borrow/duplicate_variant.rs:9:15
|
8 | #[serde(borrow)]
| ^^^^^^
9 | S(#[serde(borrow)] Str<'a>),
| ^^^^^^

0 comments on commit 696f6f5

Please sign in to comment.