@@ -20,21 +20,24 @@ use base_db::RootQueryDb;
2020use expect_test:: Expect ;
2121use hir_expand:: {
2222 AstId , InFile , MacroCallId , MacroCallKind , MacroKind ,
23+ builtin:: quote:: quote,
2324 db:: ExpandDatabase ,
2425 proc_macro:: { ProcMacro , ProcMacroExpander , ProcMacroExpansionError , ProcMacroKind } ,
2526 span_map:: SpanMapRef ,
2627} ;
27- use intern:: Symbol ;
28+ use intern:: { Symbol , sym } ;
2829use itertools:: Itertools ;
29- use span:: { Edition , Span } ;
30+ use span:: { Edition , ROOT_ERASED_FILE_AST_ID , Span , SpanAnchor , SyntaxContext } ;
3031use stdx:: { format_to, format_to_acc} ;
3132use syntax:: {
3233 AstNode , AstPtr ,
3334 SyntaxKind :: { COMMENT , EOF , IDENT , LIFETIME_IDENT } ,
3435 SyntaxNode , T ,
3536 ast:: { self , edit:: IndentLevel } ,
3637} ;
38+ use syntax_bridge:: token_tree_to_syntax_node;
3739use test_fixture:: WithFixture ;
40+ use tt:: { TextRange , TextSize } ;
3841
3942use crate :: {
4043 AdtId , Lookup , ModuleDefId ,
@@ -386,3 +389,38 @@ impl ProcMacroExpander for IdentityWhenValidProcMacroExpander {
386389 other. type_id ( ) == TypeId :: of :: < Self > ( )
387390 }
388391}
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