4141//! # extern crate derive_where as derive_where_;
4242//! # use std::marker::PhantomData;
4343//! # use derive_where::derive_where;
44- //! #[derive_where(crate = " derive_where_" )]
44+ //! #[derive_where(crate = derive_where_)]
4545//! #[derive_where(Clone, Debug)]
4646//! struct Example<T>(PhantomData<T>);
4747//! ```
237237//! # use std::marker::PhantomData;
238238//! # use derive_where::derive_where;
239239//! # use zeroize_::Zeroize;
240- //! #[derive_where(Zeroize(crate = " zeroize_" ))]
240+ //! #[derive_where(Zeroize(crate = zeroize_))]
241241//! struct Example(#[derive_where(Zeroize(fqs))] i32);
242242//!
243243//! impl Example {
275275//! # {
276276//! # use std::marker::PhantomData;
277277//! # use derive_where::derive_where;
278- //! #[derive_where(ZeroizeOnDrop(crate = " zeroize_" ))]
278+ //! #[derive_where(ZeroizeOnDrop(crate = zeroize_))]
279279//! struct Example(i32);
280280//!
281281//! assert!(core::mem::needs_drop::<Example>());
@@ -394,8 +394,8 @@ use proc_macro2::TokenStream;
394394use quote:: { quote, quote_spanned, ToTokens } ;
395395use syn:: {
396396 punctuated:: Punctuated , spanned:: Spanned , Attribute , DataEnum , DataStruct , DataUnion ,
397- DeriveInput , Expr , ExprLit , Fields , FieldsNamed , FieldsUnnamed , Generics , Lit , Meta , Path ,
398- Token , Variant ,
397+ DeriveInput , Expr , ExprLit , ExprPath , Fields , FieldsNamed , FieldsUnnamed , Generics , Lit , Meta ,
398+ Path , Token , Variant ,
399399} ;
400400
401401#[ cfg( feature = "zeroize" ) ]
@@ -421,13 +421,12 @@ const DERIVE_WHERE_FORWARD: &str = "DeriveWhere";
421421const DERIVE_WHERE_VISITED : & str = "derive_where_visited" ;
422422
423423/// Item-level options:
424- /// - `#[derive_where(crate = "path")]`: Specify path to the `derive_where`
425- /// crate.
424+ /// - `#[derive_where(crate = path)]`: Specify path to the `derive_where` crate.
426425/// - `#[derive_where(Clone, ..; T, ..)]`: Specify traits to implement and
427426/// optionally bounds.
428- /// - `#[derive_where(Zeroize(crate = " path" ))]`: Specify path to [`Zeroize`]
427+ /// - `#[derive_where(Zeroize(crate = path))]`: Specify path to [`Zeroize`]
429428/// trait.
430- /// - `#[derive_where(ZeroizeOnDrop(crate = " path" ))]`: Specify path to
429+ /// - `#[derive_where(ZeroizeOnDrop(crate = path))]`: Specify path to
431430/// [`ZeroizeOnDrop`] trait.
432431/// - `#[derive_where(skip_inner(EqHashOrd, ..))]`: Skip all fields in the item.
433432/// Optionally specify trait groups to constrain skipping fields. Only works
@@ -492,36 +491,35 @@ fn derive_where_internal(mut item: DeriveInput) -> Result<TokenStream, syn::Erro
492491
493492 if meta. path ( ) . is_ident ( "crate" ) {
494493 if let Meta :: NameValue ( name_value) = meta {
495- if let Expr :: Lit ( ExprLit {
496- lit : Lit :: Str ( lit_str) ,
497- ..
498- } ) = & name_value. value
499- {
500- match lit_str. parse :: < Path > ( ) {
501- Ok ( path) => {
502- if path == util:: path_from_strs ( & [ DERIVE_WHERE ] ) {
503- return Err ( Error :: path_unnecessary (
504- path. span ( ) ,
505- & format ! ( "::{}" , DERIVE_WHERE ) ,
506- ) ) ;
507- }
508-
509- match crate_ {
510- Some ( _) => {
511- return Err ( Error :: option_duplicate (
512- name_value. span ( ) ,
513- "crate" ,
514- ) )
515- }
516- None => crate_ = Some ( path) ,
517- }
518- }
494+ let path = match & name_value. value {
495+ Expr :: Lit ( ExprLit {
496+ lit : Lit :: Str ( lit_str) ,
497+ ..
498+ } ) => match lit_str. parse :: < Path > ( ) {
499+ Ok ( path) => path,
519500 Err ( error) => {
520501 return Err ( Error :: path ( lit_str. span ( ) , error) )
521502 }
503+ } ,
504+ Expr :: Path ( ExprPath { path, .. } ) => path. clone ( ) ,
505+ _ => return Err ( Error :: option_syntax ( name_value. value . span ( ) ) ) ,
506+ } ;
507+
508+ if path == util:: path_from_strs ( & [ DERIVE_WHERE ] ) {
509+ return Err ( Error :: path_unnecessary (
510+ path. span ( ) ,
511+ & format ! ( "::{}" , DERIVE_WHERE ) ,
512+ ) ) ;
513+ }
514+
515+ match crate_ {
516+ Some ( _) => {
517+ return Err ( Error :: option_duplicate (
518+ name_value. span ( ) ,
519+ "crate" ,
520+ ) )
522521 }
523- } else {
524- return Err ( Error :: option_syntax ( name_value. value . span ( ) ) ) ;
522+ None => crate_ = Some ( path) ,
525523 }
526524 } else {
527525 return Err ( Error :: option_syntax ( meta. span ( ) ) ) ;
0 commit comments