Add syntax and representation for return-by-mutably-rooted-ref
This will be used in the near future to decide what can safely be done with the returned reference. Issue #918
This commit is contained in:
parent
1cabe37155
commit
93de2f0b74
11 changed files with 55 additions and 34 deletions
|
|
@ -381,7 +381,7 @@ 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;
|
||||
return_ref(bool);
|
||||
}
|
||||
|
||||
type _fn = {decl: fn_decl, proto: proto, body: blk};
|
||||
|
|
|
|||
|
|
@ -213,6 +213,13 @@ fn ternary_to_if(e: @expr) -> @expr {
|
|||
}
|
||||
}
|
||||
|
||||
fn ret_by_ref(style: ret_style) -> bool {
|
||||
alt style {
|
||||
return_ref(_) { true }
|
||||
_ { false }
|
||||
}
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
// fill-column: 78;
|
||||
|
|
|
|||
|
|
@ -445,7 +445,7 @@ fn parse_ret_ty(p: parser) -> (ast::ret_style, @ast::ty) {
|
|||
} else {
|
||||
let style = ast::return_val;
|
||||
if eat(p, token::BINOP(token::AND)) {
|
||||
style = ast::return_ref;
|
||||
style = ast::return_ref(eat(p, token::NOT));
|
||||
};
|
||||
(style, parse_ty(p, false))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1224,7 +1224,10 @@ 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, "->");
|
||||
if decl.cf == ast::return_ref { word(s.s, "&"); }
|
||||
alt decl.cf {
|
||||
ast::return_ref(mut) { word(s.s, mut ? "&!" : "&"); }
|
||||
_ {}
|
||||
}
|
||||
print_type(s, decl.output);
|
||||
}
|
||||
}
|
||||
|
|
@ -1423,7 +1426,10 @@ fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>,
|
|||
if cf == ast::noreturn {
|
||||
word_nbsp(s, "!")
|
||||
} else {
|
||||
if cf == ast::return_ref { word(s.s, "&"); }
|
||||
alt cf {
|
||||
ast::return_ref(mut) { word(s.s, mut ? "&!" : "&"); }
|
||||
_ {}
|
||||
}
|
||||
print_type(s, output);
|
||||
}
|
||||
end(s);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue