@@ -38,9 +38,10 @@ pub mod partial_ord;
38
38
39
39
pub mod generic;
40
40
41
- pub ( crate ) struct BuiltinDerive (
42
- pub ( crate ) fn ( & mut ExtCtxt < ' _ > , Span , & MetaItem , & Annotatable , & mut dyn FnMut ( Annotatable ) ) ,
43
- ) ;
41
+ pub ( crate ) type BuiltinDeriveFn =
42
+ fn ( & mut ExtCtxt < ' _ > , Span , & MetaItem , & Annotatable , & mut dyn FnMut ( Annotatable ) , bool ) ;
43
+
44
+ pub ( crate ) struct BuiltinDerive ( pub ( crate ) BuiltinDeriveFn ) ;
44
45
45
46
impl MultiItemModifier for BuiltinDerive {
46
47
fn expand (
@@ -49,6 +50,7 @@ impl MultiItemModifier for BuiltinDerive {
49
50
span : Span ,
50
51
meta_item : & MetaItem ,
51
52
item : Annotatable ,
53
+ is_derive_const : bool ,
52
54
) -> ExpandResult < Vec < Annotatable > , Annotatable > {
53
55
// FIXME: Built-in derives often forget to give spans contexts,
54
56
// so we are doing it here in a centralized way.
@@ -57,21 +59,28 @@ impl MultiItemModifier for BuiltinDerive {
57
59
match item {
58
60
Annotatable :: Stmt ( stmt) => {
59
61
if let ast:: StmtKind :: Item ( item) = stmt. into_inner ( ) . kind {
60
- ( self . 0 ) ( ecx, span, meta_item, & Annotatable :: Item ( item) , & mut |a| {
61
- // Cannot use 'ecx.stmt_item' here, because we need to pass 'ecx'
62
- // to the function
63
- items. push ( Annotatable :: Stmt ( P ( ast:: Stmt {
64
- id : ast:: DUMMY_NODE_ID ,
65
- kind : ast:: StmtKind :: Item ( a. expect_item ( ) ) ,
66
- span,
67
- } ) ) ) ;
68
- } ) ;
62
+ ( self . 0 ) (
63
+ ecx,
64
+ span,
65
+ meta_item,
66
+ & Annotatable :: Item ( item) ,
67
+ & mut |a| {
68
+ // Cannot use 'ecx.stmt_item' here, because we need to pass 'ecx'
69
+ // to the function
70
+ items. push ( Annotatable :: Stmt ( P ( ast:: Stmt {
71
+ id : ast:: DUMMY_NODE_ID ,
72
+ kind : ast:: StmtKind :: Item ( a. expect_item ( ) ) ,
73
+ span,
74
+ } ) ) ) ;
75
+ } ,
76
+ is_derive_const,
77
+ ) ;
69
78
} else {
70
79
unreachable ! ( "should have already errored on non-item statement" )
71
80
}
72
81
}
73
82
_ => {
74
- ( self . 0 ) ( ecx, span, meta_item, & item, & mut |a| items. push ( a) ) ;
83
+ ( self . 0 ) ( ecx, span, meta_item, & item, & mut |a| items. push ( a) , is_derive_const ) ;
75
84
}
76
85
}
77
86
ExpandResult :: Ready ( items)
0 commit comments