Skip to content

Commit

Permalink
Remove mutability from unique boxes in the AST
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Jun 29, 2013
1 parent b29c368 commit 3bad712
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
's' => { return ast::sty_static; }
'v' => { return ast::sty_value; }
'@' => { return ast::sty_box(get_mutability(string[1])); }
'~' => { return ast::sty_uniq(get_mutability(string[1])); }
'~' => { return ast::sty_uniq; }
'&' => {
// FIXME(#4846) expl. region
return ast::sty_region(None, get_mutability(string[1]));
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,8 @@ fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::explic
ebml_w.writer.write(&[ '@' as u8 ]);
encode_mutability(ebml_w, m);
}
sty_uniq(m) => {
sty_uniq => {
ebml_w.writer.write(&[ '~' as u8 ]);
encode_mutability(ebml_w, m);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn check_expr(sess: Session,
if is_const {
match e.node {
expr_unary(_, deref, _) => { }
expr_unary(_, box(_), _) | expr_unary(_, uniq(_), _) => {
expr_unary(_, box(_), _) | expr_unary(_, uniq, _) => {
sess.span_err(e.span,
"disallowed operator in constant expression");
return;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ fn visit_fn(fk: &visit::fn_kind,
match *fk {
fk_method(_, _, method) => {
match method.explicit_self.node {
sty_value | sty_region(*) | sty_box(_) | sty_uniq(_) => {
sty_value | sty_region(*) | sty_box(_) | sty_uniq => {
fn_maps.add_variable(Arg(method.self_id,
special_idents::self_));
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::expr) -> ValueRef {
let is_float = ty::type_is_fp(ty);
return match u {
ast::box(_) |
ast::uniq(_) |
ast::uniq |
ast::deref => {
let (dv, _dt) = const_deref(cx, te, ty, true);
dv
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ fn trans_unary_datum(bcx: block,
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty,
heap_managed)
}
ast::uniq(_) => {
ast::uniq => {
let heap = heap_for_unique(bcx, un_ty);
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ pub fn trans_trait_callee(bcx: block,
let llpair = match explicit_self {
ast::sty_region(*) => Load(bcx, llpair),
ast::sty_static | ast::sty_value |
ast::sty_box(_) | ast::sty_uniq(_) => llpair
ast::sty_box(_) | ast::sty_uniq => llpair
};

let callee_ty = node_id_type(bcx, callee_id);
Expand Down Expand Up @@ -622,7 +622,7 @@ pub fn trans_trait_callee_from_llval(bcx: block,

self_mode = ty::ByRef;
}
ast::sty_uniq(_) => {
ast::sty_uniq => {
// Pass the unique pointer.
match store {
ty::UniqTraitStore => llself = llbox,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/type_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ pub fn mark_for_method_call(cx: &Context, e_id: node_id, callee_id: node_id) {
pub fn mark_for_expr(cx: &Context, e: &expr) {
match e.node {
expr_vstore(_, _) | expr_vec(_, _) | expr_struct(*) | expr_tup(_) |
expr_unary(_, box(_), _) | expr_unary(_, uniq(_), _) |
expr_unary(_, box(_), _) | expr_unary(_, uniq, _) |
expr_binary(_, add, _, _) | expr_copy(_) | expr_repeat(*) => {
node_type_needs(cx, use_repr, e.id);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,10 @@ fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Copy + 'static>(
ty::mt {ty: self_info.untransformed_self_ty,
mutbl: mutability}))
}
ast::sty_uniq(mutability) => {
ast::sty_uniq => {
Some(ty::mk_uniq(this.tcx(),
ty::mt {ty: self_info.untransformed_self_ty,
mutbl: mutability}))
mutbl: ast::m_imm}))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,11 +1123,11 @@ impl<'self> LookupContext<'self> {
}
}

sty_uniq(m) => {
sty_uniq => {
debug!("(is relevant?) explicit self is a unique pointer");
match ty::get(rcvr_ty).sty {
ty::ty_uniq(mt) => {
mutability_matches(mt.mutbl, m) &&
mutability_matches(mt.mutbl, ast::m_imm) &&
self.fcx.can_mk_subty(mt.ty, candidate.rcvr_ty).is_ok()
}

Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
ast::expr_unary(callee_id, unop, oprnd) => {
let exp_inner = do unpack_expected(fcx, expected) |sty| {
match unop {
ast::box(_) | ast::uniq(_) => match *sty {
ast::box(_) | ast::uniq => match *sty {
ty::ty_box(ref mt) | ty::ty_uniq(ref mt) => Some(mt.ty),
_ => None
},
Expand All @@ -2318,9 +2318,10 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
oprnd_t = ty::mk_box(tcx,
ty::mt {ty: oprnd_t, mutbl: mutbl});
}
ast::uniq(mutbl) => {
ast::uniq => {
oprnd_t = ty::mk_uniq(tcx,
ty::mt {ty: oprnd_t, mutbl: mutbl});
ty::mt {ty: oprnd_t,
mutbl: ast::m_imm});
}
ast::deref => {
let sty = structure_of(fcx, expr.span, oprnd_t);
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ pub enum binop {
#[deriving(Eq, Encodable, Decodable,IterBytes)]
pub enum unop {
box(mutability),
uniq(mutability),
uniq,
deref,
not,
neg
Expand Down Expand Up @@ -805,7 +805,7 @@ pub enum explicit_self_ {
sty_value, // `self`
sty_region(Option<@Lifetime>, mutability), // `&'lt self`
sty_box(mutability), // `@self`
sty_uniq(mutability) // `~self`
sty_uniq // `~self`
}
pub type explicit_self = spanned<explicit_self_>;
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn is_shift_binop(b: binop) -> bool {
pub fn unop_to_str(op: unop) -> ~str {
match op {
box(mt) => if mt == m_mutbl { ~"@mut " } else { ~"@" },
uniq(mt) => if mt == m_mutbl { ~"~mut " } else { ~"~" },
uniq => ~"~",
deref => ~"*",
not => ~"!",
neg => ~"-"
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option<PtrTy>)
let self_ty = respan(
span,
match *ptr {
Send => ast::sty_uniq(ast::m_imm),
Send => ast::sty_uniq,
Managed(mutbl) => ast::sty_box(mutbl),
Borrowed(ref lt, mutbl) => {
let lt = lt.map(|s| @cx.lifetime(span,
Expand Down
12 changes: 8 additions & 4 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2071,9 +2071,8 @@ impl Parser {
ex = match e.node {
expr_vec(*) |
expr_lit(@codemap::spanned { node: lit_str(_), span: _}) |
expr_repeat(*)
if m == m_imm => expr_vstore(e, expr_vstore_uniq),
_ => self.mk_unary(uniq(m), e)
expr_repeat(*) => expr_vstore(e, expr_vstore_uniq),
_ => self.mk_unary(uniq, e)
};
}
_ => return self.parse_dot_or_call_expr()
Expand Down Expand Up @@ -3366,7 +3365,12 @@ impl Parser {
maybe_parse_explicit_self(sty_box, self)
}
token::TILDE => {
maybe_parse_explicit_self(sty_uniq, self)
maybe_parse_explicit_self(|mutability| {
if mutability != m_imm {
self.obsolete(*self.last_span, ObsoleteMutOwnedPointer);
}
sty_uniq
}, self)
}
token::IDENT(*) if self.is_self_ident() => {
self.bump();
Expand Down
4 changes: 1 addition & 3 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,7 @@ pub fn print_explicit_self(s: @ps, explicit_self: ast::explicit_self_) -> bool {
match explicit_self {
ast::sty_static => { return false; }
ast::sty_value => { word(s.s, "self"); }
ast::sty_uniq => { word(s.s, "~self"); }
ast::sty_region(lt, m) => {
word(s.s, "&");
print_opt_lifetime(s, lt);
Expand All @@ -1662,9 +1663,6 @@ pub fn print_explicit_self(s: @ps, explicit_self: ast::explicit_self_) -> bool {
ast::sty_box(m) => {
word(s.s, "@"); print_mutability(s, m); word(s.s, "self");
}
ast::sty_uniq(m) => {
word(s.s, "~"); print_mutability(s, m); word(s.s, "self");
}
}
return true;
}
Expand Down

1 comment on commit 3bad712

@emberian
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.