-
Notifications
You must be signed in to change notification settings - Fork 466
Fix clippy warnings #376
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 clippy warnings #376
Conversation
src/re_bytes.rs
Outdated
@@ -785,6 +785,7 @@ pub struct Captures<'t> { | |||
named_groups: Arc<HashMap<String, usize>>, | |||
} | |||
|
|||
#[allow(len_without_is_empty)] |
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.
It's probably better to
fn is_empty(&self) -> bool {
debug_assert!(self.len() > 0);
false
}
as this will trigger const-folding and warnings should anyone expect captures to be empty
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 don't agree with adding a useless method to the public API.
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.
@lukaslueg Thanks so much for doing this. I realize it's a chore to do this, and I apologize in advance for being so picky about this stuff, but my comments probably show why I haven't really gotten on board the Clippy train.
At a high level, I agree with a lot of your changes. The amount of superfluous &
sigils is amusing, and I wonder if I can blame that on a bygone era when those were actually required.
But there are a number of things I flat out disagree with, and I think some of the transformations you made make the code less readable. On a different note, your use of the {debug_}?assert_ne!
macros requires a minimum Rust version bump, which I do not want to do at this time. We need to stick with Rust 1.12.
It seems like the way to express disagreement with Clippy is to pepper the code base with cfg'd attributes, and I simply do not want to deal with that. In principle, I'd be fine if it were rare, but this PR contains a lot of them. They have to go. If there is a way to add a config file to globally disable some lints, then I think I would be OK with the loss of precision.
@@ -9,6 +9,8 @@ macro_rules! regex { | |||
}} | |||
} | |||
|
|||
#[cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))] | |||
#[allow(regex_macro)] |
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 do not want to litter the examples directory with a bunch of clippy stuff. We need to find a way to remove this (similarly for the rest of the examples).
src/compile.rs
Outdated
@@ -1049,13 +1055,6 @@ impl ByteClassSet { | |||
} | |||
} | |||
|
|||
fn u32_to_usize(n: u32) -> usize { |
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.
Why did you get rid of this function? Please put it back. Without it, you've turned a hard error into a silent error.
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.
Actually, I think this is the only really useful warning by clippy for the whole codebase: The comparison always evaluates to false, making the check superfluous.
Why is it there anyway? if usize
is 32bit, n
can't be larger. If usize
is 64bit, n
can't be larger as well.
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.
It's a guard against the case when usize
is less than 32 bits. I'm not sure what the state of 16 bit usizes is in rustc, but IIRC people were interested in making it happen. It's certainly possible, so it seems worthwhile to be conservative.
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.
Shall I leave a comment about std::convert::TryFrom
?
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.
Sure.
src/compile.rs
Outdated
@@ -713,6 +713,12 @@ impl Compiler { | |||
} | |||
} | |||
|
|||
impl Default for Compiler { |
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.
Is this actually used anywhere? If not, I don't see any reason to add it.
src/dfa.rs
Outdated
@@ -271,7 +271,7 @@ struct State{ | |||
data: Box<[u8]>, | |||
} | |||
|
|||
/// InstPtr is a 32 bit pointer into a sequence of opcodes (i.e., it indexes | |||
/// `InstPt`r is a 32 bit pointer into a sequence of opcodes (i.e., it indexes |
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.
Looks like the ending backtick is in the wrong spot.
(I really don't see why every single identifier needs to be put in backticks. These comments aren't public, so they'll never be rendered anyway.)
src/dfa.rs
Outdated
@@ -482,7 +484,7 @@ impl<'a> Fsm<'a> { | |||
Some(STATE_DEAD) => return Result::NoMatch(at), | |||
Some(si) => si, | |||
}; | |||
debug_assert!(dfa.start != STATE_UNKNOWN); | |||
debug_assert_ne!(dfa.start, STATE_UNKNOWN); |
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.
debug_assert_ne!
was added in Rust 1.13. regex 0.2's minimum support Rust version is 1.12. You'll need to revert all uses of debug_assert_ne!
and assert_ne!
.
src/re_bytes.rs
Outdated
@@ -785,6 +785,7 @@ pub struct Captures<'t> { | |||
named_groups: Arc<HashMap<String, usize>>, | |||
} | |||
|
|||
#[allow(len_without_is_empty)] |
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 don't agree with adding a useless method to the public API.
src/re_bytes.rs
Outdated
@@ -986,7 +987,7 @@ pub trait Replacer { | |||
/// be beneficial to avoid finding sub-captures. | |||
/// | |||
/// In general, this is called once for every call to `replacen`. | |||
fn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, [u8]>> { | |||
fn no_expansion(&mut self) -> Option<Cow<[u8]>> { |
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.
Please put the lifetimes back. I don't mind elision in simple cases, but I'd rather the lifetime parameter be explicit here, especially in the trait definition.
src/re_trait.rs
Outdated
self, | ||
text: &'t Self::Text, | ||
) -> CaptureMatches<'t, Self> { | ||
text: & Self::Text, |
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.
There's an extra space here.
src/re_unicode.rs
Outdated
@@ -1198,7 +1199,7 @@ pub trait Replacer { | |||
/// be beneficial to avoid finding sub-captures. | |||
/// | |||
/// In general, this is called once for every call to `replacen`. | |||
fn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, str>> { | |||
fn no_expansion(&mut self) -> Option<Cow<str>> { |
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.
As with above, please put the lifetime back. Leaving it off the implementations is fine.
tests/api.rs
Outdated
@@ -1,36 +1,48 @@ | |||
#[test] | |||
#[cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))] | |||
#[allow(trivial_regex, string_lit_as_bytes)] |
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.
No, I'm sorry, I cannot abide peppering attributes everywhere for Clippy. These have to go. If that means we don't get clean Clippy output, then we'll just have to live with that.
Don't hesitate to let me know of needed changes, it's just a few hunk-jumps :-) |
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.
@lukaslueg Thanks so much! This is looking much better. :-) Unfortunately, I spotted one more nit that I didn't see last time. (I suspect it was accidental.)
src/lib.rs
Outdated
@@ -432,9 +432,9 @@ These classes are based on the definitions provided in | |||
<pre class="rust"> | |||
\d digit (\p{Nd}) | |||
\D not digit | |||
\s whitespace (\p{White_Space}) | |||
\s whitespace (\p{`White_Space`}) |
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.
Oh hmm, I don't think you should be using back ticks here.
src/lib.rs
Outdated
\S not whitespace | ||
\w word character (\p{Alphabetic} + \p{M} + \d + \p{Pc} + \p{Join_Control}) | ||
\w word character (\p{Alphabetic} + \p{M} + \d + \p{Pc} + \p{`Join_Control`}) |
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.
Or here. :-)
@bors r+ |
📌 Commit fbb2ba7 has been approved by |
Fix clippy warnings This fixes all clippy warnings, mostly lifetime elisions and useless borrows. Clippy now passes on nightly; on stable/without clippy, no lint warnings are given. All tests still pass. I've not moved any code around, which is the reason for allowing `string_lit_as_bytes` in so many places. Up for review
☀️ Test successful - status-appveyor, status-travis |
This fixes all clippy warnings, mostly lifetime elisions and useless borrows. Clippy now passes on nightly; on stable/without clippy, no lint warnings are given. All tests still pass.
I've not moved any code around, which is the reason for allowing
string_lit_as_bytes
in so many places.Up for review