You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like the option to force all branches of all functions to use the optional return keyword.
Motivation
I think explicitly stating return rather than relying on the implicit behavior of {} blocks makes code easier to understand at a glance, and especially if there are complicated branching statements inside. (Admittedly, this is mostly a style preference, so I understand that it probably won't be a high-priority change.)
For a toy example, the proposed formatting option should change this:
fnadd_one(x:u32) -> u32{
x + 1}fnfoo() -> (){println!("This function has no return value!");}
to this:
fnadd_one(x:u32) -> u32{return x + 1;}fnfoo() -> (){println!("This function has no return value!");return;}
This syntax is more familiar to developers with backgrounds in other languages, such as C/C++, and follows the common Rust pattern that explicit is better than implicit.
Related configuration options
I wasn't able to find anything that was directly related to my proposed option, but it would follow in the spirit of options like force_explicit_abi.
Activity