-
Notifications
You must be signed in to change notification settings - Fork 61
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
Make clippy happier #57
base: master
Are you sure you want to change the base?
Changes from all commits
6c0bcc6
ba1df75
5228453
19a2c1f
1441e73
be56ab8
3f3aa59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,6 @@ impl SyntaxText { | |
} | ||
|
||
pub fn char_at(&self, offset: TextSize) -> Option<char> { | ||
let offset = offset.into(); | ||
let mut start: TextSize = 0.into(); | ||
let res = self.try_for_each_chunk(|chunk| { | ||
let end = start + TextSize::of(chunk); | ||
|
@@ -59,7 +58,7 @@ impl SyntaxText { | |
|
||
pub fn slice<R: private::SyntaxTextRange>(&self, range: R) -> SyntaxText { | ||
let start = range.start().unwrap_or_default(); | ||
let end = range.end().unwrap_or(self.len()); | ||
let end = range.end().unwrap_or_else(|| self.len()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. false positive imo |
||
assert!(start <= end); | ||
let len = end - start; | ||
let start = self.range.start() + start; | ||
|
@@ -97,6 +96,7 @@ impl SyntaxText { | |
|
||
pub fn for_each_chunk<F: FnMut(&str)>(&self, mut f: F) { | ||
enum Void {} | ||
#[allow(clippy::unit_arg)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am pretty 👎 on silencing clippy lints in code. I think this is a point where it clearly becomes a hindrance rather than a helper. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if I take a fully opposite position, but I do see value in locally allowing lints. For one, it's explicitly saying "yes, this may be weird, but it's intended." Secondly, and more importantly to me, is that a linter is most useful when it's silent. Warnings are a lot more useful when you only have a few and plan to address them all. Not suppressing false positives is how you get warning fatigue and ignoring new lints. Anecdotal case in point is that the 10 or so clippy warnings this PR fixes were already enough to make me change my check workflow when working with rowan from In another formulation, imho, the lack of silencing the clippy lint harms clippy's usefulness more than some The TL;DR is that clippy has false positives, as a consequence of its design. The options are either to allow some lints sometimes or allow the false positives to overwhelm any useful information the linter provides. That said, I'd be fine yeeting the two problematic commits and either globally allowing those lints or just stopping trying to use clippy on rowan, depending on your preference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is going to get a tad too philosophical, so bear with me.... (but the TL;DR is that I don't find clippy useful in this context). I feel that the general "use linters" advice is too religiously carried over to Rust. In languages like In Rust, however, everything really important is already handled by compiler. For a user, who is already familiar with Rust idioms, majority of clippy suggestions are just a wash. Like in this PR:
The overall theme here is that clippy makes me change my code, without making it better. It creates noise, and I think that noise has a pretty high cost. Similarly, explicit What I can get behind is conservative clippy profile, consisting of a lints which are candidates for inclusion in the compiler. IIRC, there's no such clippy profile yet. What we do in rust-analyzer is that we define, globally, the list of disabled lints: But we still don't run clippy on CI, as I find that would be mostly waste of time. Where clippy shines is when teaching new users Rust idioms, but this use case is different. I guess the bottom line is that I am 👎 on running clippy on CI, and, for this reason in particular, I don't want to see anything just to appease clippy in the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Chiming in from Clippy: The Clippy philosophy is that sprinkling of allows is encouraged, for the reason @CAD97 already stated: "The following code is intentional." I think disabling |
||
match self.try_for_each_chunk(|chunk| Ok::<(), Void>(f(chunk))) { | ||
Ok(()) => (), | ||
Err(void) => match void {}, | ||
|
@@ -285,10 +285,12 @@ mod tests { | |
fn do_check(t1: &[&str], t2: &[&str]) { | ||
let t1 = build_tree(t1).text(); | ||
let t2 = build_tree(t2).text(); | ||
let expected = t1.to_string() == t2.to_string(); | ||
let t1_s = t1.to_string(); | ||
let t2_s = t2.to_string(); | ||
let expected = t1_s == t2_s; | ||
let actual = t1 == t2; | ||
assert_eq!(expected, actual, "`{}` (SyntaxText) `{}` (SyntaxText)", t1, t2); | ||
let actual = t1 == &*t2.to_string(); | ||
let actual = t1 == t2_s.as_str(); | ||
assert_eq!(expected, actual, "`{}` (SyntaxText) `{}` (&str)", t1, t2); | ||
} | ||
fn check(t1: &[&str], t2: &[&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.