History

Fix Clippy warnings in `util` crate (#8721)

This PR fixes a number of Clippy warnings in the `util` crate. Release Notes: - N/A

Marshall Bowers committed 2 years ago

Commit c19587d1 parent 0ac203b4 files · +20 −16Browse files

Unified · Split

4 files
  1. crates/util/src/http.rs +11 −8
  2. crates/util/src/paths.rs +2 −2
  3. crates/util/src/test.rs +2 −2
  4. crates/util/src/test/marked_text.rs +5 −4
crates/util/src/http.rs+11−8
@@ -128,22 +128,25 @@ impl HttpClient for isahc::HttpClient { · 127 unmodified lines
128 }128 }
129}129}
130 130
131#[cfg(feature = "test-support")]
132type FakeHttpHandler = Box<
133 dyn Fn(Request<AsyncBody>) -> BoxFuture<'static, Result<Response<AsyncBody>, Error>>
134 + Send
135 + Sync
136 + 'static,
137>;
138
131#[cfg(feature = "test-support")]139#[cfg(feature = "test-support")]
132pub struct FakeHttpClient {140pub struct FakeHttpClient {
133 handler: Box<141 handler: FakeHttpHandler,
134 dyn 'static
135 + Send
136 + Sync
137 + Fn(Request<AsyncBody>) -> BoxFuture<'static, Result<Response<AsyncBody>, Error>>,
138 >,
139}142}
140 143
141#[cfg(feature = "test-support")]144#[cfg(feature = "test-support")]
142impl FakeHttpClient {145impl FakeHttpClient {
143 pub fn create<Fut, F>(handler: F) -> Arc<HttpClientWithUrl>146 pub fn create<Fut, F>(handler: F) -> Arc<HttpClientWithUrl>
144 where147 where
145 Fut: 'static + Send + futures::Future<Output = Result<Response<AsyncBody>, Error>>,148 Fut: futures::Future<Output = Result<Response<AsyncBody>, Error>> + Send + 'static,
146 F: 'static + Send + Sync + Fn(Request<AsyncBody>) -> Fut,149 F: Fn(Request<AsyncBody>) -> Fut + Send + Sync + 'static,
147 {150 {
148 Arc::new(HttpClientWithUrl {151 Arc::new(HttpClientWithUrl {
149 base_url: Mutex::new("http://test.example".into()),152 base_url: Mutex::new("http://test.example".into()),
crates/util/src/paths.rs+2−2
@@ -459,7 +459,7 @@ mod tests { · 458 unmodified lines
459 let path = Path::new("/work/node_modules");459 let path = Path::new("/work/node_modules");
460 let path_matcher = PathMatcher::new("**/node_modules/**").unwrap();460 let path_matcher = PathMatcher::new("**/node_modules/**").unwrap();
461 assert!(461 assert!(
462 path_matcher.is_match(&path),462 path_matcher.is_match(path),
463 "Path matcher {path_matcher} should match {path:?}"463 "Path matcher {path_matcher} should match {path:?}"
464 );464 );
465 }465 }
@@ -469,7 +469,7 @@ mod tests { · 3 unmodified lines
469 let path = Path::new("/Users/someonetoignore/work/zed/zed.dev/node_modules");469 let path = Path::new("/Users/someonetoignore/work/zed/zed.dev/node_modules");
470 let path_matcher = PathMatcher::new("**/node_modules/**").unwrap();470 let path_matcher = PathMatcher::new("**/node_modules/**").unwrap();
471 assert!(471 assert!(
472 path_matcher.is_match(&path),472 path_matcher.is_match(path),
473 "Path matcher {path_matcher} should match {path:?}"473 "Path matcher {path_matcher} should match {path:?}"
474 );474 );
475 }475 }
crates/util/src/test.rs+2−2
@@ -29,8 +29,8 @@ fn write_tree(path: &Path, tree: serde_json::Value) { · 28 unmodified lines
29 Value::Object(_) => {29 Value::Object(_) => {
30 fs::create_dir(&path).unwrap();30 fs::create_dir(&path).unwrap();
31 31
32 if path.file_name() == Some(&OsStr::new(".git")) {32 if path.file_name() == Some(OsStr::new(".git")) {
33 git2::Repository::init(&path.parent().unwrap()).unwrap();33 git2::Repository::init(path.parent().unwrap()).unwrap();
34 }34 }
35 35
36 write_tree(&path, contents);36 write_tree(&path, contents);
crates/util/src/test/marked_text.rs+5−4
@@ -12,7 +12,7 @@ pub fn marked_text_offsets_by( · 11 unmodified lines
12 12
13 for char in marked_text.chars() {13 for char in marked_text.chars() {
14 if markers.contains(&char) {14 if markers.contains(&char) {
15 let char_offsets = extracted_markers.entry(char).or_insert(Vec::new());15 let char_offsets = extracted_markers.entry(char).or_default();
16 char_offsets.push(unmarked_text.len());16 char_offsets.push(unmarked_text.len());
17 } else {17 } else {
18 unmarked_text.push(char);18 unmarked_text.push(char);
@@ -119,7 +119,7 @@ pub fn marked_text_ranges( · 100 unmodified lines
119 let mut current_range_start = None;119 let mut current_range_start = None;
120 let mut current_range_cursor = None;120 let mut current_range_cursor = None;
121 121
122 let marked_text = marked_text.replace("•", " ");122 let marked_text = marked_text.replace('•', " ");
123 for (marked_ix, marker) in marked_text.match_indices(&['«', '»', 'ˇ']) {123 for (marked_ix, marker) in marked_text.match_indices(&['«', '»', 'ˇ']) {
124 unmarked_text.push_str(&marked_text[prev_marked_ix..marked_ix]);124 unmarked_text.push_str(&marked_text[prev_marked_ix..marked_ix]);
125 let unmarked_len = unmarked_text.len();125 let unmarked_len = unmarked_text.len();
@@ -131,9 +131,9 @@ pub fn marked_text_ranges( · 5 unmodified lines
131 if current_range_start.is_some() {131 if current_range_start.is_some() {
132 if current_range_cursor.is_some() {132 if current_range_cursor.is_some() {
133 panic!("duplicate point marker 'ˇ' at index {marked_ix}");133 panic!("duplicate point marker 'ˇ' at index {marked_ix}");
134 } else {
135 current_range_cursor = Some(unmarked_len);
136 }134 }
135
136 current_range_cursor = Some(unmarked_len);
137 } else {137 } else {
138 ranges.push(unmarked_len..unmarked_len);138 ranges.push(unmarked_len..unmarked_len);
139 }139 }
@@ -252,6 +252,7 @@ impl From<(char, char)> for TextRangeMarker { · 112 unmodified lines
252mod tests {252mod tests {
253 use super::{generate_marked_text, marked_text_ranges};253 use super::{generate_marked_text, marked_text_ranges};
254 254
255 #[allow(clippy::reversed_empty_ranges)]
255 #[test]256 #[test]
256 fn test_marked_text() {257 fn test_marked_text() {
257 let (text, ranges) = marked_text_ranges("one «ˇtwo» «threeˇ» «ˇfour» fiveˇ six", true);258 let (text, ranges) = marked_text_ranges("one «ˇtwo» «threeˇ» «ˇfour» fiveˇ six", true);