@@ -22,7 +22,7 @@ use ast::{DeclLocal, DefaultBlock, DefaultReturn};
22
22
use ast:: { UnDeref , BiDiv , EMPTY_CTXT , EnumDef , ExplicitSelf } ;
23
23
use ast:: { Expr , Expr_ , ExprAddrOf , ExprMatch , ExprAgain } ;
24
24
use ast:: { ExprAssign , ExprAssignOp , ExprBinary , ExprBlock , ExprBox } ;
25
- use ast:: { ExprBreak , ExprCall , ExprCast } ;
25
+ use ast:: { ExprBreak , ExprCall , ExprCast , ExprCompletion } ;
26
26
use ast:: { ExprField , ExprTupField , ExprClosure , ExprIf , ExprIfLet , ExprIndex } ;
27
27
use ast:: { ExprLit , ExprLoop , ExprMac , ExprRange } ;
28
28
use ast:: { ExprMethodCall , ExprParen , ExprPath , ExprQPath } ;
@@ -2030,7 +2030,7 @@ impl<'a> Parser<'a> {
2030
2030
}
2031
2031
}
2032
2032
2033
- pub fn mk_expr ( & mut self , lo : BytePos , hi : BytePos , node : Expr_ ) -> P < Expr > {
2033
+ pub fn mk_expr ( & self , lo : BytePos , hi : BytePos , node : Expr_ ) -> P < Expr > {
2034
2034
P ( Expr {
2035
2035
id : ast:: DUMMY_NODE_ID ,
2036
2036
node : node,
@@ -2505,6 +2505,15 @@ impl<'a> Parser<'a> {
2505
2505
self . abort_if_errors ( ) ;
2506
2506
2507
2507
}
2508
+ token:: GenerateCompletion => {
2509
+ // Important: do not bump
2510
+ let sp = self . span ;
2511
+ let hi = self . last_span . hi ;
2512
+ let id = codemap:: respan ( sp, special_idents:: invalid) ;
2513
+ let field = self . mk_field ( e, id) ;
2514
+ e = self . mk_expr ( lo, hi,
2515
+ ExprCompletion ( self . mk_expr ( lo, hi, field) ) ) ;
2516
+ }
2508
2517
_ => self . unexpected ( )
2509
2518
}
2510
2519
continue ;
@@ -3942,12 +3951,17 @@ impl<'a> Parser<'a> {
3942
3951
stmts : & mut Vec < P < Stmt > > ,
3943
3952
last_block_expr : & mut Option < P < Expr > > ) {
3944
3953
// expression without semicolon
3945
- if classify:: expr_requires_semi_to_be_stmt ( & * e) {
3954
+ if classify:: expr_requires_semi_to_be_stmt ( & * e) &&
3955
+ self . token != token:: GenerateCompletion {
3946
3956
// Just check for errors and recover; do not eat semicolon yet.
3947
3957
self . commit_stmt ( & [ ] ,
3948
3958
& [ token:: Semi , token:: CloseDelim ( token:: Brace ) ] ) ;
3949
3959
}
3950
3960
3961
+ if self . token == token:: GenerateCompletion {
3962
+ self . bump ( ) ;
3963
+ }
3964
+
3951
3965
match self . token {
3952
3966
token:: Semi => {
3953
3967
self . bump ( ) ;
0 commit comments