Skip to content

Commit

Permalink
chore: clean up new clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
laplab committed May 3, 2024
1 parent 5446571 commit 0eb9893
Show file tree
Hide file tree
Showing 30 changed files with 122 additions and 196 deletions.
17 changes: 9 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions psl/schema-ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
diagnostics = { path = "../diagnostics" }

pest = "2.1.3"
pest_derive = "2.1.0"
pest = "2.7.10"
pest_derive = "2.7.10"
serde.workspace = true
serde_json.workspace = true
2 changes: 0 additions & 2 deletions psl/schema-ast/src/ast/find_at_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,7 @@ impl<'ast> SourcePosition<'ast> {
pub enum PropertyPosition<'ast> {
/// prop
Property,
///
Value(&'ast str),
///
FunctionValue(&'ast str),
}

Expand Down
12 changes: 6 additions & 6 deletions quaint/src/ast/function/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ pub struct TextSearch<'a> {
/// );
///
/// assert_eq!(params, vec![Value::from("chicken")]);
/// # Ok(())
/// # Ok(())
/// # }
/// ```
pub fn text_search<'a, T: Clone>(exprs: &[T]) -> super::Function<'a>
pub fn text_search<'a, T>(exprs: &[T]) -> super::Function<'a>
where
T: Into<Expression<'a>>,
T: Clone + Into<Expression<'a>>,
{
let exprs: Vec<Expression> = exprs.iter().map(|c| c.clone().into()).collect();
let fun = TextSearch { exprs };
Expand Down Expand Up @@ -57,12 +57,12 @@ pub struct TextSearchRelevance<'a> {
/// );
///
/// assert_eq!(params, vec![Value::from("chicken"), Value::from(0.1)]);
/// # Ok(())
/// # Ok(())
/// # }
/// ```
pub fn text_search_relevance<'a, E: Clone, Q>(exprs: &[E], query: Q) -> super::Function<'a>
pub fn text_search_relevance<'a, E, Q>(exprs: &[E], query: Q) -> super::Function<'a>
where
E: Into<Expression<'a>>,
E: Clone + Into<Expression<'a>>,
Q: Into<Cow<'a, str>>,
{
let exprs: Vec<Expression> = exprs.iter().map(|c| c.clone().into()).collect();
Expand Down
43 changes: 1 addition & 42 deletions quaint/src/connector/postgres/url.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#![cfg_attr(target_arch = "wasm32", allow(dead_code))]

use std::{
borrow::Cow,
fmt::{Debug, Display},
time::Duration,
};
use std::{borrow::Cow, fmt::Debug, time::Duration};

use percent_encoding::percent_decode;
use url::{Host, Url};
Expand Down Expand Up @@ -435,43 +431,6 @@ pub(crate) struct PostgresUrlQueryParams {
pub(crate) ssl_mode: SslMode,
}

// A SearchPath connection parameter (Display-impl) for connection initialization.
struct CockroachSearchPath<'a>(&'a str);

impl Display for CockroachSearchPath<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.0)
}
}

// A SearchPath connection parameter (Display-impl) for connection initialization.
struct PostgresSearchPath<'a>(&'a str);

impl Display for PostgresSearchPath<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("\"")?;
f.write_str(self.0)?;
f.write_str("\"")?;

Ok(())
}
}

// A SetSearchPath statement (Display-impl) for connection initialization.
struct SetSearchPath<'a>(Option<&'a str>);

impl Display for SetSearchPath<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(schema) = self.0 {
f.write_str("SET search_path = \"")?;
f.write_str(schema)?;
f.write_str("\";\n")?;
}

Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use super::*;
use darling::{FromMeta, ToTokens};
use proc_macro2::Span;
Expand Down Expand Up @@ -71,11 +73,11 @@ impl darling::FromMeta for RelationMode {
}
}

impl ToString for RelationMode {
fn to_string(&self) -> String {
impl Display for RelationMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Prisma => "prisma".to_string(),
Self::ForeignKeys => "foreignKeys".to_string(),
Self::Prisma => f.write_str("prisma"),
Self::ForeignKeys => f.write_str("foreignKeys"),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ use tokio::sync::{mpsc, oneshot, RwLock};

type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;

#[derive(Debug)]
struct GenericError(String);

impl Display for GenericError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

impl std::error::Error for GenericError {}

pub(crate) struct ExecutorProcess {
task_handle: mpsc::Sender<ReqImpl>,
request_id_counter: AtomicU64,
Expand Down Expand Up @@ -216,9 +205,9 @@ fn start_rpc_thread(mut receiver: mpsc::Receiver<ReqImpl>) -> Result<()> {
tokio::select! {
line = stdout.next_line() => {
match line {
// Two error modes in here: the external process can response with
// something that is not a jsonrpc response (basically any normal logging
// output), or it can respond with a jsonrpc response that represents a
// Two error modes in here: the external process can response with
// something that is not a jsonrpc response (basically any normal logging
// output), or it can respond with a jsonrpc response that represents a
// failure.
Ok(Some(line)) => // new response
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,23 @@ impl fmt::Display for ConnectorVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let printable = match self {
Self::SqlServer(v) => match v {
Some(v) => format!("SQL Server ({})", v.to_string()),
Some(v) => format!("SQL Server ({v})"),
None => "SQL Server (unknown)".to_string(),
},
Self::Postgres(v) => match v {
Some(v) => format!("PostgreSQL ({})", v.to_string()),
Some(v) => format!("PostgreSQL ({v})"),
None => "PostgreSQL (unknown)".to_string(),
},
Self::MySql(v) => match v {
Some(v) => format!("MySQL ({})", v.to_string()),
Some(v) => format!("MySQL ({v})"),
None => "MySQL (unknown)".to_string(),
},
Self::MongoDb(v) => match v {
Some(v) => format!("MongoDB ({})", v.to_string()),
Some(v) => format!("MongoDB ({v})"),
None => "MongoDB (unknown)".to_string(),
},
Self::Sqlite(v) => match v {
Some(v) => format!("SQLite ({})", v.to_string()),
Some(v) => format!("SQLite ({v})"),
None => "SQLite (unknown)".to_string(),
},
Self::Vitess(v) => match v {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use super::*;
use crate::{MongoDbSchemaRenderer, TestError};
use psl::builtin_connectors::MONGODB;
Expand Down Expand Up @@ -49,13 +51,12 @@ impl TryFrom<&str> for MongoDbVersion {
}
}

impl ToString for MongoDbVersion {
fn to_string(&self) -> String {
impl Display for MongoDbVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MongoDbVersion::V4_4 => "4.4",
&MongoDbVersion::V4_2 => "4.2",
MongoDbVersion::V5 => "5",
MongoDbVersion::V4_4 => f.write_str("4.4"),
&MongoDbVersion::V4_2 => f.write_str("4.2"),
MongoDbVersion::V5 => f.write_str("5"),
}
.to_owned()
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use super::*;
use crate::{datamodel_rendering::SqlDatamodelRenderer, BoxFuture, TestError};
use quaint::{prelude::Queryable, single::Quaint};
Expand Down Expand Up @@ -50,14 +52,13 @@ impl TryFrom<&str> for MySqlVersion {
}
}

impl ToString for MySqlVersion {
fn to_string(&self) -> String {
impl Display for MySqlVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MySqlVersion::V5_6 => "5.6",
MySqlVersion::V5_7 => "5.7",
MySqlVersion::V8 => "8",
MySqlVersion::MariaDb => "mariadb",
MySqlVersion::V5_6 => f.write_str("5.6"),
MySqlVersion::V5_7 => f.write_str("5.7"),
MySqlVersion::V8 => f.write_str("8"),
MySqlVersion::MariaDb => f.write_str("mariadb"),
}
.to_owned()
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use super::*;
use crate::{datamodel_rendering::SqlDatamodelRenderer, BoxFuture, TestError};
use quaint::{prelude::Queryable, single::Quaint};
Expand Down Expand Up @@ -68,23 +70,22 @@ impl TryFrom<&str> for PostgresVersion {
}
}

impl ToString for PostgresVersion {
fn to_string(&self) -> String {
impl Display for PostgresVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PostgresVersion::V9 => "9",
PostgresVersion::V10 => "10",
PostgresVersion::V11 => "11",
PostgresVersion::V12 => "12",
PostgresVersion::V13 => "13",
PostgresVersion::V14 => "14",
PostgresVersion::V15 => "15",
PostgresVersion::V16 => "16",
PostgresVersion::PgBouncer => "pgbouncer",
PostgresVersion::NeonJsNapi => "neon.js",
PostgresVersion::PgJsNapi => "pg.js",
PostgresVersion::PgJsWasm => "pg.js.wasm",
PostgresVersion::NeonJsWasm => "pg.js.wasm",
PostgresVersion::V9 => f.write_str("9"),
PostgresVersion::V10 => f.write_str("10"),
PostgresVersion::V11 => f.write_str("11"),
PostgresVersion::V12 => f.write_str("12"),
PostgresVersion::V13 => f.write_str("13"),
PostgresVersion::V14 => f.write_str("14"),
PostgresVersion::V15 => f.write_str("15"),
PostgresVersion::V16 => f.write_str("16"),
PostgresVersion::PgBouncer => f.write_str("pgbouncer"),
PostgresVersion::NeonJsNapi => f.write_str("neon.js"),
PostgresVersion::PgJsNapi => f.write_str("pg.js"),
PostgresVersion::PgJsWasm => f.write_str("pg.js.wasm"),
PostgresVersion::NeonJsWasm => f.write_str("pg.js.wasm"),
}
.to_owned()
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use quaint::{prelude::Queryable, single::Quaint};

use super::*;
Expand Down Expand Up @@ -49,13 +51,12 @@ impl TryFrom<&str> for SqlServerVersion {
}
}

impl ToString for SqlServerVersion {
fn to_string(&self) -> String {
impl Display for SqlServerVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SqlServerVersion::V2017 => "2017",
SqlServerVersion::V2019 => "2019",
SqlServerVersion::V2022 => "2022",
SqlServerVersion::V2017 => f.write_str("2017"),
SqlServerVersion::V2019 => f.write_str("2019"),
SqlServerVersion::V2022 => f.write_str("2022"),
}
.to_owned()
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use super::*;
use crate::{BoxFuture, SqlDatamodelRenderer};
use quaint::{prelude::Queryable, single::Quaint};
Expand Down Expand Up @@ -35,14 +37,14 @@ pub enum SqliteVersion {
CloudflareD1,
}

impl ToString for SqliteVersion {
fn to_string(&self) -> String {
impl Display for SqliteVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SqliteVersion::ReactNative => "react-native".to_string(),
SqliteVersion::V3 => "3".to_string(),
SqliteVersion::LibsqlJsNapi => "libsql.js".to_string(),
SqliteVersion::LibsqlJsWasm => "libsql.js.wasm".to_string(),
SqliteVersion::CloudflareD1 => "cfd1".to_owned(),
SqliteVersion::ReactNative => f.write_str("react-native"),
SqliteVersion::V3 => f.write_str("3"),
SqliteVersion::LibsqlJsNapi => f.write_str("libsql.js"),
SqliteVersion::LibsqlJsWasm => f.write_str("libsql.js.wasm"),
SqliteVersion::CloudflareD1 => f.write_str("cfd1"),
}
}
}
Expand Down
Loading

0 comments on commit 0eb9893

Please sign in to comment.