Skip to content

Commit

Permalink
One big cleanup pass of clippy lints
Browse files Browse the repository at this point in the history
Co-authored-by: Mikayla <[email protected]>
  • Loading branch information
2 people authored and K Simmons committed Aug 10, 2022
1 parent e7540d2 commit 8ba2f77
Show file tree
Hide file tree
Showing 138 changed files with 1,328 additions and 1,366 deletions.
6 changes: 6 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[target.'cfg(all())']
rustflags = [
"-Aclippy::reversed_empty_ranges",
"-Aclippy::missing_safety_doc",
"-Aclippy::let_unit_value",
]
8 changes: 4 additions & 4 deletions crates/activity_indicator/src/activity_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use workspace::{ItemHandle, StatusItemView, Workspace};

actions!(lsp_status, [ShowErrorMessage]);

const DOWNLOAD_ICON: &'static str = "icons/download_12.svg";
const WARNING_ICON: &'static str = "icons/triangle_exclamation_12.svg";
const DONE_ICON: &'static str = "icons/circle_check_12.svg";
const DOWNLOAD_ICON: &str = "icons/download_12.svg";
const WARNING_ICON: &str = "icons/triangle_exclamation_12.svg";
const DONE_ICON: &str = "icons/circle_check_12.svg";

pub enum Event {
ShowError { lsp_name: Arc<str>, error: String },
Expand Down Expand Up @@ -76,7 +76,7 @@ impl ActivityIndicator {
cx.subscribe(&this, move |workspace, _, event, cx| match event {
Event::ShowError { lsp_name, error } => {
if let Some(buffer) = project
.update(cx, |project, cx| project.create_buffer(&error, None, cx))
.update(cx, |project, cx| project.create_buffer(error, None, cx))
.log_err()
{
buffer.update(cx, |buffer, cx| {
Expand Down
5 changes: 2 additions & 3 deletions crates/auto_update/src/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use std::{env, ffi::OsString, path::PathBuf, sync::Arc, time::Duration};
use update_notification::UpdateNotification;
use workspace::Workspace;

const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &'static str =
"auto-updater-should-show-updated-notification";
const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &str = "auto-updater-should-show-updated-notification";
const POLL_INTERVAL: Duration = Duration::from_secs(60 * 60);

lazy_static! {
Expand Down Expand Up @@ -61,7 +60,7 @@ pub fn init(
server_url: String,
cx: &mut MutableAppContext,
) {
if let Some(version) = ZED_APP_VERSION.clone().or(cx.platform().app_version().ok()) {
if let Some(version) = (*ZED_APP_VERSION).or_else(|| cx.platform().app_version().ok()) {
let auto_updater = cx.add_model(|cx| {
let updater = AutoUpdater::new(version, db.clone(), http_client, server_url.clone());
updater.start_polling(cx).detach();
Expand Down
4 changes: 2 additions & 2 deletions crates/chat_panel/src/chat_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl ChatPanel {
let theme = &cx.global::<Settings>().theme.chat_panel.channel_select;
SelectStyle {
header: theme.header.container,
menu: theme.menu.clone(),
menu: theme.menu,
}
})
});
Expand All @@ -91,7 +91,7 @@ impl ChatPanel {
let _observe_status = cx.spawn_weak(|this, mut cx| {
let mut status = rpc.status();
async move {
while let Some(_) = status.recv().await {
while (status.recv().await).is_some() {
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |_, cx| cx.notify());
} else {
Expand Down
14 changes: 7 additions & 7 deletions crates/client/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl ChannelList {
}

pub fn available_channels(&self) -> Option<&[ChannelDetails]> {
self.available_channels.as_ref().map(Vec::as_slice)
self.available_channels.as_deref()
}

pub fn get_channel(
Expand Down Expand Up @@ -601,8 +601,8 @@ mod tests {

let user_id = 5;
let http_client = FakeHttpClient::with_404_response();
let mut client = Client::new(http_client.clone());
let server = FakeServer::for_client(user_id, &mut client, &cx).await;
let client = Client::new(http_client.clone());
let server = FakeServer::for_client(user_id, &client, cx).await;

Channel::init(&client);
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
Expand All @@ -623,7 +623,7 @@ mod tests {
},
)
.await;
channel_list.next_notification(&cx).await;
channel_list.next_notification(cx).await;
channel_list.read_with(cx, |list, _| {
assert_eq!(
list.available_channels().unwrap(),
Expand Down Expand Up @@ -701,7 +701,7 @@ mod tests {
.await;

assert_eq!(
channel.next_event(&cx).await,
channel.next_event(cx).await,
ChannelEvent::MessagesUpdated {
old_range: 0..0,
new_count: 2,
Expand Down Expand Up @@ -749,7 +749,7 @@ mod tests {
.await;

assert_eq!(
channel.next_event(&cx).await,
channel.next_event(cx).await,
ChannelEvent::MessagesUpdated {
old_range: 2..2,
new_count: 1,
Expand Down Expand Up @@ -798,7 +798,7 @@ mod tests {
.await;

assert_eq!(
channel.next_event(&cx).await,
channel.next_event(cx).await,
ChannelEvent::MessagesUpdated {
old_range: 0..0,
new_count: 2,
Expand Down
30 changes: 17 additions & 13 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ pub use user::*;

lazy_static! {
pub static ref ZED_SERVER_URL: String =
std::env::var("ZED_SERVER_URL").unwrap_or("https://zed.dev".to_string());
std::env::var("ZED_SERVER_URL").unwrap_or_else(|_| "https://zed.dev".to_string());
pub static ref IMPERSONATE_LOGIN: Option<String> = std::env::var("ZED_IMPERSONATE")
.ok()
.and_then(|s| if s.is_empty() { None } else { Some(s) });
}

pub const ZED_SECRET_CLIENT_TOKEN: &'static str = "618033988749894";
pub const ZED_SECRET_CLIENT_TOKEN: &str = "618033988749894";

actions!(client, [Authenticate]);

Expand All @@ -65,10 +65,13 @@ pub struct Client {
http: Arc<dyn HttpClient>,
state: RwLock<ClientState>,

#[allow(clippy::type_complexity)]
#[cfg(any(test, feature = "test-support"))]
authenticate: RwLock<
Option<Box<dyn 'static + Send + Sync + Fn(&AsyncAppContext) -> Task<Result<Credentials>>>>,
>,

#[allow(clippy::type_complexity)]
#[cfg(any(test, feature = "test-support"))]
establish_connection: RwLock<
Option<
Expand Down Expand Up @@ -149,6 +152,7 @@ struct ClientState {
entities_by_type_and_remote_id: HashMap<(TypeId, u64), AnyWeakEntityHandle>,
models_by_message_type: HashMap<TypeId, AnyWeakModelHandle>,
entity_types_by_message_type: HashMap<TypeId, TypeId>,
#[allow(clippy::type_complexity)]
message_handlers: HashMap<
TypeId,
Arc<
Expand Down Expand Up @@ -596,7 +600,7 @@ impl Client {
let mut status_rx = self.status();
let _ = status_rx.next().await;
futures::select_biased! {
authenticate = self.authenticate(&cx).fuse() => {
authenticate = self.authenticate(cx).fuse() => {
match authenticate {
Ok(creds) => credentials = Some(creds),
Err(err) => {
Expand Down Expand Up @@ -819,7 +823,7 @@ impl Client {
.get("Location")
.ok_or_else(|| anyhow!("missing location header in /rpc response"))?
.to_str()
.map_err(|error| EstablishConnectionError::other(error))?
.map_err(EstablishConnectionError::other)?
.to_string();
}
// Until we switch the zed.dev domain to point to the new Next.js app, there
Expand Down Expand Up @@ -1051,7 +1055,7 @@ fn write_credentials_to_keychain(credentials: &Credentials, cx: &AsyncAppContext
)
}

const WORKTREE_URL_PREFIX: &'static str = "zed://worktrees/";
const WORKTREE_URL_PREFIX: &str = "zed://worktrees/";

pub fn encode_worktree_url(id: u64, access_token: &str) -> String {
format!("{}{}/{}", WORKTREE_URL_PREFIX, id, access_token)
Expand Down Expand Up @@ -1081,8 +1085,8 @@ mod tests {
cx.foreground().forbid_parking();

let user_id = 5;
let mut client = Client::new(FakeHttpClient::with_404_response());
let server = FakeServer::for_client(user_id, &mut client, &cx).await;
let client = Client::new(FakeHttpClient::with_404_response());
let server = FakeServer::for_client(user_id, &client, cx).await;
let mut status = client.status();
assert!(matches!(
status.next().await,
Expand Down Expand Up @@ -1169,8 +1173,8 @@ mod tests {
cx.foreground().forbid_parking();

let user_id = 5;
let mut client = Client::new(FakeHttpClient::with_404_response());
let server = FakeServer::for_client(user_id, &mut client, &cx).await;
let client = Client::new(FakeHttpClient::with_404_response());
let server = FakeServer::for_client(user_id, &client, cx).await;

let (done_tx1, mut done_rx1) = smol::channel::unbounded();
let (done_tx2, mut done_rx2) = smol::channel::unbounded();
Expand Down Expand Up @@ -1215,8 +1219,8 @@ mod tests {
cx.foreground().forbid_parking();

let user_id = 5;
let mut client = Client::new(FakeHttpClient::with_404_response());
let server = FakeServer::for_client(user_id, &mut client, &cx).await;
let client = Client::new(FakeHttpClient::with_404_response());
let server = FakeServer::for_client(user_id, &client, cx).await;

let model = cx.add_model(|_| Model::default());
let (done_tx1, _done_rx1) = smol::channel::unbounded();
Expand All @@ -1243,8 +1247,8 @@ mod tests {
cx.foreground().forbid_parking();

let user_id = 5;
let mut client = Client::new(FakeHttpClient::with_404_response());
let server = FakeServer::for_client(user_id, &mut client, &cx).await;
let client = Client::new(FakeHttpClient::with_404_response());
let server = FakeServer::for_client(user_id, &client, cx).await;

let model = cx.add_model(|_| Model::default());
let (done_tx, mut done_rx) = smol::channel::unbounded();
Expand Down
4 changes: 2 additions & 2 deletions crates/client/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub type Request = isahc::Request<AsyncBody>;
pub type Response = isahc::Response<AsyncBody>;

pub trait HttpClient: Send + Sync {
fn send<'a>(&'a self, req: Request) -> BoxFuture<'a, Result<Response, Error>>;
fn send(&self, req: Request) -> BoxFuture<Result<Response, Error>>;

fn get<'a>(
&'a self,
Expand Down Expand Up @@ -45,7 +45,7 @@ pub fn client() -> Arc<dyn HttpClient> {
}

impl HttpClient for isahc::HttpClient {
fn send<'a>(&'a self, req: Request) -> BoxFuture<'a, Result<Response, Error>> {
fn send(&self, req: Request) -> BoxFuture<Result<Response, Error>> {
Box::pin(async move { self.send_async(req).await })
}
}
9 changes: 5 additions & 4 deletions crates/client/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl FakeServer {
}
})
.override_establish_connection({
let peer = Arc::downgrade(&server.peer).clone();
let peer = Arc::downgrade(&server.peer);
let state = Arc::downgrade(&server.state);
move |credentials, cx| {
let peer = peer.clone();
Expand Down Expand Up @@ -123,6 +123,7 @@ impl FakeServer {
self.peer.send(self.connection_id(), message).unwrap();
}

#[allow(clippy::await_holding_lock)]
pub async fn receive<M: proto::EnvelopedMessage>(&self) -> Result<TypedEnvelope<M>> {
self.executor.start_waiting();
let message = self
Expand Down Expand Up @@ -194,7 +195,7 @@ pub struct FakeHttpClient {
}

impl FakeHttpClient {
pub fn new<Fut, F>(handler: F) -> Arc<dyn HttpClient>
pub fn create<Fut, F>(handler: F) -> Arc<dyn HttpClient>
where
Fut: 'static + Send + Future<Output = Result<Response, http::Error>>,
F: 'static + Send + Sync + Fn(Request) -> Fut,
Expand All @@ -205,7 +206,7 @@ impl FakeHttpClient {
}

pub fn with_404_response() -> Arc<dyn HttpClient> {
Self::new(|_| async move {
Self::create(|_| async move {
Ok(isahc::Response::builder()
.status(404)
.body(Default::default())
Expand All @@ -221,7 +222,7 @@ impl fmt::Debug for FakeHttpClient {
}

impl HttpClient for FakeHttpClient {
fn send<'a>(&'a self, req: Request) -> BoxFuture<'a, Result<Response, crate::http::Error>> {
fn send(&self, req: Request) -> BoxFuture<Result<Response, crate::http::Error>> {
let future = (self.handler)(req);
Box::pin(async move { future.await.map(Into::into) })
}
Expand Down
2 changes: 1 addition & 1 deletion crates/client/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct User {

impl PartialOrd for User {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(&other))
Some(self.cmp(other))
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/clock/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ impl<'a> Add<&'a Self> for Local {
type Output = Local;

fn add(self, other: &'a Self) -> Self::Output {
cmp::max(&self, other).clone()
*cmp::max(&self, other)
}
}

impl<'a> AddAssign<&'a Local> for Local {
fn add_assign(&mut self, other: &Self) {
if *self < *other {
*self = other.clone();
*self = *other;
}
}
}
Expand Down Expand Up @@ -177,7 +177,7 @@ impl Global {
false
}

pub fn iter<'a>(&'a self) -> impl 'a + Iterator<Item = Local> {
pub fn iter(&self) -> impl Iterator<Item = Local> + '_ {
self.0.iter().enumerate().map(|(replica_id, seq)| Local {
replica_id: replica_id as ReplicaId,
value: *seq,
Expand Down
2 changes: 1 addition & 1 deletion crates/collab/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ async fn create_access_token(
} else {
return Err(Error::Http(
StatusCode::UNAUTHORIZED,
format!("you do not have permission to impersonate other users"),
"you do not have permission to impersonate other users".to_string(),
));
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/collab/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub async fn validate_header<B>(mut req: Request<B>, next: Next<B>) -> impl Into
let state = req.extensions().get::<Arc<AppState>>().unwrap();
let mut credentials_valid = false;
for password_hash in state.db.get_access_token_hashes(user_id).await? {
if verify_access_token(&access_token, &password_hash)? {
if verify_access_token(access_token, &password_hash)? {
credentials_valid = true;
break;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn encrypt_access_token(access_token: &str, public_key: String) -> Result<St
let native_app_public_key =
rpc::auth::PublicKey::try_from(public_key).context("failed to parse app public key")?;
let encrypted_access_token = native_app_public_key
.encrypt_string(&access_token)
.encrypt_string(access_token)
.context("failed to encrypt access token with public key")?;
Ok(encrypted_access_token)
}
Expand Down
Loading

0 comments on commit 8ba2f77

Please sign in to comment.