3
3
use base_db:: { salsa, CrateId , FileId , SourceDatabase } ;
4
4
use either:: Either ;
5
5
use limit:: Limit ;
6
- use mbe:: { syntax_node_to_token_tree, ValueResult } ;
6
+ use mbe:: syntax_node_to_token_tree;
7
7
use rustc_hash:: FxHashSet ;
8
8
use span:: { AstIdMap , Span , SyntaxContextData , SyntaxContextId } ;
9
9
use syntax:: { ast, AstNode , Parse , SyntaxElement , SyntaxError , SyntaxNode , SyntaxToken , T } ;
@@ -98,10 +98,7 @@ pub trait ExpandDatabase: SourceDatabase {
98
98
/// Lowers syntactic macro call to a token tree representation. That's a firewall
99
99
/// query, only typing in the macro call itself changes the returned
100
100
/// subtree.
101
- fn macro_arg (
102
- & self ,
103
- id : MacroCallId ,
104
- ) -> ValueResult < ( Arc < tt:: Subtree > , SyntaxFixupUndoInfo ) , Arc < Box < [ SyntaxError ] > > > ;
101
+ fn macro_arg ( & self , id : MacroCallId ) -> ( Arc < tt:: Subtree > , SyntaxFixupUndoInfo ) ;
105
102
/// Fetches the expander for this macro.
106
103
#[ salsa:: transparent]
107
104
#[ salsa:: invoke( TokenExpander :: macro_expander) ]
@@ -341,10 +338,7 @@ pub(crate) fn parse_with_map(
341
338
342
339
// FIXME: for derive attributes, this will return separate copies of the same structures! Though
343
340
// they may differ in spans due to differing call sites...
344
- fn macro_arg (
345
- db : & dyn ExpandDatabase ,
346
- id : MacroCallId ,
347
- ) -> ValueResult < ( Arc < tt:: Subtree > , SyntaxFixupUndoInfo ) , Arc < Box < [ SyntaxError ] > > > {
341
+ fn macro_arg ( db : & dyn ExpandDatabase , id : MacroCallId ) -> ( Arc < tt:: Subtree > , SyntaxFixupUndoInfo ) {
348
342
let loc = db. lookup_intern_macro_call ( id) ;
349
343
350
344
if let MacroCallLoc {
@@ -353,7 +347,7 @@ fn macro_arg(
353
347
..
354
348
} = & loc
355
349
{
356
- return ValueResult :: ok ( ( eager. arg . clone ( ) , SyntaxFixupUndoInfo :: NONE ) ) ;
350
+ return ( eager. arg . clone ( ) , SyntaxFixupUndoInfo :: NONE ) ;
357
351
}
358
352
359
353
let ( parse, map) = parse_with_map ( db, loc. kind . file_id ( ) ) ;
@@ -376,15 +370,8 @@ fn macro_arg(
376
370
} ;
377
371
378
372
let node = & ast_id. to_ptr ( db) . to_node ( & root) ;
379
- let offset = node. syntax ( ) . text_range ( ) . start ( ) ;
380
373
let Some ( tt) = node. token_tree ( ) else {
381
- return ValueResult :: new (
382
- dummy_tt ( tt:: DelimiterKind :: Invisible ) ,
383
- Arc :: new ( Box :: new ( [ SyntaxError :: new_at_offset (
384
- "missing token tree" . to_owned ( ) ,
385
- offset,
386
- ) ] ) ) ,
387
- ) ;
374
+ return dummy_tt ( tt:: DelimiterKind :: Invisible ) ;
388
375
} ;
389
376
let first = tt. left_delimiter_token ( ) . map ( |it| it. kind ( ) ) . unwrap_or ( T ! [ '(' ] ) ;
390
377
let last = tt. right_delimiter_token ( ) . map ( |it| it. kind ( ) ) . unwrap_or ( T ! [ . ] ) ;
@@ -409,33 +396,15 @@ fn macro_arg(
409
396
T ! [ '{' ] => tt:: DelimiterKind :: Brace ,
410
397
_ => tt:: DelimiterKind :: Invisible ,
411
398
} ;
412
- return ValueResult :: new (
413
- dummy_tt ( kind) ,
414
- Arc :: new ( Box :: new ( [ SyntaxError :: new_at_offset (
415
- "mismatched delimiters" . to_owned ( ) ,
416
- offset,
417
- ) ] ) ) ,
418
- ) ;
399
+ return dummy_tt ( kind) ;
419
400
}
420
401
421
402
let mut tt = mbe:: syntax_node_to_token_tree ( tt. syntax ( ) , map. as_ref ( ) , loc. call_site ) ;
422
403
if loc. def . is_proc_macro ( ) {
423
404
// proc macros expect their inputs without parentheses, MBEs expect it with them included
424
405
tt. delimiter . kind = tt:: DelimiterKind :: Invisible ;
425
406
}
426
- let val = ( Arc :: new ( tt) , SyntaxFixupUndoInfo :: NONE ) ;
427
- return if matches ! ( loc. def. kind, MacroDefKind :: BuiltInEager ( ..) ) {
428
- match parse. errors ( ) {
429
- errors if errors. is_empty ( ) => ValueResult :: ok ( val) ,
430
- errors => ValueResult :: new (
431
- val,
432
- // Box::<[_]>::from(res.errors()), not stable yet
433
- Arc :: new ( errors. to_vec ( ) . into_boxed_slice ( ) ) ,
434
- ) ,
435
- }
436
- } else {
437
- ValueResult :: ok ( val)
438
- } ;
407
+ return ( Arc :: new ( tt) , SyntaxFixupUndoInfo :: NONE ) ;
439
408
}
440
409
MacroCallKind :: Derive { ast_id, derive_attr_index, .. } => {
441
410
let node = ast_id. to_ptr ( db) . to_node ( & root) ;
@@ -475,7 +444,7 @@ fn macro_arg(
475
444
tt. delimiter . kind = tt:: DelimiterKind :: Invisible ;
476
445
}
477
446
478
- ValueResult :: ok ( ( Arc :: new ( tt) , undo_info) )
447
+ ( Arc :: new ( tt) , undo_info)
479
448
}
480
449
481
450
// FIXME: Censoring info should be calculated by the caller! Namely by name resolution
@@ -538,17 +507,7 @@ fn macro_expand(
538
507
let ExpandResult { value : tt, err } = match loc. def . kind {
539
508
MacroDefKind :: ProcMacro ( ..) => return db. expand_proc_macro ( macro_call_id) . map ( CowArc :: Arc ) ,
540
509
_ => {
541
- let ValueResult { value : ( macro_arg, undo_info) , err } = db. macro_arg ( macro_call_id) ;
542
- let format_parse_err = |err : Arc < Box < [ SyntaxError ] > > | {
543
- let mut buf = String :: new ( ) ;
544
- for err in & * * err {
545
- use std:: fmt:: Write ;
546
- _ = write ! ( buf, "{}, " , err) ;
547
- }
548
- buf. pop ( ) ;
549
- buf. pop ( ) ;
550
- ExpandError :: other ( buf)
551
- } ;
510
+ let ( macro_arg, undo_info) = db. macro_arg ( macro_call_id) ;
552
511
553
512
let arg = & * macro_arg;
554
513
let res = match loc. def . kind {
@@ -570,10 +529,7 @@ fn macro_expand(
570
529
// As such we just return the input subtree here.
571
530
let eager = match & loc. kind {
572
531
MacroCallKind :: FnLike { eager : None , .. } => {
573
- return ExpandResult {
574
- value : CowArc :: Arc ( macro_arg. clone ( ) ) ,
575
- err : err. map ( format_parse_err) ,
576
- } ;
532
+ return ExpandResult :: ok ( CowArc :: Arc ( macro_arg. clone ( ) ) ) ;
577
533
}
578
534
MacroCallKind :: FnLike { eager : Some ( eager) , .. } => Some ( & * * eager) ,
579
535
_ => None ,
@@ -594,11 +550,7 @@ fn macro_expand(
594
550
}
595
551
_ => unreachable ! ( ) ,
596
552
} ;
597
- ExpandResult {
598
- value : res. value ,
599
- // if the arg had parse errors, show them instead of the expansion errors
600
- err : err. map ( format_parse_err) . or ( res. err ) ,
601
- }
553
+ ExpandResult { value : res. value , err : res. err }
602
554
}
603
555
} ;
604
556
@@ -631,7 +583,7 @@ fn proc_macro_span(db: &dyn ExpandDatabase, ast: AstId<ast::Fn>) -> Span {
631
583
632
584
fn expand_proc_macro ( db : & dyn ExpandDatabase , id : MacroCallId ) -> ExpandResult < Arc < tt:: Subtree > > {
633
585
let loc = db. lookup_intern_macro_call ( id) ;
634
- let ( macro_arg, undo_info) = db. macro_arg ( id) . value ;
586
+ let ( macro_arg, undo_info) = db. macro_arg ( id) ;
635
587
636
588
let ( expander, ast) = match loc. def . kind {
637
589
MacroDefKind :: ProcMacro ( expander, _, ast) => ( expander, ast) ,
0 commit comments