@@ -466,32 +466,38 @@ impl MacResult for MacEager {
466466#[ derive( Copy , Clone ) ]
467467pub struct DummyResult {
468468 expr_only : bool ,
469- span : Span
469+ is_error : bool ,
470+ span : Span ,
470471}
471472
472473impl DummyResult {
473474 /// Create a default MacResult that can be anything.
474475 ///
475476 /// Use this as a return value after hitting any errors and
476477 /// calling `span_err`.
477- pub fn any ( sp : Span ) -> Box < dyn MacResult +' static > {
478- Box :: new ( DummyResult { expr_only : false , span : sp } )
478+ pub fn any ( span : Span ) -> Box < dyn MacResult +' static > {
479+ Box :: new ( DummyResult { expr_only : false , is_error : true , span } )
480+ }
481+
482+ /// Same as `any`, but must be a valid fragment, not error.
483+ pub fn any_valid ( span : Span ) -> Box < dyn MacResult +' static > {
484+ Box :: new ( DummyResult { expr_only : false , is_error : false , span } )
479485 }
480486
481487 /// Create a default MacResult that can only be an expression.
482488 ///
483489 /// Use this for macros that must expand to an expression, so even
484490 /// if an error is encountered internally, the user will receive
485491 /// an error that they also used it in the wrong place.
486- pub fn expr ( sp : Span ) -> Box < dyn MacResult +' static > {
487- Box :: new ( DummyResult { expr_only : true , span : sp } )
492+ pub fn expr ( span : Span ) -> Box < dyn MacResult +' static > {
493+ Box :: new ( DummyResult { expr_only : true , is_error : true , span } )
488494 }
489495
490496 /// A plain dummy expression.
491- pub fn raw_expr ( sp : Span ) -> P < ast:: Expr > {
497+ pub fn raw_expr ( sp : Span , is_error : bool ) -> P < ast:: Expr > {
492498 P ( ast:: Expr {
493499 id : ast:: DUMMY_NODE_ID ,
494- node : ast:: ExprKind :: Err ,
500+ node : if is_error { ast:: ExprKind :: Err } else { ast :: ExprKind :: Tup ( Vec :: new ( ) ) } ,
495501 span : sp,
496502 attrs : ThinVec :: new ( ) ,
497503 } )
@@ -507,18 +513,18 @@ impl DummyResult {
507513 }
508514
509515 /// A plain dummy type.
510- pub fn raw_ty ( sp : Span ) -> P < ast:: Ty > {
516+ pub fn raw_ty ( sp : Span , is_error : bool ) -> P < ast:: Ty > {
511517 P ( ast:: Ty {
512518 id : ast:: DUMMY_NODE_ID ,
513- node : ast:: TyKind :: Err ,
519+ node : if is_error { ast:: TyKind :: Err } else { ast :: TyKind :: Tup ( Vec :: new ( ) ) } ,
514520 span : sp
515521 } )
516522 }
517523}
518524
519525impl MacResult for DummyResult {
520526 fn make_expr ( self : Box < DummyResult > ) -> Option < P < ast:: Expr > > {
521- Some ( DummyResult :: raw_expr ( self . span ) )
527+ Some ( DummyResult :: raw_expr ( self . span , self . is_error ) )
522528 }
523529
524530 fn make_pat ( self : Box < DummyResult > ) -> Option < P < ast:: Pat > > {
@@ -561,13 +567,13 @@ impl MacResult for DummyResult {
561567 fn make_stmts ( self : Box < DummyResult > ) -> Option < SmallVec < [ ast:: Stmt ; 1 ] > > {
562568 Some ( smallvec ! [ ast:: Stmt {
563569 id: ast:: DUMMY_NODE_ID ,
564- node: ast:: StmtKind :: Expr ( DummyResult :: raw_expr( self . span) ) ,
570+ node: ast:: StmtKind :: Expr ( DummyResult :: raw_expr( self . span, self . is_error ) ) ,
565571 span: self . span,
566572 } ] )
567573 }
568574
569575 fn make_ty ( self : Box < DummyResult > ) -> Option < P < ast:: Ty > > {
570- Some ( DummyResult :: raw_ty ( self . span ) )
576+ Some ( DummyResult :: raw_ty ( self . span , self . is_error ) )
571577 }
572578}
573579
0 commit comments