Fix Clippy warnings in util crate (#8721)

This PR fixes a number of Clippy warnings in the `util` crate.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-03-02 13:06:35 -05:00 committed by GitHub
parent 0ac203bde0
commit c19587d4e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 16 deletions

View file

@ -128,22 +128,25 @@ impl HttpClient for isahc::HttpClient {
} }
} }
#[cfg(feature = "test-support")]
type FakeHttpHandler = Box<
dyn Fn(Request<AsyncBody>) -> BoxFuture<'static, Result<Response<AsyncBody>, Error>>
+ Send
+ Sync
+ 'static,
>;
#[cfg(feature = "test-support")] #[cfg(feature = "test-support")]
pub struct FakeHttpClient { pub struct FakeHttpClient {
handler: Box< handler: FakeHttpHandler,
dyn 'static
+ Send
+ Sync
+ Fn(Request<AsyncBody>) -> BoxFuture<'static, Result<Response<AsyncBody>, Error>>,
>,
} }
#[cfg(feature = "test-support")] #[cfg(feature = "test-support")]
impl FakeHttpClient { impl FakeHttpClient {
pub fn create<Fut, F>(handler: F) -> Arc<HttpClientWithUrl> pub fn create<Fut, F>(handler: F) -> Arc<HttpClientWithUrl>
where where
Fut: 'static + Send + futures::Future<Output = Result<Response<AsyncBody>, Error>>, Fut: futures::Future<Output = Result<Response<AsyncBody>, Error>> + Send + 'static,
F: 'static + Send + Sync + Fn(Request<AsyncBody>) -> Fut, F: Fn(Request<AsyncBody>) -> Fut + Send + Sync + 'static,
{ {
Arc::new(HttpClientWithUrl { Arc::new(HttpClientWithUrl {
base_url: Mutex::new("http://test.example".into()), base_url: Mutex::new("http://test.example".into()),

View file

@ -459,7 +459,7 @@ mod tests {
let path = Path::new("/work/node_modules"); let path = Path::new("/work/node_modules");
let path_matcher = PathMatcher::new("**/node_modules/**").unwrap(); let path_matcher = PathMatcher::new("**/node_modules/**").unwrap();
assert!( assert!(
path_matcher.is_match(&path), path_matcher.is_match(path),
"Path matcher {path_matcher} should match {path:?}" "Path matcher {path_matcher} should match {path:?}"
); );
} }
@ -469,7 +469,7 @@ mod tests {
let path = Path::new("/Users/someonetoignore/work/zed/zed.dev/node_modules"); let path = Path::new("/Users/someonetoignore/work/zed/zed.dev/node_modules");
let path_matcher = PathMatcher::new("**/node_modules/**").unwrap(); let path_matcher = PathMatcher::new("**/node_modules/**").unwrap();
assert!( assert!(
path_matcher.is_match(&path), path_matcher.is_match(path),
"Path matcher {path_matcher} should match {path:?}" "Path matcher {path_matcher} should match {path:?}"
); );
} }

View file

@ -29,8 +29,8 @@ fn write_tree(path: &Path, tree: serde_json::Value) {
Value::Object(_) => { Value::Object(_) => {
fs::create_dir(&path).unwrap(); fs::create_dir(&path).unwrap();
if path.file_name() == Some(&OsStr::new(".git")) { if path.file_name() == Some(OsStr::new(".git")) {
git2::Repository::init(&path.parent().unwrap()).unwrap(); git2::Repository::init(path.parent().unwrap()).unwrap();
} }
write_tree(&path, contents); write_tree(&path, contents);

View file

@ -12,7 +12,7 @@ pub fn marked_text_offsets_by(
for char in marked_text.chars() { for char in marked_text.chars() {
if markers.contains(&char) { if markers.contains(&char) {
let char_offsets = extracted_markers.entry(char).or_insert(Vec::new()); let char_offsets = extracted_markers.entry(char).or_default();
char_offsets.push(unmarked_text.len()); char_offsets.push(unmarked_text.len());
} else { } else {
unmarked_text.push(char); unmarked_text.push(char);
@ -119,7 +119,7 @@ pub fn marked_text_ranges(
let mut current_range_start = None; let mut current_range_start = None;
let mut current_range_cursor = None; let mut current_range_cursor = None;
let marked_text = marked_text.replace("", " "); let marked_text = marked_text.replace('•', " ");
for (marked_ix, marker) in marked_text.match_indices(&['«', '»', 'ˇ']) { for (marked_ix, marker) in marked_text.match_indices(&['«', '»', 'ˇ']) {
unmarked_text.push_str(&marked_text[prev_marked_ix..marked_ix]); unmarked_text.push_str(&marked_text[prev_marked_ix..marked_ix]);
let unmarked_len = unmarked_text.len(); let unmarked_len = unmarked_text.len();
@ -131,9 +131,9 @@ pub fn marked_text_ranges(
if current_range_start.is_some() { if current_range_start.is_some() {
if current_range_cursor.is_some() { if current_range_cursor.is_some() {
panic!("duplicate point marker 'ˇ' at index {marked_ix}"); panic!("duplicate point marker 'ˇ' at index {marked_ix}");
} else {
current_range_cursor = Some(unmarked_len);
} }
current_range_cursor = Some(unmarked_len);
} else { } else {
ranges.push(unmarked_len..unmarked_len); ranges.push(unmarked_len..unmarked_len);
} }
@ -252,6 +252,7 @@ impl From<(char, char)> for TextRangeMarker {
mod tests { mod tests {
use super::{generate_marked_text, marked_text_ranges}; use super::{generate_marked_text, marked_text_ranges};
#[allow(clippy::reversed_empty_ranges)]
#[test] #[test]
fn test_marked_text() { fn test_marked_text() {
let (text, ranges) = marked_text_ranges("one «ˇtwo» «threeˇ» «ˇfour» fiveˇ six", true); let (text, ranges) = marked_text_ranges("one «ˇtwo» «threeˇ» «ˇfour» fiveˇ six", true);