@@ -726,8 +726,8 @@ pub struct SyntaxExtension {
726
726
/// Built-in macros have a couple of special properties like availability
727
727
/// in `#[no_implicit_prelude]` modules, so we have to keep this flag.
728
728
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 > ,
731
731
}
732
732
733
733
impl SyntaxExtension {
@@ -756,7 +756,7 @@ impl SyntaxExtension {
756
756
helper_attrs : Vec :: new ( ) ,
757
757
edition,
758
758
is_builtin : false ,
759
- is_derive_copy : false ,
759
+ derive : None ,
760
760
kind,
761
761
}
762
762
}
@@ -789,6 +789,7 @@ impl SyntaxExtension {
789
789
. span_diagnostic
790
790
. span_err ( span, "macros cannot have const stability attributes" ) ;
791
791
}
792
+ let derive = if is_builtin { BuiltinDerive :: from_name ( name) } else { None } ;
792
793
793
794
SyntaxExtension {
794
795
kind,
@@ -801,7 +802,7 @@ impl SyntaxExtension {
801
802
helper_attrs,
802
803
edition,
803
804
is_builtin,
804
- is_derive_copy : is_builtin && name == sym :: Copy ,
805
+ derive ,
805
806
}
806
807
}
807
808
@@ -855,6 +856,25 @@ impl SyntaxExtension {
855
856
}
856
857
}
857
858
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
+
858
878
/// Result of resolving a macro invocation.
859
879
pub enum InvocationRes {
860
880
Single ( Lrc < SyntaxExtension > ) ,
@@ -894,8 +914,8 @@ pub trait ResolverExpand {
894
914
fn lint_node_id ( & mut self , expn_id : ExpnId ) -> NodeId ;
895
915
896
916
// 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 ;
899
919
/// Path resolution logic for `#[cfg_accessible(path)]`.
900
920
fn cfg_accessible ( & mut self , expn_id : ExpnId , path : & ast:: Path ) -> Result < bool , Indeterminate > ;
901
921
}
0 commit comments