@@ -56,39 +56,6 @@ pub enum DescendPreference {
56
56
None ,
57
57
}
58
58
59
- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
60
- pub enum MacroInputKind {
61
- Root ,
62
- Bang ,
63
- AttrInput ,
64
- AttrTarget ,
65
- Derive ,
66
- DeriveHelper ,
67
- // Include,
68
- }
69
- impl MacroInputKind {
70
- pub fn is_tt ( self ) -> bool {
71
- matches ! (
72
- self ,
73
- MacroInputKind :: AttrInput
74
- | MacroInputKind :: Bang
75
- | MacroInputKind :: DeriveHelper
76
- | MacroInputKind :: Derive
77
- )
78
- }
79
- }
80
-
81
- impl ops:: BitOr for MacroInputKind {
82
- type Output = Self ;
83
-
84
- fn bitor ( self , rhs : Self ) -> Self :: Output {
85
- match self {
86
- Self :: Root => rhs,
87
- _ => self ,
88
- }
89
- }
90
- }
91
-
92
59
#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
93
60
pub enum PathResolution {
94
61
/// An item
@@ -586,7 +553,7 @@ impl<'db> SemanticsImpl<'db> {
586
553
string : & ast:: String ,
587
554
) -> Option < Vec < ( TextRange , Option < PathResolution > ) > > {
588
555
let quote = string. open_quote_text_range ( ) ?;
589
- self . descend_into_macros_ng_b ( string. syntax ( ) . clone ( ) , |kind , token| {
556
+ self . descend_into_macros_ng_b ( string. syntax ( ) . clone ( ) , |token| {
590
557
( || {
591
558
let token = token. value ;
592
559
let string = ast:: String :: cast ( token) ?;
@@ -613,7 +580,7 @@ impl<'db> SemanticsImpl<'db> {
613
580
) -> Option < ( TextRange , Option < PathResolution > ) > {
614
581
let original_string = ast:: String :: cast ( original_token. clone ( ) ) ?;
615
582
let quote = original_string. open_quote_text_range ( ) ?;
616
- self . descend_into_macros_ng_b ( original_token. clone ( ) , |kind , token| {
583
+ self . descend_into_macros_ng_b ( original_token. clone ( ) , |token| {
617
584
( || {
618
585
let token = token. value ;
619
586
self . resolve_offset_in_format_args (
@@ -656,7 +623,7 @@ impl<'db> SemanticsImpl<'db> {
656
623
657
624
if first == last {
658
625
// node is just the token, so descend the token
659
- self . descend_into_macros_impl ( first, & mut |_kind , InFile { value, .. } | {
626
+ self . descend_into_macros_impl ( first, & mut |InFile { value, .. } | {
660
627
if let Some ( node) = value
661
628
. parent_ancestors ( )
662
629
. take_while ( |it| it. text_range ( ) == value. text_range ( ) )
@@ -669,15 +636,15 @@ impl<'db> SemanticsImpl<'db> {
669
636
} else {
670
637
// Descend first and last token, then zip them to look for the node they belong to
671
638
let mut scratch: SmallVec < [ _ ; 1 ] > = smallvec ! [ ] ;
672
- self . descend_into_macros_impl ( first, & mut |_kind , token| {
639
+ self . descend_into_macros_impl ( first, & mut |token| {
673
640
scratch. push ( token) ;
674
641
CONTINUE_NO_BREAKS
675
642
} ) ;
676
643
677
644
let mut scratch = scratch. into_iter ( ) ;
678
645
self . descend_into_macros_impl (
679
646
last,
680
- & mut |_kind , InFile { value : last, file_id : last_fid } | {
647
+ & mut |InFile { value : last, file_id : last_fid } | {
681
648
if let Some ( InFile { value : first, file_id : first_fid } ) = scratch. next ( ) {
682
649
if first_fid == last_fid {
683
650
if let Some ( p) = first. parent ( ) {
@@ -727,7 +694,7 @@ impl<'db> SemanticsImpl<'db> {
727
694
let mut res = smallvec ! [ ] ;
728
695
self . descend_into_macros_impl :: < Infallible > (
729
696
token. clone ( ) ,
730
- & mut |kind , InFile { value, .. } | {
697
+ & mut |InFile { value, .. } | {
731
698
let is_a_match = match mode {
732
699
// Dp::SameText(text) => value.text() == text,
733
700
Dp :: SameKind ( preferred_kind) => {
@@ -753,20 +720,20 @@ impl<'db> SemanticsImpl<'db> {
753
720
pub fn descend_into_macros_ng (
754
721
& self ,
755
722
token : SyntaxToken ,
756
- mut cb : impl FnMut ( MacroInputKind , InFile < SyntaxToken > ) ,
723
+ mut cb : impl FnMut ( InFile < SyntaxToken > ) ,
757
724
) {
758
- self . descend_into_macros_impl ( token. clone ( ) , & mut |kind , t| {
759
- cb ( kind , t) ;
725
+ self . descend_into_macros_impl ( token. clone ( ) , & mut |t| {
726
+ cb ( t) ;
760
727
CONTINUE_NO_BREAKS
761
728
} ) ;
762
729
}
763
730
764
731
pub fn descend_into_macros_ng_b < T > (
765
732
& self ,
766
733
token : SyntaxToken ,
767
- mut cb : impl FnMut ( MacroInputKind , InFile < SyntaxToken > ) -> ControlFlow < T > ,
734
+ mut cb : impl FnMut ( InFile < SyntaxToken > ) -> ControlFlow < T > ,
768
735
) -> Option < T > {
769
- self . descend_into_macros_impl ( token. clone ( ) , & mut |kind , t| cb ( kind , t) )
736
+ self . descend_into_macros_impl ( token. clone ( ) , & mut |t| cb ( t) )
770
737
}
771
738
772
739
/// Descends the token into expansions, returning the tokens that matches the input
@@ -776,7 +743,7 @@ impl<'db> SemanticsImpl<'db> {
776
743
let text = token. text ( ) ;
777
744
let kind = token. kind ( ) ;
778
745
779
- self . descend_into_macros_ng ( token. clone ( ) , |m_kind , InFile { value, file_id } | {
746
+ self . descend_into_macros_ng ( token. clone ( ) , |InFile { value, file_id : _ } | {
780
747
let mapped_kind = value. kind ( ) ;
781
748
let any_ident_match = || kind. is_any_identifier ( ) && value. kind ( ) . is_any_identifier ( ) ;
782
749
let matches = ( kind == mapped_kind || any_ident_match ( ) ) && text == value. text ( ) ;
@@ -796,7 +763,7 @@ impl<'db> SemanticsImpl<'db> {
796
763
let text = token. text ( ) ;
797
764
let kind = token. kind ( ) ;
798
765
799
- self . descend_into_macros_ng_b ( token. clone ( ) , |m_kind , InFile { value, file_id } | {
766
+ self . descend_into_macros_ng_b ( token. clone ( ) , |InFile { value, file_id : _ } | {
800
767
let mapped_kind = value. kind ( ) ;
801
768
let any_ident_match = || kind. is_any_identifier ( ) && value. kind ( ) . is_any_identifier ( ) ;
802
769
let matches = ( kind == mapped_kind || any_ident_match ( ) ) && text == value. text ( ) ;
@@ -812,7 +779,7 @@ impl<'db> SemanticsImpl<'db> {
812
779
fn descend_into_macros_impl < T > (
813
780
& self ,
814
781
token : SyntaxToken ,
815
- f : & mut dyn FnMut ( MacroInputKind , InFile < SyntaxToken > ) -> ControlFlow < T > ,
782
+ f : & mut dyn FnMut ( InFile < SyntaxToken > ) -> ControlFlow < T > ,
816
783
) -> Option < T > {
817
784
let _p = tracing:: info_span!( "descend_into_macros_impl" ) . entered ( ) ;
818
785
let ( sa, span, file_id) =
@@ -832,11 +799,10 @@ impl<'db> SemanticsImpl<'db> {
832
799
// These are tracked to know which macro calls we still have to look into
833
800
// the tokens themselves aren't that interesting as the span that is being used to map
834
801
// things down never changes.
835
- let mut stack: Vec < ( _ , _ , SmallVec < [ _ ; 2 ] > ) > =
836
- vec ! [ ( file_id, MacroInputKind :: Root , smallvec![ token] ) ] ;
802
+ let mut stack: Vec < ( _ , SmallVec < [ _ ; 2 ] > ) > = vec ! [ ( file_id, smallvec![ token] ) ] ;
837
803
838
804
// Process the expansion of a call, pushing all tokens with our span in the expansion back onto our stack
839
- let process_expansion_for_token = |stack : & mut Vec < _ > , macro_file, remap_kind | {
805
+ let process_expansion_for_token = |stack : & mut Vec < _ > , macro_file| {
840
806
let InMacroFile { file_id, value : mapped_tokens } = self . with_ctx ( |ctx| {
841
807
Some (
842
808
ctx. cache
@@ -858,7 +824,7 @@ impl<'db> SemanticsImpl<'db> {
858
824
// we have found a mapping for the token if the vec is non-empty
859
825
let res = mapped_tokens. is_empty ( ) . not ( ) . then_some ( ( ) ) ;
860
826
// requeue the tokens we got from mapping our current token down
861
- stack. push ( ( HirFileId :: from ( file_id) , remap_kind , mapped_tokens) ) ;
827
+ stack. push ( ( HirFileId :: from ( file_id) , mapped_tokens) ) ;
862
828
res
863
829
} ;
864
830
@@ -868,7 +834,7 @@ impl<'db> SemanticsImpl<'db> {
868
834
tokens. retain ( |t : & mut SyntaxToken | !range. contains_range ( t. text_range ( ) ) )
869
835
} ;
870
836
871
- while let Some ( ( expansion, remap_kind , ref mut tokens) ) = stack. pop ( ) {
837
+ while let Some ( ( expansion, ref mut tokens) ) = stack. pop ( ) {
872
838
while let Some ( token) = tokens. pop ( ) {
873
839
let was_not_remapped = ( || {
874
840
// First expand into attribute invocations
@@ -909,11 +875,7 @@ impl<'db> SemanticsImpl<'db> {
909
875
. unwrap_or_else ( || text_range. start ( ) ) ;
910
876
let text_range = TextRange :: new ( start, text_range. end ( ) ) ;
911
877
filter_duplicates ( tokens, text_range) ;
912
- return process_expansion_for_token (
913
- & mut stack,
914
- file_id,
915
- remap_kind | MacroInputKind :: AttrTarget ,
916
- ) ;
878
+ return process_expansion_for_token ( & mut stack, file_id) ;
917
879
}
918
880
919
881
// Then check for token trees, that means we are either in a function-like macro or
@@ -952,20 +914,11 @@ impl<'db> SemanticsImpl<'db> {
952
914
let text_range = tt. syntax ( ) . text_range ( ) ;
953
915
filter_duplicates ( tokens, text_range) ;
954
916
955
- process_expansion_for_token (
956
- & mut stack,
957
- file_id,
958
- remap_kind | MacroInputKind :: Bang ,
959
- )
960
- . or ( file_id
917
+ process_expansion_for_token ( & mut stack, file_id) . or ( file_id
961
918
. eager_arg ( self . db . upcast ( ) )
962
919
. and_then ( |arg| {
963
920
// also descend into eager expansions
964
- process_expansion_for_token (
965
- & mut stack,
966
- arg. as_macro_file ( ) ,
967
- remap_kind | MacroInputKind :: Bang ,
968
- )
921
+ process_expansion_for_token ( & mut stack, arg. as_macro_file ( ) )
969
922
} ) )
970
923
}
971
924
// derive or derive helper
@@ -997,9 +950,7 @@ impl<'db> SemanticsImpl<'db> {
997
950
!text_range. contains_range ( t. text_range ( ) )
998
951
} ) ;
999
952
return process_expansion_for_token (
1000
- & mut stack,
1001
- file_id,
1002
- remap_kind | MacroInputKind :: Derive ,
953
+ & mut stack, file_id,
1003
954
) ;
1004
955
}
1005
956
None => Some ( adt) ,
@@ -1043,7 +994,6 @@ impl<'db> SemanticsImpl<'db> {
1043
994
res = res. or ( process_expansion_for_token (
1044
995
& mut stack,
1045
996
derive. as_macro_file ( ) ,
1046
- remap_kind | MacroInputKind :: DeriveHelper ,
1047
997
) ) ;
1048
998
}
1049
999
res
@@ -1053,7 +1003,7 @@ impl<'db> SemanticsImpl<'db> {
1053
1003
. is_none ( ) ;
1054
1004
1055
1005
if was_not_remapped {
1056
- if let ControlFlow :: Break ( b) = f ( remap_kind , InFile :: new ( expansion, token) ) {
1006
+ if let ControlFlow :: Break ( b) = f ( InFile :: new ( expansion, token) ) {
1057
1007
return Some ( b) ;
1058
1008
}
1059
1009
}
0 commit comments