Change convention for specifying referenced argument

It is now 1-based, rather than 0 based. (Seems more natural, and allows 0 to
be used to refer to self and maybe to closure.)

Also allows non-referenced args to be implicitly copied again.

Issue #918
This commit is contained in:
Marijn Haverbeke 2011-09-16 12:42:18 +02:00
parent 059b31f7a3
commit d7587c1eda
5 changed files with 34 additions and 22 deletions

View file

@ -448,16 +448,19 @@ fn parse_ret_ty(p: parser, n_args: uint) -> (ast::ret_style, @ast::ty) {
if n_args == 0u {
p.fatal("can not return reference from argument-less fn");
}
let mut_root = eat(p, token::NOT), arg = 0u;
let mut_root = eat(p, token::NOT), arg = 1u;
alt p.peek() {
token::LIT_INT(val) { p.bump(); arg = val as uint; }
_ { if n_args > 1u {
p.fatal("must specify referenced parameter");
} }
}
if arg >= n_args {
if arg > n_args {
p.fatal("referenced argument does not exist");
}
if arg == 0u {
p.fatal("referenced argument can't be 0");
}
style = ast::return_ref(mut_root, arg);
};
(style, parse_ty(p, false))