@@ -726,8 +726,8 @@ pub struct SyntaxExtension {
726726 /// Built-in macros have a couple of special properties like availability
727727 /// in `#[no_implicit_prelude]` modules, so we have to keep this flag.
728728 pub is_builtin : bool ,
729- /// We have to identify macros providing a `Copy` impl early for compatibility reasons.
730- pub is_derive_copy : bool ,
729+ /// Keeps track of which builtin derives (if any) this is
730+ pub derive : Option < BuiltinDerive > ,
731731}
732732
733733impl SyntaxExtension {
@@ -756,7 +756,7 @@ impl SyntaxExtension {
756756 helper_attrs : Vec :: new ( ) ,
757757 edition,
758758 is_builtin : false ,
759- is_derive_copy : false ,
759+ derive : None ,
760760 kind,
761761 }
762762 }
@@ -789,6 +789,7 @@ impl SyntaxExtension {
789789 . span_diagnostic
790790 . span_err ( span, "macros cannot have const stability attributes" ) ;
791791 }
792+ let derive = if is_builtin { BuiltinDerive :: from_name ( name) } else { None } ;
792793
793794 SyntaxExtension {
794795 kind,
@@ -801,7 +802,7 @@ impl SyntaxExtension {
801802 helper_attrs,
802803 edition,
803804 is_builtin,
804- is_derive_copy : is_builtin && name == sym :: Copy ,
805+ derive ,
805806 }
806807 }
807808
@@ -855,6 +856,25 @@ impl SyntaxExtension {
855856 }
856857}
857858
859+ /// Built-in derives
860+ /// Only derives that are being used for special casing expansion are represented here
861+ #[ derive( Debug , Copy , Clone , Hash , Eq , PartialEq ) ]
862+ pub enum BuiltinDerive {
863+ Copy ,
864+ PartialEq ,
865+ }
866+
867+ impl BuiltinDerive {
868+ /// Possibly turn a symbol into a built-in derive
869+ fn from_name ( name : Symbol ) -> Option < Self > {
870+ match name {
871+ sym:: Copy => Some ( Self :: Copy ) ,
872+ sym:: PartialEq => Some ( Self :: PartialEq ) ,
873+ _ => None ,
874+ }
875+ }
876+ }
877+
858878/// Result of resolving a macro invocation.
859879pub enum InvocationRes {
860880 Single ( Lrc < SyntaxExtension > ) ,
@@ -894,8 +914,8 @@ pub trait ResolverExpand {
894914 fn lint_node_id ( & mut self , expn_id : ExpnId ) -> NodeId ;
895915
896916 // Resolver interfaces for specific built-in macros.
897- /// Does `#[derive(...)]` attribute with the given `ExpnId` have built-in `Copy` inside it?
898- fn has_derive_copy ( & self , expn_id : ExpnId ) -> bool ;
917+ /// Does `#[derive(...)]` attribute with the given `ExpnId` have the given built-in derive inside it?
918+ fn has_derive ( & self , expn_id : ExpnId , derive : BuiltinDerive ) -> bool ;
899919 /// Path resolution logic for `#[cfg_accessible(path)]`.
900920 fn cfg_accessible ( & mut self , expn_id : ExpnId , path : & ast:: Path ) -> Result < bool , Indeterminate > ;
901921}
0 commit comments