Skip to content

Issue 3488 #4346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl ast::def: tr {
ast::def_mod(did) => { ast::def_mod(did.tr(xcx)) }
ast::def_foreign_mod(did) => { ast::def_foreign_mod(did.tr(xcx)) }
ast::def_const(did) => { ast::def_const(did.tr(xcx)) }
ast::def_arg(nid, m) => { ast::def_arg(xcx.tr_id(nid), m) }
ast::def_arg(nid, m, b) => { ast::def_arg(xcx.tr_id(nid), m, b) }
ast::def_local(nid, b) => { ast::def_local(xcx.tr_id(nid), b) }
ast::def_variant(e_did, v_did) => {
ast::def_variant(e_did.tr(xcx), v_did.tr(xcx))
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 @@ -283,7 +283,7 @@ enum VarKind {
fn relevant_def(def: def) -> Option<node_id> {
match def {
def_binding(nid, _) |
def_arg(nid, _) |
def_arg(nid, _, _) |
def_local(nid, _) |
def_self(nid, _) => Some(nid),

Expand Down
11 changes: 6 additions & 5 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,26 +583,27 @@ impl &mem_categorization_ctxt {
mutbl:m_imm, ty:expr_ty}
}

ast::def_arg(vid, mode) => {
ast::def_arg(vid, mode, mutbl) => {
// Idea: make this could be rewritten to model by-ref
// stuff as `&const` and `&mut`?

// m: mutability of the argument
// lp: loan path, must be none for aliasable things
let {m,lp} = match ty::resolved_mode(self.tcx, mode) {
let m = if mutbl {m_mutbl} else {m_imm};
let lp = match ty::resolved_mode(self.tcx, mode) {
ast::by_move | ast::by_copy => {
{m: m_imm, lp: Some(@lp_arg(vid))}
Some(@lp_arg(vid))
}
ast::by_ref => {
{m: m_imm, lp: None}
None
}
ast::by_val => {
// by-value is this hybrid mode where we have a
// pointer but we do not own it. This is not
// considered loanable because, for example, a by-ref
// and and by-val argument might both actually contain
// the same unique ptr.
{m: m_imm, lp: None}
None
}
};
@{id:id, span:span,
Expand Down
14 changes: 6 additions & 8 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4154,9 +4154,11 @@ impl Resolver {
for declaration.inputs.each |argument| {
let binding_mode =
ArgumentIrrefutableMode(argument.mode);
let mutability =
if argument.is_mutbl {Mutable} else {Immutable};
self.resolve_pattern(argument.pat,
binding_mode,
Immutable,
mutability,
None,
visitor);

Expand Down Expand Up @@ -4340,12 +4342,7 @@ impl Resolver {
}

fn resolve_local(local: @local, visitor: ResolveVisitor) {
let mut mutability;
if local.node.is_mutbl {
mutability = Mutable;
} else {
mutability = Immutable;
}
let mutability = if local.node.is_mutbl {Mutable} else {Immutable};

// Resolve the type.
self.resolve_type(local.node.ty, visitor);
Expand Down Expand Up @@ -4606,7 +4603,8 @@ impl Resolver {
}
ArgumentIrrefutableMode(argument_mode) => {
// And for function arguments, `def_arg`.
def_arg(pattern.id, argument_mode)
def_arg(pattern.id, argument_mode,
is_mutable)
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,7 @@ fn trans_enum_variant(ccx: @crate_ctxt,
// Translate variant arguments to function arguments.
let fn_args = vec::map(args, |varg|
{mode: ast::expl(ast::by_copy),
is_mutbl: false,
ty: varg.ty,
pat: ast_util::ident_to_pat(ccx.tcx.sess.next_node_id(),
ast_util::dummy_sp(),
Expand Down Expand Up @@ -1766,6 +1767,7 @@ fn trans_tuple_struct(ccx: @crate_ctxt,
let fn_args = do fields.map |field| {
{
mode: ast::expl(ast::by_copy),
is_mutbl: false,
ty: field.node.ty,
pat: ast_util::ident_to_pat(ccx.tcx.sess.next_node_id(),
ast_util::dummy_sp(),
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 @@ -830,7 +830,7 @@ fn trans_local_var(bcx: block,
}
}
}
ast::def_arg(nid, _) => {
ast::def_arg(nid, _, _) => {
take_local(bcx, bcx.fcx.llargs, nid, expr_id_opt)
}
ast::def_local(nid, _) | ast::def_binding(nid, _) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2740,7 +2740,7 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
ty_param_bounds_and_ty {

match defn {
ast::def_arg(nid, _) | ast::def_local(nid, _) |
ast::def_arg(nid, _, _) | ast::def_local(nid, _) |
ast::def_self(nid, _) | ast::def_binding(nid, _) => {
assert (fcx.inh.locals.contains_key(nid));
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, nid));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type rvt = visit::vt<@rcx>;
fn encl_region_of_def(fcx: @fn_ctxt, def: ast::def) -> ty::Region {
let tcx = fcx.tcx();
match def {
def_local(node_id, _) | def_arg(node_id, _) | def_self(node_id, _) |
def_binding(node_id, _) =>
def_local(node_id, _) | def_arg(node_id, _, _) |
def_self(node_id, _) | def_binding(node_id, _) =>
return encl_region(tcx, node_id),
def_upvar(_, subdef, closure_id, body_id) => {
match ty_fn_proto(fcx.node_ty(closure_id)) {
Expand Down
9 changes: 5 additions & 4 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ enum def {
def_mod(def_id),
def_foreign_mod(def_id),
def_const(def_id),
def_arg(node_id, mode),
def_arg(node_id, mode, bool /* is_mutbl */),
def_local(node_id, bool /* is_mutbl */),
def_variant(def_id /* enum */, def_id /* variant */),
def_ty(def_id),
Expand Down Expand Up @@ -191,9 +191,10 @@ impl def : cmp::Eq {
_ => false
}
}
def_arg(e0a, e1a) => {
def_arg(e0a, e1a, e2a) => {
match (*other) {
def_arg(e0b, e1b) => e0a == e0b && e1a == e1b,
def_arg(e0b, e1b, e2b) =>
e0a == e0b && e1a == e1b && e2a == e2b,
_ => false
}
}
Expand Down Expand Up @@ -1138,7 +1139,7 @@ impl Ty : to_bytes::IterBytes {

#[auto_encode]
#[auto_decode]
type arg = {mode: mode, ty: @Ty, pat: @pat, id: node_id};
type arg = {mode: mode, is_mutbl: bool, ty: @Ty, pat: @pat, id: node_id};

#[auto_encode]
#[auto_decode]
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 @@ -81,7 +81,7 @@ pure fn def_id_of_def(d: def) -> def_id {
def_use(id) | def_struct(id) => {
id
}
def_arg(id, _) | def_local(id, _) | def_self(id, _) | def_self_ty(id)
def_arg(id, _, _) | def_local(id, _) | def_self(id, _) | def_self_ty(id)
| def_upvar(id, _, _, _) | def_binding(id, _) | def_region(id)
| def_typaram_binder(id) | def_label(id) => {
local_def(id)
Expand Down
3 changes: 3 additions & 0 deletions src/libsyntax/ext/auto_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ fn mk_ser_method(

let ser_inputs = ~[{
mode: ast::infer(cx.next_id()),
is_mutbl: false,
ty: ty_s,
pat: @{id: cx.next_id(),
node: ast::pat_ident(
Expand Down Expand Up @@ -600,6 +601,7 @@ fn mk_deser_method(

let deser_inputs = ~[{
mode: ast::infer(cx.next_id()),
is_mutbl: false,
ty: ty_d,
pat: @{id: cx.next_id(),
node: ast::pat_ident(
Expand Down Expand Up @@ -1120,6 +1122,7 @@ fn mk_enum_deser_body(
{
inputs: ~[{
mode: ast::infer(cx.next_id()),
is_mutbl: false,
ty: @{
id: cx.next_id(),
node: ast::ty_infer,
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ fn mk_arg(cx: ext_ctxt,
let arg_pat = mk_pat_ident(cx, span, ident);
{
mode: ast::infer(cx.next_id()),
is_mutbl: false,
ty: ty,
pat: arg_pat,
id: cx.next_id()
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/pipes/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {

fn arg(name: ident, ty: @ast::Ty) -> ast::arg {
{mode: ast::infer(self.next_id()),
is_mutbl: false,
ty: ty,
pat: @{id: self.next_id(),
node: ast::pat_ident(
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fn fold_attribute_(at: attribute, fld: ast_fold) ->
//used in noop_fold_foreign_item and noop_fold_fn_decl
fn fold_arg_(a: arg, fld: ast_fold) -> arg {
return {mode: a.mode,
is_mutbl: a.is_mutbl,
ty: fld.fold_ty(a.ty),
pat: fld.fold_pat(a.pat),
id: fld.new_id(a.id)};
Expand Down
7 changes: 5 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,10 @@ impl Parser {
// identifier names.
fn parse_arg_general(require_name: bool) -> arg {
let mut m;
let mut is_mutbl = false;
let pat = if require_name || self.is_named_argument() {
m = self.parse_arg_mode();
is_mutbl = self.eat_keyword(~"mut");
let pat = self.parse_pat(false);
self.expect(token::COLON);
pat
Expand All @@ -698,7 +700,7 @@ impl Parser {

let t = self.parse_ty(false);

{mode: m, ty: t, pat: pat, id: self.get_id()}
{mode: m, is_mutbl: is_mutbl, ty: t, pat: pat, id: self.get_id()}
}

fn parse_arg() -> arg_or_capture_item {
Expand All @@ -720,7 +722,8 @@ impl Parser {
node: ty_infer,
span: mk_sp(p.span.lo, p.span.hi)}
};
either::Left({mode: m, ty: t, pat: pat, id: p.get_id()})
either::Left({mode: m, is_mutbl: false, ty: t, pat: pat,
id: p.get_id()})
}
}

Expand Down