From b7b636a23f4e56c615b4830f3e44f925d3d74b44 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 11 Mar 2023 11:17:35 -0800 Subject: [PATCH] Treat field-level borrow attr as duplicate of variant-level borrow attr --- serde_derive/src/internals/attr.rs | 14 +++++++------- .../tests/ui/borrow/duplicate_variant.stderr | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/serde_derive/src/internals/attr.rs b/serde_derive/src/internals/attr.rs index 3db2d2b8f..9e820fb53 100644 --- a/serde_derive/src/internals/attr.rs +++ b/serde_derive/src/internals/attr.rs @@ -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 => { diff --git a/test_suite/tests/ui/borrow/duplicate_variant.stderr b/test_suite/tests/ui/borrow/duplicate_variant.stderr index eaeaf97eb..cd0746c2c 100644 --- a/test_suite/tests/ui/borrow/duplicate_variant.stderr +++ b/test_suite/tests/ui/borrow/duplicate_variant.stderr @@ -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>), + | ^^^^^^