File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -15,11 +15,14 @@ pub fn prettify_macro_expansion(
15
15
span_map : & ExpansionSpanMap ,
16
16
target_crate_id : CrateId ,
17
17
) -> SyntaxNode {
18
+ // Because `syntax_bridge::prettify_macro_expansion::prettify_macro_expansion()` clones subtree for `syn`,
19
+ // that means it will be offsetted to the beginning.
20
+ let span_offset = syn. text_range ( ) . start ( ) ;
18
21
let crate_graph = db. crate_graph ( ) ;
19
22
let target_crate = & crate_graph[ target_crate_id] ;
20
23
let mut syntax_ctx_id_to_dollar_crate_replacement = FxHashMap :: default ( ) ;
21
24
syntax_bridge:: prettify_macro_expansion:: prettify_macro_expansion ( syn, & mut |dollar_crate| {
22
- let ctx = span_map. span_at ( dollar_crate. text_range ( ) . start ( ) ) . ctx ;
25
+ let ctx = span_map. span_at ( dollar_crate. text_range ( ) . start ( ) + span_offset ) . ctx ;
23
26
let replacement =
24
27
syntax_ctx_id_to_dollar_crate_replacement. entry ( ctx) . or_insert_with ( || {
25
28
let ctx_data = db. lookup_intern_syntax_context ( ctx) ;
Original file line number Diff line number Diff line change @@ -8988,3 +8988,33 @@ mod m {
8988
8988
"# ] ] ,
8989
8989
) ;
8990
8990
}
8991
+
8992
+ #[ test]
8993
+ fn regression_18238 ( ) {
8994
+ check (
8995
+ r#"
8996
+ macro_rules! foo {
8997
+ ($name:ident) => {
8998
+ pub static $name = Foo::new(|| {
8999
+ $crate;
9000
+ });
9001
+ };
9002
+ }
9003
+
9004
+ foo!(BAR_$0);
9005
+ "# ,
9006
+ expect ! [ [ r#"
9007
+ *BAR_*
9008
+
9009
+ ```rust
9010
+ test
9011
+ ```
9012
+
9013
+ ```rust
9014
+ pub static BAR_: {error} = Foo::new(||{
9015
+ crate;
9016
+ })
9017
+ ```
9018
+ "# ] ] ,
9019
+ ) ;
9020
+ }
You can’t perform that action at this time.
0 commit comments