@@ -8,7 +8,6 @@ use base_db::{AnchoredPath, Edition, FileId};
8
8
use cfg:: CfgExpr ;
9
9
use either:: Either ;
10
10
use mbe:: { parse_exprs_with_sep, parse_to_token_tree, ExpandResult } ;
11
- use parser:: FragmentKind ;
12
11
use syntax:: ast:: { self , AstToken } ;
13
12
14
13
macro_rules! register_builtin {
@@ -47,7 +46,7 @@ macro_rules! register_builtin {
47
46
let expander = match * self {
48
47
$( EagerExpander :: $e_kind => $e_expand, ) *
49
48
} ;
50
- expander( db, arg_id, tt)
49
+ expander( db, arg_id, tt)
51
50
}
52
51
}
53
52
@@ -64,14 +63,13 @@ macro_rules! register_builtin {
64
63
#[ derive( Debug ) ]
65
64
pub struct ExpandedEager {
66
65
pub ( crate ) subtree : tt:: Subtree ,
67
- pub ( crate ) fragment : FragmentKind ,
68
66
/// The included file ID of the include macro.
69
67
pub ( crate ) included_file : Option < FileId > ,
70
68
}
71
69
72
70
impl ExpandedEager {
73
- fn new ( subtree : tt:: Subtree , fragment : FragmentKind ) -> Self {
74
- ExpandedEager { subtree, fragment , included_file : None }
71
+ fn new ( subtree : tt:: Subtree ) -> Self {
72
+ ExpandedEager { subtree, included_file : None }
75
73
}
76
74
}
77
75
@@ -340,7 +338,7 @@ fn compile_error_expand(
340
338
_ => mbe:: ExpandError :: BindingError ( "`compile_error!` argument must be a string" . into ( ) ) ,
341
339
} ;
342
340
343
- ExpandResult { value : Some ( ExpandedEager :: new ( quote ! { } , FragmentKind :: Items ) ) , err : Some ( err) }
341
+ ExpandResult { value : Some ( ExpandedEager :: new ( quote ! { } ) ) , err : Some ( err) }
344
342
}
345
343
346
344
fn concat_expand (
@@ -371,7 +369,7 @@ fn concat_expand(
371
369
}
372
370
}
373
371
}
374
- ExpandResult { value : Some ( ExpandedEager :: new ( quote ! ( #text) , FragmentKind :: Expr ) ) , err }
372
+ ExpandResult { value : Some ( ExpandedEager :: new ( quote ! ( #text) ) ) , err }
375
373
}
376
374
377
375
fn concat_idents_expand (
@@ -393,7 +391,7 @@ fn concat_idents_expand(
393
391
}
394
392
}
395
393
let ident = tt:: Ident { text : ident. into ( ) , id : tt:: TokenId :: unspecified ( ) } ;
396
- ExpandResult { value : Some ( ExpandedEager :: new ( quote ! ( #ident) , FragmentKind :: Expr ) ) , err }
394
+ ExpandResult { value : Some ( ExpandedEager :: new ( quote ! ( #ident) ) ) , err }
397
395
}
398
396
399
397
fn relative_file (
@@ -442,14 +440,7 @@ fn include_expand(
442
440
443
441
match res {
444
442
Ok ( ( subtree, file_id) ) => {
445
- // FIXME:
446
- // Handle include as expression
447
-
448
- ExpandResult :: ok ( Some ( ExpandedEager {
449
- subtree,
450
- fragment : FragmentKind :: Items ,
451
- included_file : Some ( file_id) ,
452
- } ) )
443
+ ExpandResult :: ok ( Some ( ExpandedEager { subtree, included_file : Some ( file_id) } ) )
453
444
}
454
445
Err ( e) => ExpandResult :: only_err ( e) ,
455
446
}
@@ -472,7 +463,7 @@ fn include_bytes_expand(
472
463
id: tt:: TokenId :: unspecified( ) ,
473
464
} ) ) ] ,
474
465
} ;
475
- ExpandResult :: ok ( Some ( ExpandedEager :: new ( res, FragmentKind :: Expr ) ) )
466
+ ExpandResult :: ok ( Some ( ExpandedEager :: new ( res) ) )
476
467
}
477
468
478
469
fn include_str_expand (
@@ -492,14 +483,14 @@ fn include_str_expand(
492
483
let file_id = match relative_file ( db, arg_id. into ( ) , & path, true ) {
493
484
Ok ( file_id) => file_id,
494
485
Err ( _) => {
495
- return ExpandResult :: ok ( Some ( ExpandedEager :: new ( quote ! ( "" ) , FragmentKind :: Expr ) ) ) ;
486
+ return ExpandResult :: ok ( Some ( ExpandedEager :: new ( quote ! ( "" ) ) ) ) ;
496
487
}
497
488
} ;
498
489
499
490
let text = db. file_text ( file_id) ;
500
491
let text = & * text;
501
492
502
- ExpandResult :: ok ( Some ( ExpandedEager :: new ( quote ! ( #text) , FragmentKind :: Expr ) ) )
493
+ ExpandResult :: ok ( Some ( ExpandedEager :: new ( quote ! ( #text) ) ) )
503
494
}
504
495
505
496
fn get_env_inner ( db : & dyn AstDatabase , arg_id : MacroCallId , key : & str ) -> Option < String > {
@@ -535,7 +526,7 @@ fn env_expand(
535
526
} ) ;
536
527
let expanded = quote ! { #s } ;
537
528
538
- ExpandResult { value : Some ( ExpandedEager :: new ( expanded, FragmentKind :: Expr ) ) , err }
529
+ ExpandResult { value : Some ( ExpandedEager :: new ( expanded) ) , err }
539
530
}
540
531
541
532
fn option_env_expand (
@@ -553,7 +544,7 @@ fn option_env_expand(
553
544
Some ( s) => quote ! { std:: option:: Some ( #s) } ,
554
545
} ;
555
546
556
- ExpandResult :: ok ( Some ( ExpandedEager :: new ( expanded, FragmentKind :: Expr ) ) )
547
+ ExpandResult :: ok ( Some ( ExpandedEager :: new ( expanded) ) )
557
548
}
558
549
559
550
#[ cfg( test) ]
@@ -565,6 +556,7 @@ mod tests {
565
556
} ;
566
557
use base_db:: { fixture:: WithFixture , SourceDatabase } ;
567
558
use expect_test:: { expect, Expect } ;
559
+ use parser:: FragmentKind ;
568
560
use std:: sync:: Arc ;
569
561
use syntax:: ast:: NameOwner ;
570
562
@@ -617,6 +609,7 @@ mod tests {
617
609
local_inner : false ,
618
610
} ;
619
611
612
+ let fragment = crate :: to_fragment_kind ( & macro_call) ;
620
613
let args = macro_call. token_tree ( ) . unwrap ( ) ;
621
614
let parsed_args = mbe:: ast_to_token_tree ( & args) . 0 ;
622
615
let call_id = AstId :: new ( file_id. into ( ) , ast_id_map. ast_id ( & macro_call) ) ;
@@ -639,7 +632,7 @@ mod tests {
639
632
arg_or_expansion : Arc :: new ( expanded. subtree ) ,
640
633
included_file : expanded. included_file ,
641
634
} ) ,
642
- kind : MacroCallKind :: FnLike { ast_id : call_id, fragment : expanded . fragment } ,
635
+ kind : MacroCallKind :: FnLike { ast_id : call_id, fragment } ,
643
636
} ;
644
637
645
638
let id: MacroCallId = db. intern_macro ( loc) . into ( ) ;
0 commit comments