Skip to content

Commit

Permalink
chore: Fix several style lints (#17488)
Browse files Browse the repository at this point in the history
It's not comprehensive enough to start linting on `style` group, but
hey, it's a start.

Release Notes:

- N/A
  • Loading branch information
osiewicz authored Sep 6, 2024
1 parent 93249fc commit e6c1c51
Show file tree
Hide file tree
Showing 361 changed files with 3,526 additions and 3,583 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ single_range_in_vec_init = "allow"
# There are a bunch of rules currently failing in the `style` group, so
# allow all of those, for now.
style = { level = "allow", priority = -1 }
# We often return trait objects from `new` functions.
new_ret_no_self = { level = "allow" }
# We have a few `next` functions that differ in lifetimes
# compared to Iterator::next. Yet, clippy complains about those.
should_implement_trait = { level = "allow" }

# Individual rules that have violations in the codebase:
type_complexity = "allow"
Expand Down
17 changes: 6 additions & 11 deletions crates/anthropic/src/anthropic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use util::ResultExt as _;

pub use supported_countries::*;

pub const ANTHROPIC_API_URL: &'static str = "https://api.anthropic.com";
pub const ANTHROPIC_API_URL: &str = "https://api.anthropic.com";

#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -339,14 +339,12 @@ pub async fn extract_tool_args_from_events(
while let Some(event) = events.next().await {
if let Event::ContentBlockStart {
index,
content_block,
content_block: ResponseContent::ToolUse { name, .. },
} = event?
{
if let ResponseContent::ToolUse { name, .. } = content_block {
if name == tool_name {
tool_use_index = Some(index);
break;
}
if name == tool_name {
tool_use_index = Some(index);
break;
}
}
}
Expand Down Expand Up @@ -610,9 +608,6 @@ impl ApiError {
}

pub fn is_rate_limit_error(&self) -> bool {
match self.error_type.as_str() {
"rate_limit_error" => true,
_ => false,
}
matches!(self.error_type.as_str(), "rate_limit_error")
}
}
2 changes: 1 addition & 1 deletion crates/audio/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl SoundRegistry {
let bytes = self
.assets
.load(&path)?
.map(|asset| Ok(asset))
.map(Ok)
.unwrap_or_else(|| Err(anyhow::anyhow!("No such asset available")))?
.into_owned();
let cursor = Cursor::new(bytes);
Expand Down
6 changes: 2 additions & 4 deletions crates/audio/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl Sound {
}
}

#[derive(Default)]
pub struct Audio {
_output_stream: Option<OutputStream>,
output_handle: Option<OutputStreamHandle>,
Expand All @@ -45,10 +46,7 @@ impl Global for GlobalAudio {}

impl Audio {
pub fn new() -> Self {
Self {
_output_stream: None,
output_handle: None,
}
Self::default()
}

fn ensure_output_exists(&mut self) -> Option<&OutputStreamHandle> {
Expand Down
14 changes: 7 additions & 7 deletions crates/auto_update/src/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct MacOsUnmounter {
impl Drop for MacOsUnmounter {
fn drop(&mut self) {
let unmount_output = std::process::Command::new("hdiutil")
.args(&["detach", "-force"])
.args(["detach", "-force"])
.arg(&self.mount_path)
.output();

Expand Down Expand Up @@ -211,7 +211,7 @@ pub fn check(_: &Check, cx: &mut WindowContext) {
return;
}

if let Some(message) = env::var("ZED_UPDATE_EXPLANATION").ok() {
if let Ok(message) = env::var("ZED_UPDATE_EXPLANATION") {
drop(cx.prompt(
gpui::PromptLevel::Info,
"Zed was installed via a package manager.",
Expand Down Expand Up @@ -254,7 +254,7 @@ pub fn view_release_notes(_: &ViewReleaseNotes, cx: &mut AppContext) -> Option<(
let url = &auto_updater
.http_client
.build_url(&format!("/releases/{release_channel}/{current_version}"));
cx.open_url(&url);
cx.open_url(url);
}

None
Expand Down Expand Up @@ -722,7 +722,7 @@ async fn install_release_linux(
}

let output = Command::new("rsync")
.args(&["-av", "--delete"])
.args(["-av", "--delete"])
.arg(&from)
.arg(&to)
.output()
Expand Down Expand Up @@ -754,10 +754,10 @@ async fn install_release_macos(

mounted_app_path.push("/");
let output = Command::new("hdiutil")
.args(&["attach", "-nobrowse"])
.args(["attach", "-nobrowse"])
.arg(&downloaded_dmg)
.arg("-mountroot")
.arg(&temp_dir.path())
.arg(temp_dir.path())
.output()
.await?;

Expand All @@ -773,7 +773,7 @@ async fn install_release_macos(
};

let output = Command::new("rsync")
.args(&["-av", "--delete"])
.args(["-av", "--delete"])
.arg(&mounted_app_path)
.arg(&running_app_path)
.output()
Expand Down
6 changes: 6 additions & 0 deletions crates/breadcrumbs/src/breadcrumbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub struct Breadcrumbs {
subscription: Option<Subscription>,
}

impl Default for Breadcrumbs {
fn default() -> Self {
Self::new()
}
}

impl Breadcrumbs {
pub fn new() -> Self {
Self {
Expand Down
24 changes: 8 additions & 16 deletions crates/call/src/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ impl Room {
None
};

match room
let did_join = room
.update(&mut cx, |room, cx| {
room.leave_when_empty = true;
room.call(called_user_id, initial_project_id, cx)
})?
.await
{
.await;
match did_join {
Ok(()) => Ok(room),
Err(error) => Err(error.context("room creation failed")),
}
Expand Down Expand Up @@ -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))?.await?;
this.update(&mut cx, |this, cx| this.leave(cx))?.await?;
}
Err(anyhow!(
"can't reconnect to room: client failed to re-establish connection"
Expand Down Expand Up @@ -933,7 +933,7 @@ impl Room {
let list = this
.follows_by_leader_id_project_id
.entry((leader, project_id))
.or_insert(Vec::new());
.or_default();
if !list.contains(&follower) {
list.push(follower);
}
Expand All @@ -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).detach();
this.leave(cx).detach();
}

this.user_store.update(cx, |user_store, cx| {
Expand Down Expand Up @@ -1017,19 +1017,11 @@ impl Room {
.collect::<Vec<u64>>();
speaker_ids.sort_unstable();
for (sid, participant) in &mut self.remote_participants {
if let Ok(_) = speaker_ids.binary_search(sid) {
participant.speaking = true;
} else {
participant.speaking = false;
}
participant.speaking = speaker_ids.binary_search(sid).is_ok();
}
if let Some(id) = self.client.user_id() {
if let Some(room) = &mut self.live_kit {
if let Ok(_) = speaker_ids.binary_search(&id) {
room.speaking = true;
} else {
room.speaking = false;
}
room.speaking = speaker_ids.binary_search(&id).is_ok();
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions crates/channel/src/channel_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,10 @@ impl ChannelBuffer {
match event {
language::Event::Operation(operation) => {
if *ZED_ALWAYS_ACTIVE {
match operation {
language::Operation::UpdateSelections { selections, .. } => {
if selections.is_empty() {
return;
}
if let language::Operation::UpdateSelections { selections, .. } = operation {
if selections.is_empty() {
return;
}
_ => {}
}
}
let operation = language::proto::serialize_operation(operation);
Expand Down
6 changes: 3 additions & 3 deletions crates/channel/src/channel_chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ pub enum ChannelMessageId {
Pending(usize),
}

impl Into<Option<u64>> for ChannelMessageId {
fn into(self) -> Option<u64> {
match self {
impl From<ChannelMessageId> for Option<u64> {
fn from(val: ChannelMessageId) -> Self {
match val {
ChannelMessageId::Saved(id) => Some(id),
ChannelMessageId::Pending(_) => None,
}
Expand Down
34 changes: 13 additions & 21 deletions crates/channel/src/channel_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,14 @@ impl ChannelStore {
}

pub fn initialize(&mut self) {
if !self.did_subscribe {
if self
if !self.did_subscribe
&& self
.client
.send(proto::SubscribeToChannels {})
.log_err()
.is_some()
{
self.did_subscribe = true;
}
{
self.did_subscribe = true;
}
}

Expand Down Expand Up @@ -423,7 +422,7 @@ impl ChannelStore {
) {
self.channel_states
.entry(channel_id)
.or_insert_with(|| Default::default())
.or_default()
.acknowledge_message_id(message_id);
cx.notify();
}
Expand All @@ -436,7 +435,7 @@ impl ChannelStore {
) {
self.channel_states
.entry(channel_id)
.or_insert_with(|| Default::default())
.or_default()
.update_latest_message_id(message_id);
cx.notify();
}
Expand All @@ -450,7 +449,7 @@ impl ChannelStore {
) {
self.channel_states
.entry(channel_id)
.or_insert_with(|| Default::default())
.or_default()
.acknowledge_notes_version(epoch, version);
cx.notify()
}
Expand All @@ -464,7 +463,7 @@ impl ChannelStore {
) {
self.channel_states
.entry(channel_id)
.or_insert_with(|| Default::default())
.or_default()
.update_latest_notes_version(epoch, version);
cx.notify()
}
Expand Down Expand Up @@ -924,7 +923,7 @@ impl ChannelStore {
if let Some(role) = ChannelRole::from_i32(membership.role) {
this.channel_states
.entry(ChannelId(membership.channel_id))
.or_insert_with(|| ChannelState::default())
.or_default()
.set_role(role)
}
}
Expand Down Expand Up @@ -1094,11 +1093,7 @@ impl ChannelStore {
id: ChannelId(channel.id),
visibility: channel.visibility(),
name: channel.name.into(),
parent_path: channel
.parent_path
.into_iter()
.map(|cid| ChannelId(cid))
.collect(),
parent_path: channel.parent_path.into_iter().map(ChannelId).collect(),
}),
),
}
Expand All @@ -1113,14 +1108,11 @@ impl ChannelStore {

if channels_changed {
if !payload.delete_channels.is_empty() {
let delete_channels: Vec<ChannelId> = payload
.delete_channels
.into_iter()
.map(|cid| ChannelId(cid))
.collect();
let delete_channels: Vec<ChannelId> =
payload.delete_channels.into_iter().map(ChannelId).collect();
self.channel_index.delete_channels(&delete_channels);
self.channel_participants
.retain(|channel_id, _| !delete_channels.contains(&channel_id));
.retain(|channel_id, _| !delete_channels.contains(channel_id));

for channel_id in &delete_channels {
let channel_id = *channel_id;
Expand Down
12 changes: 5 additions & 7 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Settings for ClientSettings {
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
let mut result = sources.json_merge::<Self>()?;
if let Some(server_url) = &*ZED_SERVER_URL {
result.server_url.clone_from(&server_url)
result.server_url.clone_from(server_url)
}
Ok(result)
}
Expand Down Expand Up @@ -1141,7 +1141,7 @@ impl Client {
request_headers.insert("x-zed-app-version", HeaderValue::from_str(&app_version)?);
request_headers.insert(
"x-zed-release-channel",
HeaderValue::from_str(&release_channel.map(|r| r.dev_name()).unwrap_or("unknown"))?,
HeaderValue::from_str(release_channel.map(|r| r.dev_name()).unwrap_or("unknown"))?,
);

match url_scheme {
Expand Down Expand Up @@ -1344,16 +1344,14 @@ impl Client {
);
}

let user = serde_json::from_slice::<GithubUser>(body.as_slice()).map_err(|err| {
serde_json::from_slice::<GithubUser>(body.as_slice()).map_err(|err| {
log::error!("Error deserializing: {:?}", err);
log::error!(
"GitHub API response text: {:?}",
String::from_utf8_lossy(body.as_slice())
);
anyhow!("error deserializing GitHub user")
})?;

user
})?
};

let query_params = [
Expand Down Expand Up @@ -1408,7 +1406,7 @@ impl Client {

pub async fn sign_out(self: &Arc<Self>, cx: &AsyncAppContext) {
self.state.write().credentials = None;
self.disconnect(&cx);
self.disconnect(cx);

if self.has_credentials(cx).await {
self.credentials_provider
Expand Down
Loading

0 comments on commit e6c1c51

Please sign in to comment.