Use 'resource' rather than 'res' as a keyword
Resources are now defined like... resource fd(int n) { close(n); } Calling fd with an int will then produce a non-copyable value that, when dropped, will call close on the given int.
This commit is contained in:
parent
fb14afd5eb
commit
9561def209
4 changed files with 8 additions and 8 deletions
|
@ -139,7 +139,7 @@ fn bad_expr_word_table() -> hashmap[str, ()] {
|
||||||
words.insert("be", ());
|
words.insert("be", ());
|
||||||
words.insert("fail", ());
|
words.insert("fail", ());
|
||||||
words.insert("type", ());
|
words.insert("type", ());
|
||||||
words.insert("res", ());
|
words.insert("resource", ());
|
||||||
words.insert("check", ());
|
words.insert("check", ());
|
||||||
words.insert("assert", ());
|
words.insert("assert", ());
|
||||||
words.insert("claim", ());
|
words.insert("claim", ());
|
||||||
|
@ -2045,7 +2045,7 @@ fn parse_item(&parser p, vec[ast::attribute] attrs) -> parsed_item {
|
||||||
ret got_item(parse_item_tag(p, attrs));
|
ret got_item(parse_item_tag(p, attrs));
|
||||||
} else if (eat_word(p, "obj")) {
|
} else if (eat_word(p, "obj")) {
|
||||||
ret got_item(parse_item_obj(p, lyr, attrs));
|
ret got_item(parse_item_obj(p, lyr, attrs));
|
||||||
} else if (eat_word(p, "res")) {
|
} else if (eat_word(p, "resource")) {
|
||||||
ret got_item(parse_item_res(p, lyr, attrs));
|
ret got_item(parse_item_res(p, lyr, attrs));
|
||||||
} else { ret no_item; }
|
} else { ret no_item; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// error-pattern:Copying a non-copyable type
|
// error-pattern:Copying a non-copyable type
|
||||||
|
|
||||||
res foo(int i) {}
|
resource foo(int i) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
auto x <- foo(10);
|
auto x <- foo(10);
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
|
|
||||||
// Tests for alt as expressions resulting in boxed types
|
// Tests for alt as expressions resulting in boxed types
|
||||||
fn test_box() {
|
fn test_box() {
|
||||||
auto rs = alt (true) { case (true) { @100 } };
|
auto res = alt (true) { case (true) { @100 } };
|
||||||
assert (*rs == 100);
|
assert (*res == 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_str() {
|
fn test_str() {
|
||||||
auto rs = alt (true) { case (true) { "happy" } };
|
auto res = alt (true) { case (true) { "happy" } };
|
||||||
assert (rs == "happy");
|
assert (res == "happy");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() { test_box(); test_str(); }
|
fn main() { test_box(); test_str(); }
|
|
@ -1,4 +1,4 @@
|
||||||
res shrinky_pointer(@mutable int i) {
|
resource shrinky_pointer(@mutable int i) {
|
||||||
*i -= 1;
|
*i -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue