Skip to content

Commit 0a0dc5a

Browse files
committed
Add ast::ExprCompletion
1 parent c1ddcf2 commit 0a0dc5a

File tree

15 files changed

+61
-11
lines changed

15 files changed

+61
-11
lines changed

src/librustc/middle/cfg/construct.rs

+1
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
436436
ast::ExprCast(ref e, _) |
437437
ast::ExprUnary(_, ref e) |
438438
ast::ExprParen(ref e) |
439+
ast::ExprCompletion(ref e) |
439440
ast::ExprField(ref e, _) |
440441
ast::ExprTupField(ref e, _) => {
441442
self.straightline(expr, pred, Some(&**e).into_iter())

src/librustc/middle/dead.rs

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
277277
ast::ExprTupField(ref lhs, idx) => {
278278
self.handle_tup_field_access(&**lhs, idx.node);
279279
}
280+
ast::ExprCompletion(..) => return,
280281
_ => ()
281282
}
282283

src/librustc/middle/expr_use_visitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
421421
self.walk_adjustment(expr);
422422

423423
match expr.node {
424-
ast::ExprParen(ref subexpr) => {
425-
self.walk_expr(&**subexpr)
424+
ast::ExprParen(ref e) | ast::ExprCompletion(ref e) => {
425+
self.walk_expr(&e)
426426
}
427427

428428
ast::ExprPath(_) | ast::ExprQPath(_) => { }

src/librustc/middle/liveness.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
505505
ast::ExprBlock(..) | ast::ExprAssign(..) | ast::ExprAssignOp(..) |
506506
ast::ExprMac(..) | ast::ExprStruct(..) | ast::ExprRepeat(..) |
507507
ast::ExprParen(..) | ast::ExprInlineAsm(..) | ast::ExprBox(..) |
508-
ast::ExprRange(..) => {
508+
ast::ExprRange(..) | ast::ExprCompletion(..) => {
509509
visit::walk_expr(ir, expr);
510510
}
511511
}
@@ -1189,7 +1189,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11891189
ast::ExprAddrOf(_, ref e) |
11901190
ast::ExprCast(ref e, _) |
11911191
ast::ExprUnary(_, ref e) |
1192-
ast::ExprParen(ref e) => {
1192+
ast::ExprParen(ref e) |
1193+
ast::ExprCompletion(ref e) => {
11931194
self.propagate_through_expr(&**e, succ)
11941195
}
11951196

@@ -1468,7 +1469,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
14681469
ast::ExprBlock(..) | ast::ExprMac(..) | ast::ExprAddrOf(..) |
14691470
ast::ExprStruct(..) | ast::ExprRepeat(..) | ast::ExprParen(..) |
14701471
ast::ExprClosure(..) | ast::ExprPath(..) | ast::ExprBox(..) |
1471-
ast::ExprRange(..) | ast::ExprQPath(..) => {
1472+
ast::ExprRange(..) | ast::ExprQPath(..) | ast::ExprCompletion(..) => {
14721473
visit::walk_expr(this, expr);
14731474
}
14741475
ast::ExprIfLet(..) => {

src/librustc/middle/mem_categorization.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
548548
ast::ExprBlock(..) | ast::ExprLoop(..) | ast::ExprMatch(..) |
549549
ast::ExprLit(..) | ast::ExprBreak(..) | ast::ExprMac(..) |
550550
ast::ExprAgain(..) | ast::ExprStruct(..) | ast::ExprRepeat(..) |
551-
ast::ExprInlineAsm(..) | ast::ExprBox(..) => {
551+
ast::ExprInlineAsm(..) | ast::ExprBox(..) |
552+
ast::ExprCompletion(..) => {
552553
Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty))
553554
}
554555

src/librustc/middle/ty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4617,7 +4617,9 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
46174617
}
46184618
}
46194619

4620-
ast::ExprParen(ref e) => expr_kind(tcx, &**e),
4620+
ast::ExprParen(ref e) | ast::ExprCompletion(ref e) => {
4621+
expr_kind(tcx, &e)
4622+
}
46214623

46224624
ast::ExprMac(..) => {
46234625
tcx.sess.span_bug(

src/librustc_back/svh.rs

+1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ mod svh_visitor {
293293
ExprIfLet(..) => unreachable!(),
294294
ExprWhileLet(..) => unreachable!(),
295295
ExprMac(..) => unreachable!(),
296+
ExprCompletion(..) => unreachable!(),
296297
}
297298
}
298299

src/librustc_privacy/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
954954
_ => {}
955955
}
956956
}
957+
ast::ExprCompletion(_) => return,
957958
_ => {}
958959
}
959960

src/librustc_trans/trans/debuginfo.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3491,7 +3491,8 @@ fn create_scope_map(cx: &CrateContext,
34913491
ast::ExprAddrOf(_, ref sub_exp) |
34923492
ast::ExprField(ref sub_exp, _) |
34933493
ast::ExprTupField(ref sub_exp, _) |
3494-
ast::ExprParen(ref sub_exp) =>
3494+
ast::ExprParen(ref sub_exp) |
3495+
ast::ExprCompletion(ref sub_exp) =>
34953496
walk_expr(cx, &**sub_exp, scope_stack, scope_map),
34963497

34973498
ast::ExprBox(ref place, ref sub_expr) => {

src/librustc_typeck/check/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -3679,6 +3679,23 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
36793679
lvalue_pref);
36803680
fcx.write_ty(id, fcx.expr_ty(&**a));
36813681
}
3682+
ast::ExprCompletion(ref e) => {
3683+
fcx.write_ty(e.id, fcx.infcx().next_diverging_ty_var());
3684+
fcx.write_ty(id, fcx.infcx().next_diverging_ty_var());
3685+
if let ast::ExprField(ref base, _) = e.node {
3686+
check_expr_with_lvalue_pref(fcx, &base, lvalue_pref);
3687+
let expr_t = structurally_resolved_type(fcx, base.span, fcx.expr_ty(&base));
3688+
match expr_t.sty {
3689+
ty::ty_struct(base_id, _) => {
3690+
let fields = ty::lookup_struct_fields(tcx, base_id);
3691+
for field in fields.iter() {
3692+
println!("{}", field.name);
3693+
}
3694+
}
3695+
_ => ()
3696+
}
3697+
}
3698+
}
36823699
ast::ExprAssign(ref lhs, ref rhs) => {
36833700
check_expr_with_lvalue_pref(fcx, &**lhs, PreferMutLvalue);
36843701

src/libsyntax/ast.rs

+2
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ pub enum Expr_ {
761761

762762
ExprMac(Mac),
763763

764+
ExprCompletion(P<Expr>),
765+
764766
/// A struct literal expression.
765767
ExprStruct(Path, Vec<Field>, Option<P<Expr>> /* base */),
766768

src/libsyntax/fold.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
13881388
expn_id: expn_id,
13891389
}),
13901390
ExprMac(mac) => ExprMac(folder.fold_mac(mac)),
1391+
ExprCompletion(expr) => ExprCompletion(folder.fold_expr(expr)),
13911392
ExprStruct(path, fields, maybe_expr) => {
13921393
ExprStruct(folder.fold_path(path),
13931394
fields.move_map(|x| folder.fold_field(x)),

src/libsyntax/parse/parser.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ast::{DeclLocal, DefaultBlock, DefaultReturn};
2222
use ast::{UnDeref, BiDiv, EMPTY_CTXT, EnumDef, ExplicitSelf};
2323
use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain};
2424
use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox};
25-
use ast::{ExprBreak, ExprCall, ExprCast};
25+
use ast::{ExprBreak, ExprCall, ExprCast, ExprCompletion};
2626
use ast::{ExprField, ExprTupField, ExprClosure, ExprIf, ExprIfLet, ExprIndex};
2727
use ast::{ExprLit, ExprLoop, ExprMac, ExprRange};
2828
use ast::{ExprMethodCall, ExprParen, ExprPath, ExprQPath};
@@ -2030,7 +2030,7 @@ impl<'a> Parser<'a> {
20302030
}
20312031
}
20322032

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> {
20342034
P(Expr {
20352035
id: ast::DUMMY_NODE_ID,
20362036
node: node,
@@ -2505,6 +2505,15 @@ impl<'a> Parser<'a> {
25052505
self.abort_if_errors();
25062506

25072507
}
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+
}
25082517
_ => self.unexpected()
25092518
}
25102519
continue;
@@ -3942,12 +3951,17 @@ impl<'a> Parser<'a> {
39423951
stmts: &mut Vec<P<Stmt>>,
39433952
last_block_expr: &mut Option<P<Expr>>) {
39443953
// 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 {
39463956
// Just check for errors and recover; do not eat semicolon yet.
39473957
self.commit_stmt(&[],
39483958
&[token::Semi, token::CloseDelim(token::Brace)]);
39493959
}
39503960

3961+
if self.token == token::GenerateCompletion {
3962+
self.bump();
3963+
}
3964+
39513965
match self.token {
39523966
token::Semi => {
39533967
self.bump();

src/libsyntax/print/pprust.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,10 @@ impl<'a> State<'a> {
19431943
try!(self.pclose());
19441944
}
19451945
ast::ExprMac(ref m) => try!(self.print_mac(m, token::Paren)),
1946+
ast::ExprCompletion(ref e) => {
1947+
try!(self.print_expr(&e));
1948+
try!(word(&mut self.s, &token_to_string(&token::GenerateCompletion)));
1949+
}
19461950
ast::ExprParen(ref e) => {
19471951
try!(self.popen());
19481952
try!(self.print_expr(&**e));

src/libsyntax/visit.rs

+3
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,9 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
877877
walk_expr_opt(visitor, optional_expression)
878878
}
879879
ExprMac(ref mac) => visitor.visit_mac(mac),
880+
ExprCompletion(ref subexpression) => {
881+
visitor.visit_expr(&subexpression);
882+
}
880883
ExprParen(ref subexpression) => {
881884
visitor.visit_expr(&**subexpression)
882885
}

0 commit comments

Comments
 (0)