diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-11-23 10:56:10 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-11-23 11:02:27 +0100 |
| commit | 9fb3719ded8d6938c21710d4b487ab1328c7dd5e (patch) | |
| tree | 6612e313512e59a050093108962e371616d0eab9 /src/comp/syntax | |
| parent | acbc4aa9f8f46545c8c11422c62b392e3ef64cf5 (diff) | |
| download | rust-9fb3719ded8d6938c21710d4b487ab1328c7dd5e.tar.gz rust-9fb3719ded8d6938c21710d4b487ab1328c7dd5e.zip | |
Rollback return-by-reference
It's proving too inflexible, so I'm ripping out the extra complexity in the hope that regions will, at some point, provide something similar. Closes #918
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/ast.rs | 1 | ||||
| -rw-r--r-- | src/comp/syntax/ast_util.rs | 7 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 30 | ||||
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 23 |
4 files changed, 6 insertions, 55 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index dfebf9135fd..b1e1a16c6af 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -397,7 +397,6 @@ tag ret_style { noreturn; // functions with return type _|_ that always // raise an error or exit (i.e. never return to the caller) return_val; // everything else - return_ref(bool, uint); } type _fn = {decl: fn_decl, proto: proto, body: blk}; diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index c68092da90d..862d182b9fd 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -223,13 +223,6 @@ fn ternary_to_if(e: @expr) -> @expr { } } -fn ret_by_ref(style: ret_style) -> bool { - alt style { - return_ref(_, _) { true } - _ { false } - } -} - fn ty_param_kind(tp: ty_param) -> kind { tp.kind } fn compare_lit(a: @lit, b: @lit) -> int { diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 35c1e1190d3..391d5eb8819 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -295,7 +295,7 @@ fn parse_ty_fn(proto: ast::proto, p: parser) -> ast::ty_ { // FIXME: there's no syntax for this right now anyway // auto constrs = parse_constrs(~[], p); let constrs: [@ast::constr] = []; - let (ret_style, ret_ty) = parse_ret_ty(p, vec::len(inputs.node)); + let (ret_style, ret_ty) = parse_ret_ty(p); ret ast::ty_fn(proto, inputs.node, ret_ty, ret_style, constrs); } @@ -439,34 +439,12 @@ fn parse_ty_postfix(orig_t: ast::ty_, p: parser, colons_before_params: bool) } } -fn parse_ret_ty(p: parser, n_args: uint) -> (ast::ret_style, @ast::ty) { +fn parse_ret_ty(p: parser) -> (ast::ret_style, @ast::ty) { ret if eat(p, token::RARROW) { let lo = p.get_lo_pos(); if eat(p, token::NOT) { (ast::noreturn, @spanned(lo, p.get_last_hi_pos(), ast::ty_bot)) - } else { - let style = ast::return_val; - if eat(p, token::BINOP(token::AND)) { - if n_args == 0u { - p.fatal("can not return reference from argument-less fn"); - } - 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 { - 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)) - } + } else { (ast::return_val, parse_ty(p, false)) } } else { let pos = p.get_lo_pos(); (ast::return_val, @spanned(pos, pos, ast::ty_nil)) @@ -1791,7 +1769,7 @@ fn parse_fn_decl(p: parser, purity: ast::purity, il: ast::inlineness) -> p.bump(); constrs = parse_constrs({|x| parse_ty_constr(inputs.node, x) }, p); } - let (ret_style, ret_ty) = parse_ret_ty(p, vec::len(inputs.node)); + let (ret_style, ret_ty) = parse_ret_ty(p); ret {inputs: inputs.node, output: ret_ty, purity: purity, diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 7da57be4910..0fb5df69edb 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -1130,15 +1130,6 @@ fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl, constrs: [@ast::constr]) { if decl.output.node != ast::ty_nil { space_if_not_bol(s); word_space(s, "->"); - alt decl.cf { - ast::return_ref(mut, arg) { - word(s.s, mut ? "&!" : "&"); - if vec::len(decl.inputs) > 1u { - word_space(s, std::uint::str(arg)); - } - } - _ {} - } print_type(s, decl.output); } } @@ -1336,18 +1327,8 @@ fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>, space_if_not_bol(s); ibox(s, indent_unit); word_space(s, "->"); - if cf == ast::noreturn { - word_nbsp(s, "!"); - } else { - alt cf { - ast::return_ref(mut, arg) { - word(s.s, mut ? "&!" : "&"); - if vec::len(inputs) > 1u { word(s.s, std::uint::str(arg)); } - } - _ {} - } - print_type(s, output); - } + if cf == ast::noreturn { word_nbsp(s, "!"); } + else { print_type(s, output); } end(s); } word(s.s, ast_ty_fn_constrs_str(constrs)); |
