@@ -16,15 +16,12 @@ pub mod quote;
16
16
pub mod eager;
17
17
pub mod mod_path;
18
18
19
- use base_db:: ProcMacroKind ;
20
- use either:: Either ;
21
-
22
19
pub use mbe:: { ExpandError , ExpandResult , Origin } ;
23
- use mod_path:: ModPath ;
24
20
25
21
use std:: { hash:: Hash , iter, sync:: Arc } ;
26
22
27
- use base_db:: { impl_intern_key, salsa, CrateId , FileId , FileRange } ;
23
+ use base_db:: { impl_intern_key, salsa, CrateId , FileId , FileRange , ProcMacroKind } ;
24
+ use either:: Either ;
28
25
use syntax:: {
29
26
algo:: { self , skip_trivia_token} ,
30
27
ast:: { self , AstNode , HasDocComments } ,
@@ -37,6 +34,7 @@ use crate::{
37
34
builtin_derive_macro:: BuiltinDeriveExpander ,
38
35
builtin_fn_macro:: { BuiltinFnLikeExpander , EagerExpander } ,
39
36
db:: TokenExpander ,
37
+ mod_path:: ModPath ,
40
38
proc_macro:: ProcMacroExpander ,
41
39
} ;
42
40
@@ -61,11 +59,13 @@ enum HirFileIdRepr {
61
59
FileId ( FileId ) ,
62
60
MacroFile ( MacroFile ) ,
63
61
}
62
+
64
63
impl From < FileId > for HirFileId {
65
64
fn from ( id : FileId ) -> Self {
66
65
HirFileId ( HirFileIdRepr :: FileId ( id) )
67
66
}
68
67
}
68
+
69
69
impl From < MacroFile > for HirFileId {
70
70
fn from ( id : MacroFile ) -> Self {
71
71
HirFileId ( HirFileIdRepr :: MacroFile ( id) )
@@ -151,8 +151,8 @@ impl HirFileId {
151
151
HirFileIdRepr :: FileId ( file_id) => file_id,
152
152
HirFileIdRepr :: MacroFile ( macro_file) => {
153
153
let loc: MacroCallLoc = db. lookup_intern_macro_call ( macro_file. macro_call_id ) ;
154
- let file_id = match & loc. eager {
155
- Some ( EagerCallInfo { included_file : Some ( file) , .. } ) => ( * file) . into ( ) ,
154
+ let file_id = match loc. eager {
155
+ Some ( EagerCallInfo { included_file : Some ( file) , .. } ) => file. into ( ) ,
156
156
_ => loc. kind . file_id ( ) ,
157
157
} ;
158
158
file_id. original_file ( db)
@@ -249,10 +249,7 @@ impl HirFileId {
249
249
HirFileIdRepr :: FileId ( _) => false ,
250
250
HirFileIdRepr :: MacroFile ( macro_file) => {
251
251
let loc: MacroCallLoc = db. lookup_intern_macro_call ( macro_file. macro_call_id ) ;
252
- match loc. def . kind {
253
- MacroDefKind :: ProcMacro ( _, ProcMacroKind :: CustomDerive , _) => true ,
254
- _ => false ,
255
- }
252
+ matches ! ( loc. def. kind, MacroDefKind :: ProcMacro ( _, ProcMacroKind :: CustomDerive , _) )
256
253
}
257
254
}
258
255
}
@@ -302,15 +299,15 @@ impl MacroDefId {
302
299
}
303
300
304
301
pub fn ast_id ( & self ) -> Either < AstId < ast:: Macro > , AstId < ast:: Fn > > {
305
- let id = match & self . kind {
306
- MacroDefKind :: ProcMacro ( .., id) => return Either :: Right ( * id) ,
302
+ let id = match self . kind {
303
+ MacroDefKind :: ProcMacro ( .., id) => return Either :: Right ( id) ,
307
304
MacroDefKind :: Declarative ( id)
308
305
| MacroDefKind :: BuiltIn ( _, id)
309
306
| MacroDefKind :: BuiltInAttr ( _, id)
310
307
| MacroDefKind :: BuiltInDerive ( _, id)
311
308
| MacroDefKind :: BuiltInEager ( _, id) => id,
312
309
} ;
313
- Either :: Left ( * id)
310
+ Either :: Left ( id)
314
311
}
315
312
316
313
pub fn is_proc_macro ( & self ) -> bool {
@@ -359,20 +356,15 @@ impl MacroCallKind {
359
356
/// get only the specific derive that is being referred to.
360
357
pub fn original_call_range ( self , db : & dyn db:: AstDatabase ) -> FileRange {
361
358
let mut kind = self ;
362
- loop {
359
+ let file_id = loop {
363
360
match kind. file_id ( ) . 0 {
364
361
HirFileIdRepr :: MacroFile ( file) => {
365
362
kind = db. lookup_intern_macro_call ( file. macro_call_id ) . kind ;
366
363
}
367
- _ => break ,
364
+ HirFileIdRepr :: FileId ( file_id ) => break file_id ,
368
365
}
369
- }
370
-
371
- // `call_id` is now the outermost macro call, so its location is in a real file.
372
- let file_id = match kind. file_id ( ) . 0 {
373
- HirFileIdRepr :: FileId ( it) => it,
374
- HirFileIdRepr :: MacroFile ( _) => unreachable ! ( "encountered unexpected macro file" ) ,
375
366
} ;
367
+
376
368
let range = match kind {
377
369
MacroCallKind :: FnLike { ast_id, .. } => ast_id. to_node ( db) . syntax ( ) . text_range ( ) ,
378
370
MacroCallKind :: Derive { ast_id, derive_attr_index, .. } => {
@@ -574,7 +566,6 @@ impl ExpansionInfo {
574
566
/// `AstId` points to an AST node in any file.
575
567
///
576
568
/// It is stable across reparses, and can be used as salsa key/value.
577
- // FIXME: isn't this just a `Source<FileAstId<N>>` ?
578
569
pub type AstId < N > = InFile < FileAstId < N > > ;
579
570
580
571
impl < N : AstNode > AstId < N > {
@@ -602,7 +593,6 @@ impl<T> InFile<T> {
602
593
InFile { file_id, value }
603
594
}
604
595
605
- // Similarly, naming here is stupid...
606
596
pub fn with_value < U > ( & self , value : U ) -> InFile < U > {
607
597
InFile :: new ( self . file_id , value)
608
598
}
0 commit comments