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
128128 }
129129 }
130130
131+#[cfg(feature = "test-support")]
132+type FakeHttpHandler = Box<
133+ dyn Fn(Request<AsyncBody>) -> BoxFuture<'static, Result<Response<AsyncBody>, Error>>
134+ + Send
135+ + Sync
136+ + 'static,
137+>;
138+
131139 #[cfg(feature = "test-support")]
132140 pub struct FakeHttpClient {
133− handler: Box<
134− dyn 'static
135− + Send
136− + Sync
137− + Fn(Request<AsyncBody>) -> BoxFuture<'static, Result<Response<AsyncBody>, Error>>,
138− >,
141+ handler: FakeHttpHandler,
139142 }
140143
141144 #[cfg(feature = "test-support")]
142145 impl FakeHttpClient {
143146 pub fn create<Fut, F>(handler: F) -> Arc<HttpClientWithUrl>
144147 where
145− Fut: 'static + Send + futures::Future<Output = Result<Response<AsyncBody>, Error>>,
146− F: 'static + Send + Sync + Fn(Request<AsyncBody>) -> Fut,
148+ Fut: futures::Future<Output = Result<Response<AsyncBody>, Error>> + Send + 'static,
149+ F: Fn(Request<AsyncBody>) -> Fut + Send + Sync + 'static,
147150 {
148151 Arc::new(HttpClientWithUrl {
149152 base_url: Mutex::new("http://test.example".into()),
crates/util/src/paths.rs+2−2
@@ -459,7 +459,7 @@ mod tests { · 458 unmodified lines
459459 let path = Path::new("/work/node_modules");
460460 let path_matcher = PathMatcher::new("**/node_modules/**").unwrap();
461461 assert!(
462− path_matcher.is_match(&path),
462+ path_matcher.is_match(path),
463463 "Path matcher {path_matcher} should match {path:?}"
464464 );
465465 }
@@ -469,7 +469,7 @@ mod tests { · 3 unmodified lines
469469 let path = Path::new("/Users/someonetoignore/work/zed/zed.dev/node_modules");
470470 let path_matcher = PathMatcher::new("**/node_modules/**").unwrap();
471471 assert!(
472− path_matcher.is_match(&path),
472+ path_matcher.is_match(path),
473473 "Path matcher {path_matcher} should match {path:?}"
474474 );
475475 }
crates/util/src/test.rs+2−2
@@ -29,8 +29,8 @@ fn write_tree(path: &Path, tree: serde_json::Value) { · 28 unmodified lines
2929 Value::Object(_) => {
3030 fs::create_dir(&path).unwrap();
3131
32− if path.file_name() == Some(&OsStr::new(".git")) {
33− git2::Repository::init(&path.parent().unwrap()).unwrap();
32+ if path.file_name() == Some(OsStr::new(".git")) {
33+ git2::Repository::init(path.parent().unwrap()).unwrap();
3434 }
3535
3636 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
1212
1313 for char in marked_text.chars() {
1414 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();
1616 char_offsets.push(unmarked_text.len());
1717 } else {
1818 unmarked_text.push(char);
@@ -119,7 +119,7 @@ pub fn marked_text_ranges( · 100 unmodified lines
119119 let mut current_range_start = None;
120120 let mut current_range_cursor = None;
121121
122− let marked_text = marked_text.replace("•", " ");
122+ let marked_text = marked_text.replace('•', " ");
123123 for (marked_ix, marker) in marked_text.match_indices(&['«', '»', 'ˇ']) {
124124 unmarked_text.push_str(&marked_text[prev_marked_ix..marked_ix]);
125125 let unmarked_len = unmarked_text.len();
@@ -131,9 +131,9 @@ pub fn marked_text_ranges( · 5 unmodified lines
131131 if current_range_start.is_some() {
132132 if current_range_cursor.is_some() {
133133 panic!("duplicate point marker 'ˇ' at index {marked_ix}");
134− } else {
135− current_range_cursor = Some(unmarked_len);
136134 }
135+
136+ current_range_cursor = Some(unmarked_len);
137137 } else {
138138 ranges.push(unmarked_len..unmarked_len);
139139 }
@@ -252,6 +252,7 @@ impl From<(char, char)> for TextRangeMarker { · 112 unmodified lines
252252 mod tests {
253253 use super::{generate_marked_text, marked_text_ranges};
254254
255+ #[allow(clippy::reversed_empty_ranges)]
255256 #[test]
256257 fn test_marked_text() {
257258 let (text, ranges) = marked_text_ranges("one «ˇtwo» «threeˇ» «ˇfour» fiveˇ six", true);