fehler icon indicating copy to clipboard operation
fehler copied to clipboard

Detect and reject method impl without body.

Open gmadrid opened this issue 5 years ago • 4 comments

Fixes #39

This is some ugly Rust. I have always found the interaction of if and if let to be a bit awkward. I'm very interested in seeing how you clean this up.

Love fehler. Totally agree with your arguments in your article.

gmadrid avatar Apr 14 '20 17:04 gmadrid

Instead of rejecting it, could we make it generate a modified method signature with no body?

withoutboats avatar Apr 14 '20 22:04 withoutboats

Also, it's not ugly. :) Manipulating Rust's very complex AST just requires code like this to handle all of the special cases.

withoutboats avatar Apr 14 '20 22:04 withoutboats

I frequently want to write code like 'if let Some(foo) = bar && foo.blah() != 3' but I can't, so I have to nest another if inside it which complicates the data flow in a way that I find less functional and therefore a little less clear. I was kind of hoping you'd "clean it up" and I'd see how you handle this. You have a lot more Rust experience than I do.

gmadrid avatar Apr 15 '20 00:04 gmadrid

There's not really a better way around it. Well, for the example you gave, this could be more elegant:

match bar {
    Some(foo) if foo.blah() != 3 => { ... }
    _ => {}
}

But in cases like this one, where the conditional is not the binding from the match, that would be confusing.

withoutboats avatar Apr 15 '20 01:04 withoutboats