Merge pull request #2398 from dtolnay/borrow

Treat field-level borrow attr as duplicate of variant-level borrow attr
This commit is contained in:
David Tolnay 2023-03-11 11:24:50 -08:00 committed by GitHub
commit 696f6f56db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

@ -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 => {

View File

@ -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>),
| ^^^^^^