add: optional-fn-return-type - #406
Conversation
|
Thanks for contributing to formality! :) |
c3ce639 to
84015de
Compare
| let rest: Vec<TokenStream> = | ||
| chars.map(|c| quote!(__p.expect_char(#c)?;)).collect(); | ||
| (quote!(__p.expect_char(#first).is_ok()), quote!(#(#rest)*)) |
There was a problem hiding this comment.
| let rest: Vec<TokenStream> = | |
| chars.map(|c| quote!(__p.expect_char(#c)?;)).collect(); | |
| (quote!(__p.expect_char(#first).is_ok()), quote!(#(#rest)*)) | |
| ( | |
| quote!(__p.expect_char(#first).is_ok()), | |
| quote!(#(__p.expect_char(#chars)?;)*) | |
| ) |
I think maybe maybe you can just do this?
| } | ||
| } | ||
|
|
||
| /// The default type is the unit type `()`. |
There was a problem hiding this comment.
Hmm, I am not sure if we want a default for Ty that is always unit. It's convenient here but it might not be correct elsewhere. Let's have a new type like
struct OutputTy { ty: Ty }
impl Upcast<Ty> for OutputTy { }
impl Default for OutputTy { }and then change output_ty: OutputTy
There was a problem hiding this comment.
Ok , will do . Thanks!
|
@nikomatsakis I am sorry , I really got a bit busy and forgot about this . I will try to implement the suggested changes asap. Thank you! |
|
@xonx4l no worries! |
This comment has been minimized.
This comment has been minimized.
84015de to
cb28bf5
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@nikomatsakis sorry it took a while , made all the requested changes . Thank you! |
What does this PR do?
This PR implements optional function return type as discussed in #393
e.g., closes #393
How does it work, what questions do you have?
Functions can now be written
fn foo() { }instead of requiringfn foo() -> () { }. When the return type is omitted, it defaults to the unit type().Added tests demonstrating that
fn run() {trusted}parses identically tofn run() -> () {trusted}.AI disclosure