File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
src/tools/rust-analyzer/crates Expand file tree Collapse file tree 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(
1515 span_map : & ExpansionSpanMap ,
1616 target_crate_id : CrateId ,
1717) -> 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 ( ) ;
1821 let crate_graph = db. crate_graph ( ) ;
1922 let target_crate = & crate_graph[ target_crate_id] ;
2023 let mut syntax_ctx_id_to_dollar_crate_replacement = FxHashMap :: default ( ) ;
2124 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 ;
2326 let replacement =
2427 syntax_ctx_id_to_dollar_crate_replacement. entry ( ctx) . or_insert_with ( || {
2528 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 {
89888988 "# ] ] ,
89898989 ) ;
89908990}
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