From 9d7602e22668dae9124e80bd269a5b3afc5f5512 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 4 Nov 2024 23:31:14 -0500 Subject: [PATCH] Remove same_member in favor of MemberUnraw's PartialEq impl --- impl/src/valid.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/impl/src/valid.rs b/impl/src/valid.rs index 3b475af..1ddb19e 100644 --- a/impl/src/valid.rs +++ b/impl/src/valid.rs @@ -1,6 +1,5 @@ use crate::ast::{Enum, Field, Input, Struct, Variant}; use crate::attr::Attrs; -use crate::unraw::MemberUnraw; use quote::ToTokens; use std::collections::BTreeSet as Set; use syn::{Error, GenericArgument, PathArguments, Result, Type}; @@ -173,7 +172,7 @@ fn check_field_attrs(fields: &[Field]) -> Result<()> { has_backtrace |= field.is_backtrace(); } if let (Some(from_field), Some(source_field)) = (from_field, source_field) { - if !same_member(from_field, source_field) { + if from_field.member != source_field.member { return Err(Error::new_spanned( from_field.attrs.from, "#[from] is only supported on the source field, not any other field", @@ -182,7 +181,7 @@ fn check_field_attrs(fields: &[Field]) -> Result<()> { } if let Some(from_field) = from_field { let max_expected_fields = match backtrace_field { - Some(backtrace_field) => 1 + !same_member(from_field, backtrace_field) as usize, + Some(backtrace_field) => 1 + (from_field.member != backtrace_field.member) as usize, None => 1 + has_backtrace as usize, }; if fields.len() > max_expected_fields { @@ -203,14 +202,6 @@ fn check_field_attrs(fields: &[Field]) -> Result<()> { Ok(()) } -fn same_member(one: &Field, two: &Field) -> bool { - match (&one.member, &two.member) { - (MemberUnraw::Named(one), MemberUnraw::Named(two)) => one == two, - (MemberUnraw::Unnamed(one), MemberUnraw::Unnamed(two)) => one.index == two.index, - _ => unreachable!(), - } -} - fn contains_non_static_lifetime(ty: &Type) -> bool { match ty { Type::Path(ty) => {