Skip to content

Commit 800b8a7

Browse files
sanxiyncatamorphism
authored andcommitted
Implement mut in arguments
1 parent d10b5c7 commit 800b8a7

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/librustc/middle/mem_categorization.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,26 +453,27 @@ impl &mem_categorization_ctxt {
453453
mutbl:m_imm, ty:expr_ty}
454454
}
455455

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

460460
// m: mutability of the argument
461461
// lp: loan path, must be none for aliasable things
462-
let {m,lp} = match ty::resolved_mode(self.tcx, mode) {
462+
let m = if mutbl {m_mutbl} else {m_imm};
463+
let lp = match ty::resolved_mode(self.tcx, mode) {
463464
ast::by_move | ast::by_copy => {
464-
{m: m_imm, lp: Some(@lp_arg(vid))}
465+
Some(@lp_arg(vid))
465466
}
466467
ast::by_ref => {
467-
{m: m_imm, lp: None}
468+
None
468469
}
469470
ast::by_val => {
470471
// by-value is this hybrid mode where we have a
471472
// pointer but we do not own it. This is not
472473
// considered loanable because, for example, a by-ref
473474
// and and by-val argument might both actually contain
474475
// the same unique ptr.
475-
{m: m_imm, lp: None}
476+
None
476477
}
477478
};
478479
@{id:id, span:span,

src/librustc/middle/resolve.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4104,9 +4104,11 @@ impl Resolver {
41044104
for declaration.inputs.each |argument| {
41054105
let binding_mode =
41064106
ArgumentIrrefutableMode(argument.mode);
4107+
let mutability =
4108+
if argument.is_mutbl {Mutable} else {Immutable};
41074109
self.resolve_pattern(argument.pat,
41084110
binding_mode,
4109-
Immutable,
4111+
mutability,
41104112
None,
41114113
visitor);
41124114

@@ -4295,12 +4297,7 @@ impl Resolver {
42954297
}
42964298

42974299
fn resolve_local(local: @local, visitor: ResolveVisitor) {
4298-
let mut mutability;
4299-
if local.node.is_mutbl {
4300-
mutability = Mutable;
4301-
} else {
4302-
mutability = Immutable;
4303-
}
4300+
let mutability = if local.node.is_mutbl {Mutable} else {Immutable};
43044301

43054302
// Resolve the type.
43064303
self.resolve_type(local.node.ty, visitor);

0 commit comments

Comments
 (0)