33use base_db:: { salsa, CrateId , FileId , SourceDatabase } ;
44use either:: Either ;
55use limit:: Limit ;
6- use mbe:: { syntax_node_to_token_tree, ValueResult } ;
6+ use mbe:: syntax_node_to_token_tree;
77use rustc_hash:: FxHashSet ;
88use span:: { AstIdMap , Span , SyntaxContextData , SyntaxContextId } ;
99use syntax:: { ast, AstNode , Parse , SyntaxElement , SyntaxError , SyntaxNode , SyntaxToken , T } ;
@@ -98,10 +98,7 @@ pub trait ExpandDatabase: SourceDatabase {
9898 /// Lowers syntactic macro call to a token tree representation. That's a firewall
9999 /// query, only typing in the macro call itself changes the returned
100100 /// 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 ) ;
105102 /// Fetches the expander for this macro.
106103 #[ salsa:: transparent]
107104 #[ salsa:: invoke( TokenExpander :: macro_expander) ]
@@ -341,10 +338,7 @@ pub(crate) fn parse_with_map(
341338
342339// FIXME: for derive attributes, this will return separate copies of the same structures! Though
343340// 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 ) {
348342 let loc = db. lookup_intern_macro_call ( id) ;
349343
350344 if let MacroCallLoc {
@@ -353,7 +347,7 @@ fn macro_arg(
353347 ..
354348 } = & loc
355349 {
356- return ValueResult :: ok ( ( eager. arg . clone ( ) , SyntaxFixupUndoInfo :: NONE ) ) ;
350+ return ( eager. arg . clone ( ) , SyntaxFixupUndoInfo :: NONE ) ;
357351 }
358352
359353 let ( parse, map) = parse_with_map ( db, loc. kind . file_id ( ) ) ;
@@ -376,15 +370,8 @@ fn macro_arg(
376370 } ;
377371
378372 let node = & ast_id. to_ptr ( db) . to_node ( & root) ;
379- let offset = node. syntax ( ) . text_range ( ) . start ( ) ;
380373 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 ) ;
388375 } ;
389376 let first = tt. left_delimiter_token ( ) . map ( |it| it. kind ( ) ) . unwrap_or ( T ! [ '(' ] ) ;
390377 let last = tt. right_delimiter_token ( ) . map ( |it| it. kind ( ) ) . unwrap_or ( T ! [ . ] ) ;
@@ -409,33 +396,15 @@ fn macro_arg(
409396 T ! [ '{' ] => tt:: DelimiterKind :: Brace ,
410397 _ => tt:: DelimiterKind :: Invisible ,
411398 } ;
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) ;
419400 }
420401
421402 let mut tt = mbe:: syntax_node_to_token_tree ( tt. syntax ( ) , map. as_ref ( ) , loc. call_site ) ;
422403 if loc. def . is_proc_macro ( ) {
423404 // proc macros expect their inputs without parentheses, MBEs expect it with them included
424405 tt. delimiter . kind = tt:: DelimiterKind :: Invisible ;
425406 }
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 ) ;
439408 }
440409 MacroCallKind :: Derive { ast_id, derive_attr_index, .. } => {
441410 let node = ast_id. to_ptr ( db) . to_node ( & root) ;
@@ -475,7 +444,7 @@ fn macro_arg(
475444 tt. delimiter . kind = tt:: DelimiterKind :: Invisible ;
476445 }
477446
478- ValueResult :: ok ( ( Arc :: new ( tt) , undo_info) )
447+ ( Arc :: new ( tt) , undo_info)
479448}
480449
481450// FIXME: Censoring info should be calculated by the caller! Namely by name resolution
@@ -538,17 +507,7 @@ fn macro_expand(
538507 let ExpandResult { value : tt, err } = match loc. def . kind {
539508 MacroDefKind :: ProcMacro ( ..) => return db. expand_proc_macro ( macro_call_id) . map ( CowArc :: Arc ) ,
540509 _ => {
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) ;
552511
553512 let arg = & * macro_arg;
554513 let res = match loc. def . kind {
@@ -570,10 +529,7 @@ fn macro_expand(
570529 // As such we just return the input subtree here.
571530 let eager = match & loc. kind {
572531 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 ( ) ) ) ;
577533 }
578534 MacroCallKind :: FnLike { eager : Some ( eager) , .. } => Some ( & * * eager) ,
579535 _ => None ,
@@ -594,11 +550,7 @@ fn macro_expand(
594550 }
595551 _ => unreachable ! ( ) ,
596552 } ;
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 }
602554 }
603555 } ;
604556
@@ -631,7 +583,7 @@ fn proc_macro_span(db: &dyn ExpandDatabase, ast: AstId<ast::Fn>) -> Span {
631583
632584fn expand_proc_macro ( db : & dyn ExpandDatabase , id : MacroCallId ) -> ExpandResult < Arc < tt:: Subtree > > {
633585 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) ;
635587
636588 let ( expander, ast) = match loc. def . kind {
637589 MacroDefKind :: ProcMacro ( expander, _, ast) => ( expander, ast) ,
0 commit comments