File tree 4 files changed +85
-5
lines changed
src/tools/rust-analyzer/crates
4 files changed +85
-5
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ macro_rules! quote_impl__ {
102
102
( $span: ident $builder: ident # ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span $builder) '#' ) } ;
103
103
( $span: ident $builder: ident $ ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span $builder) '$' ) } ;
104
104
( $span: ident $builder: ident * ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span $builder) '*' ) } ;
105
+ ( $span: ident $builder: ident = ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span $builder) '=' ) } ;
105
106
106
107
( $span: ident $builder: ident $first: tt $( $tail: tt) + ) => { {
107
108
$crate:: builtin:: quote:: __quote!( $span $builder $first) ;
Original file line number Diff line number Diff line change @@ -441,8 +441,8 @@ fn transform_tt<'a, 'b>(
441
441
} ;
442
442
let len_diff = replacement. len ( ) as i64 - old_len as i64 ;
443
443
tt. splice ( i..i + old_len, replacement. flat_tokens ( ) . iter ( ) . cloned ( ) ) ;
444
- // `+1` for the loop .
445
- i = i . checked_add_signed ( len_diff as isize + 1 ) . unwrap ( ) ;
444
+ // Skip the newly inserted replacement, we don't want to visit it .
445
+ i += replacement . len ( ) ;
446
446
447
447
for & subtree_idx in & subtrees_stack {
448
448
let tt:: TokenTree :: Subtree ( subtree) = & mut tt[ subtree_idx] else {
Original file line number Diff line number Diff line change @@ -867,6 +867,19 @@ fn foo() {
867
867
let
868
868
loop {}
869
869
}
870
+ "# ,
871
+ ) ;
872
+ }
873
+
874
+ #[ test]
875
+ fn regression_18898 ( ) {
876
+ check (
877
+ r#"
878
+ //- proc_macros: issue_18898
879
+ #[proc_macros::issue_18898]
880
+ fn foo() {
881
+ let
882
+ }
870
883
"# ,
871
884
) ;
872
885
}
Original file line number Diff line number Diff line change @@ -376,8 +376,8 @@ impl ChangeFixture {
376
376
}
377
377
}
378
378
379
- fn default_test_proc_macros ( ) -> [ ( String , ProcMacro ) ; 8 ] {
380
- [
379
+ fn default_test_proc_macros ( ) -> Box < [ ( String , ProcMacro ) ] > {
380
+ Box :: new ( [
381
381
(
382
382
r#"
383
383
#[proc_macro_attribute]
@@ -498,7 +498,22 @@ pub fn issue_17479(input: TokenStream) -> TokenStream {
498
498
disabled : false ,
499
499
} ,
500
500
) ,
501
- ]
501
+ (
502
+ r#"
503
+ #[proc_macro_attribute]
504
+ pub fn issue_18898(_attr: TokenStream, input: TokenStream) -> TokenStream {
505
+ input
506
+ }
507
+ "#
508
+ . into ( ) ,
509
+ ProcMacro {
510
+ name : Symbol :: intern ( "issue_18898" ) ,
511
+ kind : ProcMacroKind :: Bang ,
512
+ expander : sync:: Arc :: new ( Issue18898ProcMacroExpander ) ,
513
+ disabled : false ,
514
+ } ,
515
+ ) ,
516
+ ] )
502
517
}
503
518
504
519
fn filter_test_proc_macros (
@@ -801,3 +816,54 @@ impl ProcMacroExpander for Issue17479ProcMacroExpander {
801
816
} )
802
817
}
803
818
}
819
+
820
+ // Reads ident type within string quotes, for issue #17479.
821
+ #[ derive( Debug ) ]
822
+ struct Issue18898ProcMacroExpander ;
823
+ impl ProcMacroExpander for Issue18898ProcMacroExpander {
824
+ fn expand (
825
+ & self ,
826
+ subtree : & TopSubtree ,
827
+ _: Option < & TopSubtree > ,
828
+ _: & Env ,
829
+ def_site : Span ,
830
+ _: Span ,
831
+ _: Span ,
832
+ _: Option < String > ,
833
+ ) -> Result < TopSubtree , ProcMacroExpansionError > {
834
+ let span = subtree
835
+ . token_trees ( )
836
+ . flat_tokens ( )
837
+ . last ( )
838
+ . ok_or_else ( || ProcMacroExpansionError :: Panic ( "malformed input" . to_owned ( ) ) ) ?
839
+ . first_span ( ) ;
840
+ let overly_long_subtree = quote ! { span =>
841
+ {
842
+ let a = 5 ;
843
+ let a = 5 ;
844
+ let a = 5 ;
845
+ let a = 5 ;
846
+ let a = 5 ;
847
+ let a = 5 ;
848
+ let a = 5 ;
849
+ let a = 5 ;
850
+ let a = 5 ;
851
+ let a = 5 ;
852
+ let a = 5 ;
853
+ let a = 5 ;
854
+ let a = 5 ;
855
+ let a = 5 ;
856
+ let a = 5 ;
857
+ let a = 5 ;
858
+ let a = 5 ;
859
+ let a = 5 ;
860
+ let a = 5 ;
861
+ }
862
+ } ;
863
+ Ok ( quote ! { def_site =>
864
+ fn foo( ) {
865
+ #overly_long_subtree
866
+ }
867
+ } )
868
+ }
869
+ }
You can’t perform that action at this time.
0 commit comments