@@ -7,20 +7,23 @@ use crate::{db::ExpandDatabase, tt, ExpandError, ExpandResult};
77
88#[ derive( Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
99pub struct ProcMacroExpander {
10- proc_macro_id : Option < ProcMacroId > ,
10+ proc_macro_id : ProcMacroId ,
1111}
1212
13+ const DUMMY_ID : u32 = !0 ;
14+
1315impl ProcMacroExpander {
1416 pub fn new ( proc_macro_id : ProcMacroId ) -> Self {
15- Self { proc_macro_id : Some ( proc_macro_id) }
17+ assert_ne ! ( proc_macro_id. 0 , DUMMY_ID ) ;
18+ Self { proc_macro_id }
1619 }
1720
1821 pub fn dummy ( ) -> Self {
19- Self { proc_macro_id : None }
22+ Self { proc_macro_id : ProcMacroId ( DUMMY_ID ) }
2023 }
2124
2225 pub fn is_dummy ( & self ) -> bool {
23- self . proc_macro_id . is_none ( )
26+ self . proc_macro_id . 0 == DUMMY_ID
2427 }
2528
2629 pub fn expand (
@@ -32,7 +35,10 @@ impl ProcMacroExpander {
3235 attr_arg : Option < & tt:: Subtree > ,
3336 ) -> ExpandResult < tt:: Subtree > {
3437 match self . proc_macro_id {
35- Some ( id) => {
38+ ProcMacroId ( DUMMY_ID ) => {
39+ ExpandResult :: new ( tt:: Subtree :: empty ( ) , ExpandError :: UnresolvedProcMacro ( def_crate) )
40+ }
41+ ProcMacroId ( id) => {
3642 let proc_macros = db. proc_macros ( ) ;
3743 let proc_macros = match proc_macros. get ( & def_crate) {
3844 Some ( Ok ( proc_macros) ) => proc_macros,
@@ -44,13 +50,13 @@ impl ProcMacroExpander {
4450 ) ;
4551 }
4652 } ;
47- let proc_macro = match proc_macros. get ( id. 0 as usize ) {
53+ let proc_macro = match proc_macros. get ( id as usize ) {
4854 Some ( proc_macro) => proc_macro,
4955 None => {
5056 never ! (
5157 "Proc macro index out of bounds: the length is {} but the index is {}" ,
5258 proc_macros. len( ) ,
53- id. 0
59+ id
5460 ) ;
5561 return ExpandResult :: new (
5662 tt:: Subtree :: empty ( ) ,
@@ -81,9 +87,6 @@ impl ProcMacroExpander {
8187 } ,
8288 }
8389 }
84- None => {
85- ExpandResult :: new ( tt:: Subtree :: empty ( ) , ExpandError :: UnresolvedProcMacro ( def_crate) )
86- }
8790 }
8891 }
8992}
0 commit comments