mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Merge #10440
10440: Fix Clippy warnings and replace some `if let`s with `match` r=Veykril a=arzg I decided to try fixing a bunch of Clippy warnings. I am aware of this project’s opinion of Clippy (I have read both [rust-lang/clippy#5537](https://github.com/rust-lang/rust-clippy/issues/5537) and [rust-analyzer/rowan#57 (comment)](https://github.com/rust-analyzer/rowan/pull/57#discussion_r415676159)), so I totally understand if part of or the entirety of this PR is rejected. In particular, I can see how the semicolons and `if let` vs `match` commits provide comparatively little benefit when compared to the ensuing churn. I tried to separate each kind of change into its own commit to make it easier to discard certain changes. I also only applied Clippy suggestions where I thought they provided a definite improvement to the code (apart from semicolons, which is IMO more of a formatting/consistency question than a linting question). In the end I accumulated a list of 28 Clippy lints I ignored entirely. Sidenote: I should really have asked about this on Zulip before going through all 1,555 `if let`s in the codebase to decide which ones definitely look better as `match` :P Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
This commit is contained in:
commit
86c534f244
95 changed files with 399 additions and 478 deletions
|
@ -43,7 +43,7 @@ impl AssertLinear {
|
|||
}
|
||||
|
||||
pub fn sample(&mut self, x: f64, y: f64) {
|
||||
self.rounds.last_mut().unwrap().samples.push((x, y))
|
||||
self.rounds.last_mut().unwrap().samples.push((x, y));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ impl Drop for AssertLinear {
|
|||
for round in &self.rounds {
|
||||
eprintln!("\n{}", round.plot);
|
||||
}
|
||||
panic!("Doesn't look linear!")
|
||||
panic!("Doesn't look linear!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,14 +142,14 @@ impl Fixture {
|
|||
|
||||
if line.starts_with("//-") {
|
||||
let meta = Fixture::parse_meta_line(line);
|
||||
res.push(meta)
|
||||
res.push(meta);
|
||||
} else {
|
||||
if line.starts_with("// ")
|
||||
&& line.contains(':')
|
||||
&& !line.contains("::")
|
||||
&& line.chars().all(|it| !it.is_uppercase())
|
||||
{
|
||||
panic!("looks like invalid metadata line: {:?}", line)
|
||||
panic!("looks like invalid metadata line: {:?}", line);
|
||||
}
|
||||
|
||||
if let Some(entry) = res.last_mut() {
|
||||
|
@ -256,9 +256,9 @@ impl MiniCore {
|
|||
let line = line.strip_prefix("//- minicore:").unwrap().trim();
|
||||
for entry in line.split(", ") {
|
||||
if res.has_flag(entry) {
|
||||
panic!("duplicate minicore flag: {:?}", entry)
|
||||
panic!("duplicate minicore flag: {:?}", entry);
|
||||
}
|
||||
res.activated_flags.push(entry.to_string())
|
||||
res.activated_flags.push(entry.to_string());
|
||||
}
|
||||
|
||||
res
|
||||
|
@ -310,7 +310,7 @@ impl MiniCore {
|
|||
// Fixed point loop to compute transitive closure of flags.
|
||||
loop {
|
||||
let mut changed = false;
|
||||
for &(u, v) in implications.iter() {
|
||||
for &(u, v) in &implications {
|
||||
if self.has_flag(u) && !self.has_flag(v) {
|
||||
self.activated_flags.push(v.to_string());
|
||||
changed = true;
|
||||
|
@ -354,7 +354,7 @@ impl MiniCore {
|
|||
}
|
||||
|
||||
if keep {
|
||||
buf.push_str(line)
|
||||
buf.push_str(line);
|
||||
}
|
||||
if line_region {
|
||||
active_regions.pop().unwrap();
|
||||
|
|
|
@ -244,7 +244,7 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
|
|||
|
||||
range + line_start.1
|
||||
};
|
||||
res.push((range, content))
|
||||
res.push((range, content));
|
||||
}
|
||||
LineAnnotation::Continuation { mut offset, content } => {
|
||||
offset += annotation_offset;
|
||||
|
@ -301,7 +301,7 @@ fn extract_line_annotations(mut line: &str) -> Vec<LineAnnotation> {
|
|||
let mut file = false;
|
||||
if !continuation && content.starts_with("file") {
|
||||
file = true;
|
||||
content = &content["file".len()..]
|
||||
content = &content["file".len()..];
|
||||
}
|
||||
|
||||
let content = content.trim().to_string();
|
||||
|
@ -371,7 +371,7 @@ fn main() {
|
|||
pub fn skip_slow_tests() -> bool {
|
||||
let should_skip = std::env::var("CI").is_err() && std::env::var("RUN_SLOW_TESTS").is_err();
|
||||
if should_skip {
|
||||
eprintln!("ignoring slow test")
|
||||
eprintln!("ignoring slow test");
|
||||
} else {
|
||||
let path = project_root().join("./target/.slow_tests_cookie");
|
||||
fs::write(&path, ".").unwrap();
|
||||
|
@ -432,7 +432,7 @@ pub fn bench(label: &'static str) -> impl Drop {
|
|||
|
||||
impl Drop for Bencher {
|
||||
fn drop(&mut self) {
|
||||
eprintln!("{}: {}", self.label, self.sw.elapsed())
|
||||
eprintln!("{}: {}", self.label, self.sw.elapsed());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue