mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Remove mutability from unique boxes in the AST
This commit is contained in:
parent
b29c368674
commit
3bad7129eb
@ -786,7 +786,7 @@ fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
|
|||||||
's' => { return ast::sty_static; }
|
's' => { return ast::sty_static; }
|
||||||
'v' => { return ast::sty_value; }
|
'v' => { return ast::sty_value; }
|
||||||
'@' => { return ast::sty_box(get_mutability(string[1])); }
|
'@' => { return ast::sty_box(get_mutability(string[1])); }
|
||||||
'~' => { return ast::sty_uniq(get_mutability(string[1])); }
|
'~' => { return ast::sty_uniq; }
|
||||||
'&' => {
|
'&' => {
|
||||||
// FIXME(#4846) expl. region
|
// FIXME(#4846) expl. region
|
||||||
return ast::sty_region(None, get_mutability(string[1]));
|
return ast::sty_region(None, get_mutability(string[1]));
|
||||||
|
@ -630,9 +630,8 @@ fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::explic
|
|||||||
ebml_w.writer.write(&[ '@' as u8 ]);
|
ebml_w.writer.write(&[ '@' as u8 ]);
|
||||||
encode_mutability(ebml_w, m);
|
encode_mutability(ebml_w, m);
|
||||||
}
|
}
|
||||||
sty_uniq(m) => {
|
sty_uniq => {
|
||||||
ebml_w.writer.write(&[ '~' as u8 ]);
|
ebml_w.writer.write(&[ '~' as u8 ]);
|
||||||
encode_mutability(ebml_w, m);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ pub fn check_expr(sess: Session,
|
|||||||
if is_const {
|
if is_const {
|
||||||
match e.node {
|
match e.node {
|
||||||
expr_unary(_, deref, _) => { }
|
expr_unary(_, deref, _) => { }
|
||||||
expr_unary(_, box(_), _) | expr_unary(_, uniq(_), _) => {
|
expr_unary(_, box(_), _) | expr_unary(_, uniq, _) => {
|
||||||
sess.span_err(e.span,
|
sess.span_err(e.span,
|
||||||
"disallowed operator in constant expression");
|
"disallowed operator in constant expression");
|
||||||
return;
|
return;
|
||||||
|
@ -368,7 +368,7 @@ fn visit_fn(fk: &visit::fn_kind,
|
|||||||
match *fk {
|
match *fk {
|
||||||
fk_method(_, _, method) => {
|
fk_method(_, _, method) => {
|
||||||
match method.explicit_self.node {
|
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,
|
fn_maps.add_variable(Arg(method.self_id,
|
||||||
special_idents::self_));
|
special_idents::self_));
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::expr) -> ValueRef {
|
|||||||
let is_float = ty::type_is_fp(ty);
|
let is_float = ty::type_is_fp(ty);
|
||||||
return match u {
|
return match u {
|
||||||
ast::box(_) |
|
ast::box(_) |
|
||||||
ast::uniq(_) |
|
ast::uniq |
|
||||||
ast::deref => {
|
ast::deref => {
|
||||||
let (dv, _dt) = const_deref(cx, te, ty, true);
|
let (dv, _dt) = const_deref(cx, te, ty, true);
|
||||||
dv
|
dv
|
||||||
|
@ -1314,7 +1314,7 @@ fn trans_unary_datum(bcx: block,
|
|||||||
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty,
|
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty,
|
||||||
heap_managed)
|
heap_managed)
|
||||||
}
|
}
|
||||||
ast::uniq(_) => {
|
ast::uniq => {
|
||||||
let heap = heap_for_unique(bcx, un_ty);
|
let heap = heap_for_unique(bcx, un_ty);
|
||||||
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap)
|
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap)
|
||||||
}
|
}
|
||||||
|
@ -532,7 +532,7 @@ pub fn trans_trait_callee(bcx: block,
|
|||||||
let llpair = match explicit_self {
|
let llpair = match explicit_self {
|
||||||
ast::sty_region(*) => Load(bcx, llpair),
|
ast::sty_region(*) => Load(bcx, llpair),
|
||||||
ast::sty_static | ast::sty_value |
|
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);
|
let callee_ty = node_id_type(bcx, callee_id);
|
||||||
@ -622,7 +622,7 @@ pub fn trans_trait_callee_from_llval(bcx: block,
|
|||||||
|
|
||||||
self_mode = ty::ByRef;
|
self_mode = ty::ByRef;
|
||||||
}
|
}
|
||||||
ast::sty_uniq(_) => {
|
ast::sty_uniq => {
|
||||||
// Pass the unique pointer.
|
// Pass the unique pointer.
|
||||||
match store {
|
match store {
|
||||||
ty::UniqTraitStore => llself = llbox,
|
ty::UniqTraitStore => llself = llbox,
|
||||||
|
@ -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) {
|
pub fn mark_for_expr(cx: &Context, e: &expr) {
|
||||||
match e.node {
|
match e.node {
|
||||||
expr_vstore(_, _) | expr_vec(_, _) | expr_struct(*) | expr_tup(_) |
|
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(*) => {
|
expr_binary(_, add, _, _) | expr_copy(_) | expr_repeat(*) => {
|
||||||
node_type_needs(cx, use_repr, e.id);
|
node_type_needs(cx, use_repr, e.id);
|
||||||
}
|
}
|
||||||
|
@ -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,
|
ty::mt {ty: self_info.untransformed_self_ty,
|
||||||
mutbl: mutability}))
|
mutbl: mutability}))
|
||||||
}
|
}
|
||||||
ast::sty_uniq(mutability) => {
|
ast::sty_uniq => {
|
||||||
Some(ty::mk_uniq(this.tcx(),
|
Some(ty::mk_uniq(this.tcx(),
|
||||||
ty::mt {ty: self_info.untransformed_self_ty,
|
ty::mt {ty: self_info.untransformed_self_ty,
|
||||||
mutbl: mutability}))
|
mutbl: ast::m_imm}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1123,11 +1123,11 @@ impl<'self> LookupContext<'self> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sty_uniq(m) => {
|
sty_uniq => {
|
||||||
debug!("(is relevant?) explicit self is a unique pointer");
|
debug!("(is relevant?) explicit self is a unique pointer");
|
||||||
match ty::get(rcvr_ty).sty {
|
match ty::get(rcvr_ty).sty {
|
||||||
ty::ty_uniq(mt) => {
|
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()
|
self.fcx.can_mk_subty(mt.ty, candidate.rcvr_ty).is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2301,7 +2301,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||||||
ast::expr_unary(callee_id, unop, oprnd) => {
|
ast::expr_unary(callee_id, unop, oprnd) => {
|
||||||
let exp_inner = do unpack_expected(fcx, expected) |sty| {
|
let exp_inner = do unpack_expected(fcx, expected) |sty| {
|
||||||
match unop {
|
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),
|
ty::ty_box(ref mt) | ty::ty_uniq(ref mt) => Some(mt.ty),
|
||||||
_ => None
|
_ => None
|
||||||
},
|
},
|
||||||
@ -2318,9 +2318,10 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||||||
oprnd_t = ty::mk_box(tcx,
|
oprnd_t = ty::mk_box(tcx,
|
||||||
ty::mt {ty: oprnd_t, mutbl: mutbl});
|
ty::mt {ty: oprnd_t, mutbl: mutbl});
|
||||||
}
|
}
|
||||||
ast::uniq(mutbl) => {
|
ast::uniq => {
|
||||||
oprnd_t = ty::mk_uniq(tcx,
|
oprnd_t = ty::mk_uniq(tcx,
|
||||||
ty::mt {ty: oprnd_t, mutbl: mutbl});
|
ty::mt {ty: oprnd_t,
|
||||||
|
mutbl: ast::m_imm});
|
||||||
}
|
}
|
||||||
ast::deref => {
|
ast::deref => {
|
||||||
let sty = structure_of(fcx, expr.span, oprnd_t);
|
let sty = structure_of(fcx, expr.span, oprnd_t);
|
||||||
|
@ -333,7 +333,7 @@ pub enum binop {
|
|||||||
#[deriving(Eq, Encodable, Decodable,IterBytes)]
|
#[deriving(Eq, Encodable, Decodable,IterBytes)]
|
||||||
pub enum unop {
|
pub enum unop {
|
||||||
box(mutability),
|
box(mutability),
|
||||||
uniq(mutability),
|
uniq,
|
||||||
deref,
|
deref,
|
||||||
not,
|
not,
|
||||||
neg
|
neg
|
||||||
@ -805,7 +805,7 @@ pub enum explicit_self_ {
|
|||||||
sty_value, // `self`
|
sty_value, // `self`
|
||||||
sty_region(Option<@Lifetime>, mutability), // `&'lt self`
|
sty_region(Option<@Lifetime>, mutability), // `&'lt self`
|
||||||
sty_box(mutability), // `@self`
|
sty_box(mutability), // `@self`
|
||||||
sty_uniq(mutability) // `~self`
|
sty_uniq // `~self`
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type explicit_self = spanned<explicit_self_>;
|
pub type explicit_self = spanned<explicit_self_>;
|
||||||
|
@ -135,7 +135,7 @@ pub fn is_shift_binop(b: binop) -> bool {
|
|||||||
pub fn unop_to_str(op: unop) -> ~str {
|
pub fn unop_to_str(op: unop) -> ~str {
|
||||||
match op {
|
match op {
|
||||||
box(mt) => if mt == m_mutbl { ~"@mut " } else { ~"@" },
|
box(mt) => if mt == m_mutbl { ~"@mut " } else { ~"@" },
|
||||||
uniq(mt) => if mt == m_mutbl { ~"~mut " } else { ~"~" },
|
uniq => ~"~",
|
||||||
deref => ~"*",
|
deref => ~"*",
|
||||||
not => ~"!",
|
not => ~"!",
|
||||||
neg => ~"-"
|
neg => ~"-"
|
||||||
|
@ -248,7 +248,7 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option<PtrTy>)
|
|||||||
let self_ty = respan(
|
let self_ty = respan(
|
||||||
span,
|
span,
|
||||||
match *ptr {
|
match *ptr {
|
||||||
Send => ast::sty_uniq(ast::m_imm),
|
Send => ast::sty_uniq,
|
||||||
Managed(mutbl) => ast::sty_box(mutbl),
|
Managed(mutbl) => ast::sty_box(mutbl),
|
||||||
Borrowed(ref lt, mutbl) => {
|
Borrowed(ref lt, mutbl) => {
|
||||||
let lt = lt.map(|s| @cx.lifetime(span,
|
let lt = lt.map(|s| @cx.lifetime(span,
|
||||||
|
@ -2071,9 +2071,8 @@ impl Parser {
|
|||||||
ex = match e.node {
|
ex = match e.node {
|
||||||
expr_vec(*) |
|
expr_vec(*) |
|
||||||
expr_lit(@codemap::spanned { node: lit_str(_), span: _}) |
|
expr_lit(@codemap::spanned { node: lit_str(_), span: _}) |
|
||||||
expr_repeat(*)
|
expr_repeat(*) => expr_vstore(e, expr_vstore_uniq),
|
||||||
if m == m_imm => expr_vstore(e, expr_vstore_uniq),
|
_ => self.mk_unary(uniq, e)
|
||||||
_ => self.mk_unary(uniq(m), e)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
_ => return self.parse_dot_or_call_expr()
|
_ => return self.parse_dot_or_call_expr()
|
||||||
@ -3366,7 +3365,12 @@ impl Parser {
|
|||||||
maybe_parse_explicit_self(sty_box, self)
|
maybe_parse_explicit_self(sty_box, self)
|
||||||
}
|
}
|
||||||
token::TILDE => {
|
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() => {
|
token::IDENT(*) if self.is_self_ident() => {
|
||||||
self.bump();
|
self.bump();
|
||||||
|
@ -1653,6 +1653,7 @@ pub fn print_explicit_self(s: @ps, explicit_self: ast::explicit_self_) -> bool {
|
|||||||
match explicit_self {
|
match explicit_self {
|
||||||
ast::sty_static => { return false; }
|
ast::sty_static => { return false; }
|
||||||
ast::sty_value => { word(s.s, "self"); }
|
ast::sty_value => { word(s.s, "self"); }
|
||||||
|
ast::sty_uniq => { word(s.s, "~self"); }
|
||||||
ast::sty_region(lt, m) => {
|
ast::sty_region(lt, m) => {
|
||||||
word(s.s, "&");
|
word(s.s, "&");
|
||||||
print_opt_lifetime(s, lt);
|
print_opt_lifetime(s, lt);
|
||||||
@ -1662,9 +1663,6 @@ pub fn print_explicit_self(s: @ps, explicit_self: ast::explicit_self_) -> bool {
|
|||||||
ast::sty_box(m) => {
|
ast::sty_box(m) => {
|
||||||
word(s.s, "@"); print_mutability(s, m); word(s.s, "self");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user