@@ -20,21 +20,24 @@ use base_db::RootQueryDb;
20
20
use expect_test:: Expect ;
21
21
use hir_expand:: {
22
22
AstId , InFile , MacroCallId , MacroCallKind , MacroKind ,
23
+ builtin:: quote:: quote,
23
24
db:: ExpandDatabase ,
24
25
proc_macro:: { ProcMacro , ProcMacroExpander , ProcMacroExpansionError , ProcMacroKind } ,
25
26
span_map:: SpanMapRef ,
26
27
} ;
27
- use intern:: Symbol ;
28
+ use intern:: { Symbol , sym } ;
28
29
use itertools:: Itertools ;
29
- use span:: { Edition , Span } ;
30
+ use span:: { Edition , ROOT_ERASED_FILE_AST_ID , Span , SpanAnchor , SyntaxContext } ;
30
31
use stdx:: { format_to, format_to_acc} ;
31
32
use syntax:: {
32
33
AstNode , AstPtr ,
33
34
SyntaxKind :: { COMMENT , EOF , IDENT , LIFETIME_IDENT } ,
34
35
SyntaxNode , T ,
35
36
ast:: { self , edit:: IndentLevel } ,
36
37
} ;
38
+ use syntax_bridge:: token_tree_to_syntax_node;
37
39
use test_fixture:: WithFixture ;
40
+ use tt:: { TextRange , TextSize } ;
38
41
39
42
use crate :: {
40
43
AdtId , Lookup , ModuleDefId ,
@@ -386,3 +389,38 @@ impl ProcMacroExpander for IdentityWhenValidProcMacroExpander {
386
389
other. type_id ( ) == TypeId :: of :: < Self > ( )
387
390
}
388
391
}
392
+
393
+ #[ test]
394
+ fn regression_20171 ( ) {
395
+ // This really isn't the appropriate place to put this test, but it's convenient with access to `quote!`.
396
+ let span = Span {
397
+ range : TextRange :: empty ( TextSize :: new ( 0 ) ) ,
398
+ anchor : SpanAnchor {
399
+ file_id : span:: EditionedFileId :: current_edition ( span:: FileId :: from_raw ( 0 ) ) ,
400
+ ast_id : ROOT_ERASED_FILE_AST_ID ,
401
+ } ,
402
+ ctx : SyntaxContext :: root ( Edition :: CURRENT ) ,
403
+ } ;
404
+ let close_brace = tt:: Punct { char : '}' , spacing : tt:: Spacing :: Alone , span } ;
405
+ let dotdot1 = tt:: Punct { char : '.' , spacing : tt:: Spacing :: Joint , span } ;
406
+ let dotdot2 = tt:: Punct { char : '.' , spacing : tt:: Spacing :: Alone , span } ;
407
+ let dollar_crate = sym:: dollar_crate;
408
+ let tt = quote ! {
409
+ span => {
410
+ if !( ( matches!(
411
+ drive_parser( & mut parser, data, false ) ,
412
+ Err ( TarParserError :: CorruptField {
413
+ field: CorruptFieldContext :: PaxKvLength ,
414
+ error: GeneralParseError :: ParseInt ( ParseIntError { #dotdot1 #dotdot2 } )
415
+ } )
416
+ #close_brace ) ) ) {
417
+ #dollar_crate:: panic:: panic_2021!( ) ;
418
+ } }
419
+ } ;
420
+ token_tree_to_syntax_node (
421
+ & tt,
422
+ syntax_bridge:: TopEntryPoint :: MacroStmts ,
423
+ & mut |_| Edition :: CURRENT ,
424
+ Edition :: CURRENT ,
425
+ ) ;
426
+ }
0 commit comments