Make Rust type rules standalone functions#164
Conversation
| .find_map(ast::ReturnExpr::cast) | ||
| .and_then(|ret| ret.expr()) | ||
| .or_else(|| body.stmt_list().and_then(|sl| sl.tail_expr())) | ||
| .expect("type rule must yield an initializer"); |
There was a problem hiding this comment.
I think we should add an assert or change init to only accept { X }, not { return X; } or other type of expressions.
There was a problem hiding this comment.
Aren't these two alternatives equivalent in practice? I opted to accept both options because I thought the added flexibility might be useful in the future, particularly when generating these rules automatically. Even if that doesn't turn out to be the case, what would be the disadvantages of allowing both forms?
There was a problem hiding this comment.
Even if that doesn't turn out to be the case, what would be the disadvantages of allowing both forms?
None, { X } just feels more natural
There was a problem hiding this comment.
Should I change it to only allow that form then?
There was a problem hiding this comment.
Yes, please. And also make sure that we only support:
fn t<digit>() -> TYPE {
DEFAULT-INITIALIZER
}not
fn t<digit>() -> TYPE {
expr1;
expr2;
...
DEFAULT-INITIALIZER
}f39b9f1 to
1a223c7
Compare
Changes the format of the Rust side of type rules to:
Actual changes to rules:
The initializer for the unsafe rules
t1,t2, andt3infstreamwas changed from::std::fs::File::open("")?to::std::fs::File::open("").unwrap(). This change was made because the?operator requires the function to return a value of typeResultorOption. Additionally, other rules for file-related types already use::std::fs::File::open("").unwrap()as an initializer (for example, rulet1iniostream).Added a missing generic parameter to the refcount rules
f10andf11inunique_ptr. These rules were relying on the struct defined at the top of the type.