This PR fixes a number of Clippy warnings in the `util` crate. Release Notes: - N/A
Unified · Split
| @@ -128,22 +128,25 @@ impl HttpClient for isahc::HttpClient { · 127 unmodified lines | ||
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
| 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 | + | |
| 131 | 139 | #[cfg(feature = "test-support")] |
| 132 | 140 | 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, | |
| 139 | 142 | } |
| 140 | 143 | |
| 141 | 144 | #[cfg(feature = "test-support")] |
| 142 | 145 | impl FakeHttpClient { |
| 143 | 146 | pub fn create<Fut, F>(handler: F) -> Arc<HttpClientWithUrl> |
| 144 | 147 | 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, | |
| 147 | 150 | { |
| 148 | 151 | Arc::new(HttpClientWithUrl { |
| 149 | 152 | base_url: Mutex::new("http://test.example".into()), |
| @@ -459,7 +459,7 @@ mod tests { · 458 unmodified lines | ||
| 459 | 459 | let path = Path::new("/work/node_modules"); |
| 460 | 460 | let path_matcher = PathMatcher::new("**/node_modules/**").unwrap(); |
| 461 | 461 | assert!( |
| 462 | − path_matcher.is_match(&path), | |
| 462 | + path_matcher.is_match(path), | |
| 463 | 463 | "Path matcher {path_matcher} should match {path:?}" |
| 464 | 464 | ); |
| 465 | 465 | } |
| @@ -469,7 +469,7 @@ mod tests { · 3 unmodified lines | ||
| 469 | 469 | let path = Path::new("/Users/someonetoignore/work/zed/zed.dev/node_modules"); |
| 470 | 470 | let path_matcher = PathMatcher::new("**/node_modules/**").unwrap(); |
| 471 | 471 | assert!( |
| 472 | − path_matcher.is_match(&path), | |
| 472 | + path_matcher.is_match(path), | |
| 473 | 473 | "Path matcher {path_matcher} should match {path:?}" |
| 474 | 474 | ); |
| 475 | 475 | } |
| @@ -29,8 +29,8 @@ fn write_tree(path: &Path, tree: serde_json::Value) { · 28 unmodified lines | ||
| 29 | 29 | Value::Object(_) => { |
| 30 | 30 | fs::create_dir(&path).unwrap(); |
| 31 | 31 | |
| 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(); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | write_tree(&path, contents); |
| @@ -12,7 +12,7 @@ pub fn marked_text_offsets_by( · 11 unmodified lines | ||
| 12 | 12 | |
| 13 | 13 | for char in marked_text.chars() { |
| 14 | 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 | 16 | char_offsets.push(unmarked_text.len()); |
| 17 | 17 | } else { |
| 18 | 18 | unmarked_text.push(char); |
| @@ -119,7 +119,7 @@ pub fn marked_text_ranges( · 100 unmodified lines | ||
| 119 | 119 | let mut current_range_start = None; |
| 120 | 120 | let mut current_range_cursor = None; |
| 121 | 121 | |
| 122 | − let marked_text = marked_text.replace("•", " "); | |
| 122 | + let marked_text = marked_text.replace('•', " "); | |
| 123 | 123 | for (marked_ix, marker) in marked_text.match_indices(&['«', '»', 'ˇ']) { |
| 124 | 124 | unmarked_text.push_str(&marked_text[prev_marked_ix..marked_ix]); |
| 125 | 125 | let unmarked_len = unmarked_text.len(); |
| @@ -131,9 +131,9 @@ pub fn marked_text_ranges( · 5 unmodified lines | ||
| 131 | 131 | if current_range_start.is_some() { |
| 132 | 132 | if current_range_cursor.is_some() { |
| 133 | 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 | 137 | } else { |
| 138 | 138 | ranges.push(unmarked_len..unmarked_len); |
| 139 | 139 | } |
| @@ -252,6 +252,7 @@ impl From<(char, char)> for TextRangeMarker { · 112 unmodified lines | ||
| 252 | 252 | mod tests { |
| 253 | 253 | use super::{generate_marked_text, marked_text_ranges}; |
| 254 | 254 | |
| 255 | + #[allow(clippy::reversed_empty_ranges)] | |
| 255 | 256 | #[test] |
| 256 | 257 | fn test_marked_text() { |
| 257 | 258 | let (text, ranges) = marked_text_ranges("one «ˇtwo» «threeˇ» «ˇfour» fiveˇ six", true); |