chore: Fix clippy violations from Cargo.toml (#15216)

/cc @maxdeviant 
Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-07-25 20:22:01 +02:00 committed by GitHub
parent d755d29577
commit 86456ce379
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 94 additions and 93 deletions

View File

@ -537,13 +537,6 @@ single_range_in_vec_init = "allow"
style = { level = "allow", priority = -1 }
# Individual rules that have violations in the codebase:
almost_complete_range = "allow"
arc_with_non_send_sync = "allow"
borrowed_box = "allow"
let_underscore_future = "allow"
map_entry = "allow"
non_canonical_partial_ord_impl = "allow"
reversed_empty_ranges = "allow"
type_complexity = "allow"
[workspace.metadata.cargo-machete]

View File

@ -219,7 +219,7 @@ impl SlashCommand for DocsSlashCommand {
if index {
// We don't need to hold onto this task, as the `IndexedDocsStore` will hold it
// until it completes.
let _ = store.clone().index(package.as_str().into());
drop(store.clone().index(package.as_str().into()));
}
let items = store.search(package).await;

View File

@ -493,7 +493,7 @@ impl Room {
// we leave the room and return an error.
if let Some(this) = this.upgrade() {
log::info!("reconnection failed, leaving room");
let _ = this.update(&mut cx, |this, cx| this.leave(cx))?;
let _ = this.update(&mut cx, |this, cx| this.leave(cx))?.await?;
}
Err(anyhow!(
"can't reconnect to room: client failed to re-establish connection"
@ -942,7 +942,7 @@ impl Room {
this.pending_room_update.take();
if this.should_leave() {
log::info!("room is empty, leaving");
let _ = this.leave(cx);
let _ = this.leave(cx).detach();
}
this.user_store.update(cx, |user_store, cx| {

View File

@ -1,3 +1,4 @@
#![allow(clippy::reversed_empty_ranges)]
use crate::{rpc::RECONNECT_TIMEOUT, tests::TestServer};
use call::{ActiveCall, ParticipantLocation};
use client::ChannelId;

View File

@ -691,7 +691,7 @@ impl Copilot {
{
match event {
language::Event::Edited => {
let _ = registered_buffer.report_changes(&buffer, cx);
drop(registered_buffer.report_changes(&buffer, cx));
}
language::Event::Saved => {
server

View File

@ -333,7 +333,7 @@ mod tests {
three
"});
cx.simulate_keystroke(".");
let _ = handle_completion_request(
drop(handle_completion_request(
&mut cx,
indoc! {"
one.|<>
@ -341,7 +341,7 @@ mod tests {
three
"},
vec!["completion_a", "completion_b"],
);
));
handle_copilot_completion_request(
&copilot_lsp,
vec![crate::request::Completion {
@ -375,7 +375,7 @@ mod tests {
three
"});
cx.simulate_keystroke(".");
let _ = handle_completion_request(
drop(handle_completion_request(
&mut cx,
indoc! {"
one.|<>
@ -383,7 +383,7 @@ mod tests {
three
"},
vec![],
);
));
handle_copilot_completion_request(
&copilot_lsp,
vec![crate::request::Completion {
@ -408,7 +408,7 @@ mod tests {
three
"});
cx.simulate_keystroke(".");
let _ = handle_completion_request(
drop(handle_completion_request(
&mut cx,
indoc! {"
one.|<>
@ -416,7 +416,7 @@ mod tests {
three
"},
vec!["completion_a", "completion_b"],
);
));
handle_copilot_completion_request(
&copilot_lsp,
vec![crate::request::Completion {
@ -590,7 +590,7 @@ mod tests {
three
"});
cx.simulate_keystroke(".");
let _ = handle_completion_request(
drop(handle_completion_request(
&mut cx,
indoc! {"
one.|<>
@ -598,7 +598,7 @@ mod tests {
three
"},
vec![],
);
));
handle_copilot_completion_request(
&copilot_lsp,
vec![crate::request::Completion {
@ -632,7 +632,7 @@ mod tests {
three
"});
cx.simulate_keystroke(".");
let _ = handle_completion_request(
drop(handle_completion_request(
&mut cx,
indoc! {"
one.|<>
@ -640,7 +640,7 @@ mod tests {
three
"},
vec![],
);
));
handle_copilot_completion_request(
&copilot_lsp,
vec![crate::request::Completion {
@ -889,7 +889,7 @@ mod tests {
three
"});
let _ = handle_completion_request(
drop(handle_completion_request(
&mut cx,
indoc! {"
one
@ -897,7 +897,7 @@ mod tests {
three
"},
vec!["completion_a", "completion_b"],
);
));
handle_copilot_completion_request(
&copilot_lsp,
vec![crate::request::Completion {
@ -917,7 +917,7 @@ mod tests {
});
cx.simulate_keystroke("o");
let _ = handle_completion_request(
drop(handle_completion_request(
&mut cx,
indoc! {"
one
@ -925,7 +925,7 @@ mod tests {
three
"},
vec!["completion_a_2", "completion_b_2"],
);
));
handle_copilot_completion_request(
&copilot_lsp,
vec![crate::request::Completion {
@ -944,7 +944,7 @@ mod tests {
});
cx.simulate_keystroke(".");
let _ = handle_completion_request(
drop(handle_completion_request(
&mut cx,
indoc! {"
one
@ -952,7 +952,7 @@ mod tests {
three
"},
vec!["something_else()"],
);
));
handle_copilot_completion_request(
&copilot_lsp,
vec![crate::request::Completion {

View File

@ -59,6 +59,7 @@ use std::{
fmt::{self, Write},
iter, mem,
ops::{Deref, Range},
rc::Rc,
sync::Arc,
};
use sum_tree::Bias;
@ -5492,7 +5493,7 @@ impl Element for EditorElement {
EditorLayout {
mode: snapshot.mode,
position_map: Arc::new(PositionMap {
position_map: Rc::new(PositionMap {
size: bounds.size,
scroll_pixel_position,
scroll_max,
@ -5642,7 +5643,7 @@ impl IntoElement for EditorElement {
}
pub struct EditorLayout {
position_map: Arc<PositionMap>,
position_map: Rc<PositionMap>,
hitbox: Hitbox,
text_hitbox: Hitbox,
gutter_hitbox: Hitbox,

View File

@ -363,6 +363,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
},
);
#[allow(clippy::let_underscore_future)]
let _ = store.update(cx, |store, cx| store.reload(None, cx));
cx.executor().advance_clock(RELOAD_DEBOUNCE_DURATION);

View File

@ -323,14 +323,14 @@ impl Interactivity {
pub fn on_boxed_action(
&mut self,
action: &dyn Action,
listener: impl Fn(&Box<dyn Action>, &mut WindowContext) + 'static,
listener: impl Fn(&dyn Action, &mut WindowContext) + 'static,
) {
let action = action.boxed_clone();
self.action_listeners.push((
(*action).type_id(),
Box::new(move |_, phase, cx| {
if phase == DispatchPhase::Bubble {
(listener)(&action, cx)
(listener)(&*action, cx)
}
}),
));
@ -757,7 +757,7 @@ pub trait InteractiveElement: Sized {
fn on_boxed_action(
mut self,
action: &dyn Action,
listener: impl Fn(&Box<dyn Action>, &mut WindowContext) + 'static,
listener: impl Fn(&dyn Action, &mut WindowContext) + 'static,
) -> Self {
self.interactivity().on_boxed_action(action, listener);
self

View File

@ -115,7 +115,7 @@ impl TestPlatform {
.spawn(async move {
if let Some(previous_window) = previous_window {
if let Some(window) = window.as_ref() {
if Arc::ptr_eq(&previous_window.0, &window.0) {
if Rc::ptr_eq(&previous_window.0, &window.0) {
return;
}
}

View File

@ -31,7 +31,7 @@ pub(crate) struct TestWindowState {
}
#[derive(Clone)]
pub(crate) struct TestWindow(pub(crate) Arc<Mutex<TestWindowState>>);
pub(crate) struct TestWindow(pub(crate) Rc<Mutex<TestWindowState>>);
impl HasWindowHandle for TestWindow {
fn window_handle(
@ -56,7 +56,7 @@ impl TestWindow {
platform: Weak<TestPlatform>,
display: Rc<dyn PlatformDisplay>,
) -> Self {
Self(Arc::new(Mutex::new(TestWindowState {
Self(Rc::new(Mutex::new(TestWindowState {
bounds: params.bounds,
display,
platform,

View File

@ -4419,7 +4419,7 @@ impl<'a, V: 'static> ViewContext<'a, V> {
/// Many GPUI callbacks take the form of `Fn(&E, &mut WindowContext)`,
/// but it's often useful to be able to access view state in these
/// callbacks. This method provides a convenient way to do so.
pub fn listener<E>(
pub fn listener<E: ?Sized>(
&self,
f: impl Fn(&mut V, &E, &mut ViewContext<V>) + 'static,
) -> impl Fn(&E, &mut WindowContext) + 'static {

View File

@ -2463,7 +2463,7 @@ fn test_trailing_whitespace_ranges(mut rng: StdRng) {
text.push(match rng.gen_range(0..10) {
0..=1 => ' ',
3 => '\t',
_ => rng.gen_range('a'..'z'),
_ => rng.gen_range('a'..='z'),
});
}
text.push('\n');

View File

@ -1334,7 +1334,7 @@ pub(crate) fn splice_included_ranges(
let mut removed_ranges = removed_ranges.iter().cloned().peekable();
let mut new_ranges = new_ranges.into_iter().cloned().peekable();
let mut ranges_ix = 0;
let mut changed_portion = usize::MAX..0;
let mut changed_portion: Option<Range<usize>> = None;
loop {
let next_new_range = new_ranges.peek();
let next_removed_range = removed_ranges.peek();
@ -1395,23 +1395,26 @@ pub(crate) fn splice_included_ranges(
break;
}
}
changed_portion.start = changed_portion.start.min(start_ix);
changed_portion.end = changed_portion.end.max(if insert.is_some() {
start_ix + 1
} else {
start_ix
});
let changed_start = changed_portion
.as_ref()
.map_or(usize::MAX, |range| range.start)
.min(start_ix);
let changed_end =
changed_portion
.as_ref()
.map_or(0, |range| range.end)
.max(if insert.is_some() {
start_ix + 1
} else {
start_ix
});
changed_portion = Some(changed_start..changed_end);
ranges.splice(start_ix..end_ix, insert);
ranges_ix = start_ix;
}
if changed_portion.end < changed_portion.start {
changed_portion = 0..0;
}
(ranges, changed_portion)
(ranges, changed_portion.unwrap_or(0..0))
}
/// Ensure there are newline ranges in between content range that appear on

View File

@ -1,7 +1,7 @@
use crate::{ConnectionState, RoomUpdate, Sid};
use anyhow::{anyhow, Context, Result};
use async_trait::async_trait;
use collections::{BTreeMap, HashMap, HashSet};
use collections::{btree_map::Entry as BTreeEntry, hash_map::Entry, BTreeMap, HashMap, HashSet};
use futures::Stream;
use gpui::{BackgroundExecutor, ImageSource};
use live_kit_server::{proto, token};
@ -35,18 +35,18 @@ impl TestServer {
executor: BackgroundExecutor,
) -> Result<Arc<TestServer>> {
let mut servers = SERVERS.lock();
if servers.contains_key(&url) {
Err(anyhow!("a server with url {:?} already exists", url))
} else {
if let BTreeEntry::Vacant(e) = servers.entry(url.clone()) {
let server = Arc::new(TestServer {
url: url.clone(),
url,
api_key,
secret_key,
rooms: Default::default(),
executor,
});
servers.insert(url, server.clone());
e.insert(server.clone());
Ok(server)
} else {
Err(anyhow!("a server with url {:?} already exists", url))
}
}
@ -77,11 +77,11 @@ impl TestServer {
#[cfg(any(test, feature = "test-support"))]
self.executor.simulate_random_delay().await;
let mut server_rooms = self.rooms.lock();
if server_rooms.contains_key(&room) {
Err(anyhow!("room {:?} already exists", room))
} else {
server_rooms.insert(room, Default::default());
if let Entry::Vacant(e) = server_rooms.entry(room.clone()) {
e.insert(Default::default());
Ok(())
} else {
Err(anyhow!("room {:?} already exists", room))
}
}
@ -108,13 +108,7 @@ impl TestServer {
let mut server_rooms = self.rooms.lock();
let room = (*server_rooms).entry(room_name.to_string()).or_default();
if room.client_rooms.contains_key(&identity) {
Err(anyhow!(
"{:?} attempted to join room {:?} twice",
identity,
room_name
))
} else {
if let Entry::Vacant(e) = room.client_rooms.entry(identity.clone()) {
for track in &room.video_tracks {
client_room
.0
@ -141,8 +135,14 @@ impl TestServer {
))
.unwrap();
}
room.client_rooms.insert(identity, client_room);
e.insert(client_room);
Ok(())
} else {
Err(anyhow!(
"{:?} attempted to join room {:?} twice",
identity,
room_name
))
}
}

View File

@ -500,8 +500,8 @@ impl<'a> MarkdownParser<'a> {
// We will use the start of the nested list as the end for the current item's range,
// because we don't care about the hierarchy of list items
if !source_ranges.contains_key(&depth) {
source_ranges.insert(depth, start_item_range.start..source_range.start);
if let collections::hash_map::Entry::Vacant(e) = source_ranges.entry(depth) {
e.insert(start_item_range.start..source_range.start);
}
order_stack.push(order);

View File

@ -437,7 +437,7 @@ impl ToolbarItemView for BufferSearchBar {
));
self.active_searchable_item = Some(searchable_item_handle);
let _ = self.update_matches(cx);
drop(self.update_matches(cx));
if !self.dismissed {
return ToolbarItemLocation::Secondary;
}
@ -719,7 +719,7 @@ impl BufferSearchBar {
fn toggle_search_option(&mut self, search_option: SearchOptions, cx: &mut ViewContext<Self>) {
self.search_options.toggle(search_option);
self.default_options = self.search_options;
let _ = self.update_matches(cx);
drop(self.update_matches(cx));
cx.notify();
}
@ -856,7 +856,7 @@ impl BufferSearchBar {
fn on_active_searchable_item_event(&mut self, event: &SearchEvent, cx: &mut ViewContext<Self>) {
match event {
SearchEvent::MatchesInvalidated => {
let _ = self.update_matches(cx);
drop(self.update_matches(cx));
}
SearchEvent::ActiveMatchChanged => self.update_match_index(cx),
}
@ -874,7 +874,7 @@ impl BufferSearchBar {
if let Some(active_item) = self.active_searchable_item.as_mut() {
self.selection_search_enabled = !self.selection_search_enabled;
active_item.toggle_filtered_search_ranges(self.selection_search_enabled, cx);
let _ = self.update_matches(cx);
drop(self.update_matches(cx));
cx.notify();
}
}
@ -1047,10 +1047,10 @@ impl BufferSearchBar {
.next(&mut self.search_history_cursor)
.map(str::to_string)
{
let _ = self.search(&new_query, Some(self.search_options), cx);
drop(self.search(&new_query, Some(self.search_options), cx));
} else {
self.search_history_cursor.reset();
let _ = self.search("", Some(self.search_options), cx);
drop(self.search("", Some(self.search_options), cx));
}
}
@ -1061,7 +1061,7 @@ impl BufferSearchBar {
.current(&mut self.search_history_cursor)
.map(str::to_string)
{
let _ = self.search(&new_query, Some(self.search_options), cx);
drop(self.search(&new_query, Some(self.search_options), cx));
return;
}
}
@ -1071,7 +1071,7 @@ impl BufferSearchBar {
.previous(&mut self.search_history_cursor)
.map(str::to_string)
{
let _ = self.search(&new_query, Some(self.search_options), cx);
drop(self.search(&new_query, Some(self.search_options), cx));
}
}

View File

@ -1192,7 +1192,7 @@ mod tests {
Err(anyhow!("cannot embed text containing a 'g' character"))
} else {
Ok(Embedding::new(
('a'..'z')
('a'..='z')
.map(|char| text.chars().filter(|c| *c == char).count() as f32)
.collect(),
))

View File

@ -27,8 +27,8 @@ use theme::{ActiveTheme, Theme, ThemeSettings};
use ui::{ParentElement, Tooltip};
use workspace::Workspace;
use std::{fmt::Debug, ops::RangeInclusive};
use std::{mem, sync::Arc};
use std::mem;
use std::{fmt::Debug, ops::RangeInclusive, rc::Rc};
use crate::{BlockContext, BlockProperties, TerminalView};
@ -156,7 +156,7 @@ pub struct TerminalElement {
cursor_visible: bool,
can_navigate_to_selected_word: bool,
interactivity: Interactivity,
block_below_cursor: Option<Arc<BlockProperties>>,
block_below_cursor: Option<Rc<BlockProperties>>,
}
impl InteractiveElement for TerminalElement {
@ -177,7 +177,7 @@ impl TerminalElement {
focused: bool,
cursor_visible: bool,
can_navigate_to_selected_word: bool,
block_below_cursor: Option<Arc<BlockProperties>>,
block_below_cursor: Option<Rc<BlockProperties>>,
) -> TerminalElement {
TerminalElement {
terminal,

View File

@ -47,6 +47,7 @@ use std::{
cmp,
ops::RangeInclusive,
path::{Path, PathBuf},
rc::Rc,
sync::Arc,
time::Duration,
};
@ -106,7 +107,7 @@ pub struct TerminalView {
can_navigate_to_selected_word: bool,
workspace_id: Option<WorkspaceId>,
show_title: bool,
block_below_cursor: Option<Arc<BlockProperties>>,
block_below_cursor: Option<Rc<BlockProperties>>,
scroll_top: Pixels,
_subscriptions: Vec<Subscription>,
_terminal_subscriptions: Vec<Subscription>,
@ -459,7 +460,7 @@ impl TerminalView {
}
pub fn set_block_below_cursor(&mut self, block: BlockProperties, cx: &mut ViewContext<Self>) {
self.block_below_cursor = Some(Arc::new(block));
self.block_below_cursor = Some(Rc::new(block));
self.scroll_to_bottom(&ScrollToBottom, cx);
cx.notify();
}

View File

@ -562,6 +562,7 @@ mod tests {
}
#[track_caller]
#[allow(clippy::almost_complete_range)]
fn assert_patch_composition(old: Patch<u32>, new: Patch<u32>, composed: Patch<u32>) {
let original = ('a'..'z').collect::<Vec<_>>();
let inserted = ('A'..'Z').collect::<Vec<_>>();

View File

@ -250,7 +250,7 @@ impl ContextMenu {
}
}
pub fn on_action_dispatch(&mut self, dispatched: &Box<dyn Action>, cx: &mut ViewContext<Self>) {
pub fn on_action_dispatch(&mut self, dispatched: &dyn Action, cx: &mut ViewContext<Self>) {
if self.clicked {
cx.propagate();
return;
@ -262,7 +262,7 @@ impl ContextMenu {
..
} = item
{
action.partial_eq(&**dispatched)
action.partial_eq(dispatched)
} else {
false
}

View File

@ -13,9 +13,9 @@ use workspace::Workspace;
actions!(vim, [Repeat, EndRepeat, ToggleRecord, ReplayLastRecording]);
fn should_replay(action: &Box<dyn Action>) -> bool {
fn should_replay(action: &dyn Action) -> bool {
// skip so that we don't leave the character palette open
if editor::actions::ShowCharacterPalette.partial_eq(&**action) {
if editor::actions::ShowCharacterPalette.partial_eq(action) {
return false;
}
true
@ -121,7 +121,7 @@ impl Replayer {
};
match action {
ReplayableAction::Action(action) => {
if should_replay(&action) {
if should_replay(&*action) {
cx.dispatch_action(action.boxed_clone());
cx.defer(move |cx| observe_action(action.boxed_clone(), cx));
}

View File

@ -271,7 +271,7 @@ pub fn move_to_internal(
}
let Some(query) = search_bar.query_suggestion(cx) else {
vim.clear_operator(cx);
let _ = search_bar.search("", None, cx);
drop(search_bar.search("", None, cx));
return None;
};
let mut query = regex::escape(&query);

View File

@ -1571,7 +1571,7 @@ impl Pane {
fn render_tab(
&self,
ix: usize,
item: &Box<dyn ItemHandle>,
item: &dyn ItemHandle,
detail: usize,
cx: &mut ViewContext<'_, Pane>,
) -> impl IntoElement {
@ -1863,7 +1863,7 @@ impl Pane {
.iter()
.enumerate()
.zip(tab_details(&self.items, cx))
.map(|((ix, item), detail)| self.render_tab(ix, item, detail, cx)),
.map(|((ix, item), detail)| self.render_tab(ix, &**item, detail, cx)),
)
.child(
div()