Implement mut in arguments

This commit is contained in:
Seo Sanghyeon 2013-01-04 13:20:56 +09:00 committed by Tim Chevalier
parent d10b5c725b
commit 800b8a759d
2 changed files with 10 additions and 12 deletions

View File

@ -453,18 +453,19 @@ 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
@ -472,7 +473,7 @@ impl &mem_categorization_ctxt {
// 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,

View File

@ -4104,9 +4104,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);
@ -4295,12 +4297,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);