-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some clippy lints up to rust 1.41.1 #780
Conversation
dca881d
to
31f64cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this! It looks like the vast majority of the changes are in struct initialization. Those LGTM. Specifically:
It seems in some cases, struct initialization with redundant field: field was on purpose if one field (at least) was not redundant. This PR does "simplify" those cases, but that might not be wanted?
A lot of the code in this crate was written before the short-hand field initialization syntax was added, and I just never saw a good reason to go through and update everything. (And some of the code was even written before Rust 1.0.) So thank you for doing that. :-)
But there are a few changes I don't agree with. It's generally why I don't run Clippy and why it's not hooked up to CI either. I find it to be too opinionated and just haven't bothered to go through the list of lints to whitelist only the ones I agree with. And even if I agree with a lint generally, I don't always agree with its universal application. And that in turn requires allow
'ing lints within certain scopes which I find a bit annoying. So that's kind of another reason why I haven't started using Clippy.
If you can fix up some of the nits I had, then I'd be happy to merge this. Thanks again!
@@ -387,11 +388,11 @@ impl Compiler { | |||
} else { | |||
let entry = self.insts.len(); | |||
let hole = self.push_hole(InstHole::Save { slot: first_slot }); | |||
let patch = self.c(expr)?.unwrap_or(self.next_inst()); | |||
let patch = self.c(expr)?.unwrap_or_else(|| self.next_inst()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess these unwrap_or_else
s are fine, although, I suspect they don't really make a difference when it comes to perf, so I feel like this is another case of making the code more obtuse for no real reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the same kind of pattern (.unwrap_or_else(|| self.next_inst()))
) is repeated at least 4 times, it might be better to introduce a dedicated function? I'll try to look into it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly.
To be honest, this whole compiler is going to be thrown away "soon" as part of #656. The current state of that rewrite (not quite to parity yet) is here: https://github.com/BurntSushi/regex-automata/blob/c4fee38d7499721a2eccaa7074f21bf2c955cbce/src/nfa/thompson/compiler.rs
The rewrite is faster for the cases I've tested, generates more compact bytecode and is overall much clearer. (It does away with the whole InstHole
thing.)
So I think it's probably not wise to spend too much time refactoring or clarifying the code here. :-) With that said, a helper function sounds fine if you want to pursue that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have kept the unwrap_or_else
for those cases, I hope that's ok!
I fully agree with that statement, however it does find useful things sometime, so running it manually from time to time can be valuable.
I will make the requested change 👍 Another change I had in mind is to annotate the error enums which contain a |
Definitely agree there. I should do this more often.
I believe that, in principle, yes we should move to |
31f64cd
to
2d133a4
Compare
Some lints have been intentionally ignored, especially: * any lints that would change public APIs (like &self -> self) * any lints that would introduce new public APIs (like Default over new)
Some lints have been intentionally ignored, especially: * any lints that would change public APIs (like &self -> self) * any lints that would introduce new public APIs (like Default over new)
2d133a4
to
105761d
Compare
Some lints have been intentionally ignored, especially: * any lints that would change public APIs (like &self -> self) * any lints that would introduce new public APIs (like Default over new) Closes #780
Some lints have been intentionally ignored, especially:
&self
->self
)impl Default
overfn new()
)It seems in some cases, struct initialization with redundant
field: field
was on purpose if one field (at least) was not redundant. This PR does "simplify" those cases, but that might not be wanted?