Skip to content

Commit ec8380f

Browse files
committed
rustc: Add the safe address-of operator to the AST
1 parent 19c651f commit ec8380f

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

src/rustc/metadata/astencode_gen.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,7 @@ fn serialize_81<S: std::serialization::serializer>(s: S,
13931393
/*syntax::ast::mutability*/
13941394

13951395

1396+
13961397
{||
13971398
alt v {
13981399
syntax::ast::box(v0) {
@@ -1429,6 +1430,10 @@ fn serialize_81<S: std::serialization::serializer>(s: S,
14291430
syntax::ast::neg {
14301431
s.emit_enum_variant("syntax::ast::neg", 4u, 0u, {|| })
14311432
}
1433+
syntax::ast::addr_of {
1434+
s.emit_enum_variant("syntax::ast::addr_of", 5u, 0u,
1435+
{|| })
1436+
}
14321437
}
14331438
});
14341439
}
@@ -5543,6 +5548,8 @@ fn deserialize_81<S: std::serialization::deserializer>(s: S) ->
55435548

55445549

55455550

5551+
5552+
55465553
{||
55475554
s.read_enum_variant({|v_id|
55485555
alt check v_id {
@@ -5561,6 +5568,7 @@ fn deserialize_81<S: std::serialization::deserializer>(s: S) ->
55615568
2u { syntax::ast::deref }
55625569
3u { syntax::ast::not }
55635570
4u { syntax::ast::neg }
5571+
5u { syntax::ast::addr_of }
55645572
}
55655573
})
55665574
})

src/rustc/middle/trans/base.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,9 @@ fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr,
16451645
translated using trans_lval(), not \
16461646
trans_unary()");
16471647
}
1648+
ast::addr_of {
1649+
bcx.sess().bug("TODO pcwalton");
1650+
}
16481651
}
16491652
}
16501653

@@ -4305,7 +4308,8 @@ fn trans_const_expr(cx: crate_ctxt, e: @ast::expr) -> ValueRef {
43054308
ret alt u {
43064309
ast::box(_) |
43074310
ast::uniq(_) |
4308-
ast::deref { cx.sess.span_bug(e.span,
4311+
ast::deref |
4312+
ast::addr_of { cx.sess.span_bug(e.span,
43094313
"bad unop type in trans_const_expr"); }
43104314
ast::not { llvm::LLVMConstNot(te) }
43114315
ast::neg {

src/rustc/middle/typeck.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,6 +2186,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
21862186
oper_t = check_user_unop(fcx, "-", "unary-", expr, oper_t);
21872187
}
21882188
}
2189+
ast::addr_of {
2190+
tcx.sess.bug("TODO pcwalton");
2191+
}
21892192
}
21902193
write_ty(tcx, id, oper_t);
21912194
}

src/rustc/syntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ enum binop {
159159
enum unop {
160160
box(mutability),
161161
uniq(mutability),
162-
deref, not, neg,
162+
deref, not, neg, addr_of
163163
}
164164

165165
// Generally, after typeck you can get the inferred value

src/rustc/syntax/ast_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ fn unop_to_str(op: unop) -> str {
9494
deref { ret "*"; }
9595
not { ret "!"; }
9696
neg { ret "-"; }
97+
addr_of { ret "&"; }
9798
}
9899
}
99100

0 commit comments

Comments
 (0)