deny implicit returns #228
Replies: 3 comments
-
@cedricchevalier19 @franck-ledoux @dssgabriel opinions? |
Beta Was this translation helpful? Give feedback.
-
While it.map(|x| x * 2);
let foo = if bar > baz {
7
} else {
42
}; Explicit From what I've read, Rust preferred code style is to use expressions instead of explicit
However, I agree that this may create inconsistencies in the code and affect readability. Some people also complain about fn find_foo(&self, bars: Vec<Foo>) -> Foo {
bars.into_iter().find(|bar| {
bar.baz == self.baz
})
} gets formatted as: fn find_foo(&self, bars: Vec<Foo>) -> Foo {
bars.into_iter().find(|bar| bar.baz == self.baz)
} IMHO, at the end of the day this is just personal style and either one is fine. If you decide to go the "explicit return" route though, you may consider allowing Some discussions about the subject you may find worthwhile reading: |
Beta Was this translation helpful? Give feedback.
-
I absolutely forgot these cases were technically returns, but from blocks.
w.r.t. the above, a solution could be to allow |
Beta Was this translation helpful? Give feedback.
-
Rust allows implicit return at the end of function:
While I think this is acceptable for small code bases, it creates inconsistencies and poor readability when complex control flow is involved. It is possible to deny this syntax using a clippy lint (
clippy::implicit_return
).Should we enforce this rule? I personally prefer explicit returns, so I'm not sure if this is justified or if I am rationalizing too much.
Beta Was this translation helpful? Give feedback.
All reactions