Skip to content

Commit

Permalink
Fix clippy errors and warnings with Rust 1.72 (prisma#4169)
Browse files Browse the repository at this point in the history
* clippy: fix auto-fixable issues

* clippy: fix incorrect_clone_impl_on_copy_type lint

* clippy: fix manual_try_fold

* clippy: fix auto-fixable problems in quaint

* clippy: allow module_inception in tests

* se: fix deprecation warnings

* clippy: fix redundant_pattern_matching

* clippy: fix zero_prefixed_literal

* qe: disable clippy::needless_raw_string_hashes in tests

`insta` relies on triple-hash strings in snapshots, see
https://prisma-company.slack.com/archives/C4GCG53BP/p1692960497395659?thread_ts=1692960083.600799&cid=C4GCG53BP

* qe: disable clippy::needless_raw_string_hashes in black-box-tests

* qe: disable clippy::needless_raw_string_hashes in protocol_adapter tests

* se: fix needless_raw_string_hashes

* quaint: fix formatting
  • Loading branch information
aqrln authored Aug 25, 2023
1 parent 9f8ddf5 commit f957933
Show file tree
Hide file tree
Showing 48 changed files with 171 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ pub(super) fn validate_unsupported_field_type(field: ScalarFieldWalker<'_>, ctx:
let source = if let Some(s) = ctx.datasource { s } else { return };

static TYPE_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r#"(?x)
Regex::new(r"(?x)
^ # beginning of the string
(?P<prefix>[^(]+) # a required prefix that is any character until the first opening brace
(?:\((?P<params>.*?)\))? # (optional) an opening parenthesis, a closing parenthesis and captured params in-between
(?P<suffix>.+)? # (optional) captured suffix after the params until the end of the string
$ # end of the string
"#).unwrap()
").unwrap()
});

let connector = source.active_connector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,17 @@ mod tests {
use super::is_leftwise_included_it;
#[test]
fn test_is_left_wise_included() {
let item = vec![1, 2];
let group = vec![1, 2, 3, 4];
let item = [1, 2];
let group = [1, 2, 3, 4];
assert!(is_leftwise_included_it(item.iter(), group.iter()));
let item = vec![1, 2, 3, 4];
let group = vec![1, 2, 3, 4];
let item = [1, 2, 3, 4];
let group = [1, 2, 3, 4];
assert!(is_leftwise_included_it(item.iter(), group.iter()));
let item = vec![1, 2, 3, 4];
let group = vec![1, 2];
let item = [1, 2, 3, 4];
let group = [1, 2];
assert!(!is_leftwise_included_it(item.iter(), group.iter()));
let item = vec![2, 3];
let group = vec![1, 2, 3, 4];
let item = [2, 3];
let group = [1, 2, 3, 4];
assert!(!is_leftwise_included_it(item.iter(), group.iter()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub(crate) fn validate_no_referential_actions(
field
.explicit_on_delete_span()
.into_iter()
.chain(field.explicit_on_update_span().into_iter())
.chain(field.explicit_on_update_span())
});

for span in referential_action_spans {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) fn validate_no_referential_actions(relation: ImplicitManyToManyRelati
field
.explicit_on_delete_span()
.into_iter()
.chain(field.explicit_on_update_span().into_iter())
.chain(field.explicit_on_update_span())
});

for span in referential_action_spans {
Expand Down
2 changes: 1 addition & 1 deletion psl/psl/tests/parsing/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ fn sql_server_absolute_windows_ca_file_should_not_be_modified() {
.unwrap();

assert_eq!(
r#"sqlserver://localhost:1433;trustServerCertificateCA=C:{\\}path{\}customCA.crt"#,
r"sqlserver://localhost:1433;trustServerCertificateCA=C:{\\}path{\}customCA.crt",
url
)
}
6 changes: 3 additions & 3 deletions psl/schema-ast/src/parser/parse_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ fn parse_string_literal(token: Pair<'_>, diagnostics: &mut Diagnostics) -> Strin
final_span.start += start;
final_span.end = final_span.start + 1 + c.len_utf8();
diagnostics.push_error(DatamodelError::new_static(
r#"Unknown escape sequence. If the value is a windows-style path, `\` must be escaped as `\\`."#,
final_span
r"Unknown escape sequence. If the value is a windows-style path, `\` must be escaped as `\\`.",
final_span,
));
}
},
Expand Down Expand Up @@ -162,7 +162,7 @@ fn try_parse_unicode_codepoint(
}
(consumed_second_codepoint, Some(second_codepoint)) => {
// UTF-16 surrogate with
let char = match char::decode_utf16([first_codepoint, second_codepoint].into_iter()).next() {
let char = match char::decode_utf16([first_codepoint, second_codepoint]).next() {
Some(Ok(c)) => Some(c),
_ => {
diagnostics.push_error(unicode_sequence_error(
Expand Down
2 changes: 1 addition & 1 deletion quaint/src/ast/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'a> Compare<'a> {
let base_select = super::Select::from_table(ident).column(selected_columns.remove(0));

// We know we have the same amount of columns on both sides,
let column_pairs = cols.into_iter().zip(selected_columns.into_iter());
let column_pairs = cols.into_iter().zip(selected_columns);

// Adding to the new select a condition to filter out the rest of
// the tuple, so if our tuple is `(a, b) IN (SELECT x, y ..)`, this
Expand Down
6 changes: 3 additions & 3 deletions quaint/src/ast/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'a> TryFrom<Insert<'a>> for Merge<'a> {

let query = match insert.values.kind {
ExpressionKind::Row(row) => {
let cols_vals = columns.iter().zip(row.values.into_iter());
let cols_vals = columns.iter().zip(row.values);

let select = cols_vals.fold(Select::default(), |query, (col, val)| {
query.value(val.alias(col.name.clone()))
Expand All @@ -117,14 +117,14 @@ impl<'a> TryFrom<Insert<'a>> for Merge<'a> {
ExpressionKind::Values(values) => {
let mut rows = values.rows;
let row = rows.pop().unwrap();
let cols_vals = columns.iter().zip(row.values.into_iter());
let cols_vals = columns.iter().zip(row.values);

let select = cols_vals.fold(Select::default(), |query, (col, val)| {
query.value(val.alias(col.name.clone()))
});

let union = rows.into_iter().fold(Union::new(select), |union, row| {
let cols_vals = columns.iter().zip(row.values.into_iter());
let cols_vals = columns.iter().zip(row.values);

let select = cols_vals.fold(Select::default(), |query, (col, val)| {
query.value(val.alias(col.name.clone()))
Expand Down
5 changes: 1 addition & 4 deletions quaint/src/ast/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ impl<'a> Update<'a> {
/// # }
/// ```
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg_attr(
feature = "docs",
doc(cfg(any(feature = "postgresql", feature = "sqlite")))
)]
#[cfg_attr(feature = "docs", doc(cfg(any(feature = "postgresql", feature = "sqlite"))))]
pub fn returning<K, I>(mut self, columns: I) -> Self
where
K: Into<Column<'a>>,
Expand Down
6 changes: 3 additions & 3 deletions quaint/src/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2991,7 +2991,7 @@ async fn generate_binary_uuid(api: &mut dyn TestApi) -> crate::Result<()> {
let val = res.into_single()?;

// If it is a byte type and has a value, it's a generated UUID.
assert!(matches!(val, Value::Bytes(x) if matches!(x, Some(_))));
assert!(matches!(val, Value::Bytes(x) if x.is_some()));

Ok(())
}
Expand All @@ -3004,7 +3004,7 @@ async fn generate_swapped_binary_uuid(api: &mut dyn TestApi) -> crate::Result<()
let val = res.into_single()?;

// If it is a byte type and has a value, it's a generated UUID.
assert!(matches!(val, Value::Bytes(x) if matches!(x, Some(_))));
assert!(matches!(val, Value::Bytes(x) if x.is_some()));

Ok(())
}
Expand All @@ -3017,7 +3017,7 @@ async fn generate_native_uuid(api: &mut dyn TestApi) -> crate::Result<()> {
let val = res.into_single()?;

// If it is a text type and has a value, it's a generated string UUID.
assert!(matches!(val, Value::Text(x) if matches!(x, Some(_))));
assert!(matches!(val, Value::Text(x) if x.is_some()));

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion quaint/src/tests/types/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ async fn test_get_int64_from_int32_field_fails(api: &mut dyn TestApi) -> crate::
let select = Select::from_table(&table).column("value").order_by("id".descend());
let res = api.conn().select(select).await;

assert!(matches!(res, Err(_)));
assert!(res.is_err());

Ok(())
}
4 changes: 2 additions & 2 deletions quaint/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ pub trait Visitor<'a> {

{
self.write(" SET ")?;
let pairs = update.columns.into_iter().zip(update.values.into_iter());
let pairs = update.columns.into_iter().zip(update.values);
let len = pairs.len();

for (i, (key, value)) in pairs.enumerate() {
Expand Down Expand Up @@ -365,7 +365,7 @@ pub trait Visitor<'a> {
}

fn visit_update_set(&mut self, update: Update<'a>) -> Result {
let pairs = update.columns.into_iter().zip(update.values.into_iter());
let pairs = update.columns.into_iter().zip(update.values);
let len = pairs.len();

for (i, (key, value)) in pairs.enumerate() {
Expand Down
2 changes: 2 additions & 0 deletions query-engine/black-box-tests/tests/black_box_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::module_inception, clippy::needless_raw_string_hashes)]

mod helpers;

mod metrics;
Expand Down
4 changes: 2 additions & 2 deletions query-engine/black-box-tests/tests/metrics/smoke_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod smoke_tests {
let res = client
.post("http://0.0.0.0:57582/")
.body(
r###"
r#"
{
"action": "findMany",
"modelName": "Person",
Expand All @@ -38,7 +38,7 @@ mod smoke_tests {
}
}
}
"###,
"#,
)
.send()
.await
Expand Down
8 changes: 4 additions & 4 deletions query-engine/black-box-tests/tests/protocols/mismatched.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::helpers::*;
use query_engine_tests::*;

const JSON_QUERY: &str = r###"
const JSON_QUERY: &str = r#"
{
"action": "findMany",
"modelName": "Person",
Expand All @@ -13,15 +13,15 @@ const JSON_QUERY: &str = r###"
}
}
}
"###;
"#;

const GRAPHQL_QUERY: &str = r###"
const GRAPHQL_QUERY: &str = r#"
{
"operationName": null,
"variables": {},
"query": "{\n findManyPerson {\n id\n }\n}\n"
}
"###;
"#;

#[test_suite(schema(schema))]
mod mismatched {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ mod interactive_tx {
// Mongo for example doesn't read the inner commit value.
is_one_of!(
run_query!(&runner, r#"query { findManyTestModel { id }}"#),
vec![
[
r#"{"data":{"findManyTestModel":[{"id":1}]}}"#,
r#"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"#
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ mod json_filters {
// MySQL has slightly different semantics and also coerces null to [null].
is_one_of!(
run_query!(runner, jsonq(&runner, r#"array_contains: "null""#, None)),
vec![
[
r#"{"data":{"findManyTestModel":[{"id":7}]}}"#,
r#"{"data":{"findManyTestModel":[{"id":7},{"id":8}]}}"#
]
);

is_one_of!(
run_query!(runner, jsonq(&runner, r#"array_contains: "[null]""#, None)),
vec![
[
r#"{"data":{"findManyTestModel":[{"id":7}]}}"#,
r#"{"data":{"findManyTestModel":[{"id":7},{"id":8}]}}"#
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ mod views {
&runner,
r#"{ findManyTestView(orderBy: { children: { _count: asc } }) { id _count { children } } }"#
),
vec![
[
r#"{"data":{"findManyTestView":[{"id":2,"_count":{"children":0}},{"id":3,"_count":{"children":0}},{"id":1,"_count":{"children":2}}]}}"#,
r#"{"data":{"findManyTestView":[{"id":3,"_count":{"children":0}},{"id":2,"_count":{"children":0}},{"id":1,"_count":{"children":2}}]}}"#,
r#"{"data":{"findManyTestView":[{"id":3,"_count":{"children":0}},{"id":2,"_count":{"children":0}},{"id":1,"_count":{"children":2}}]}}"#
]
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#![allow(clippy::module_inception, clippy::too_many_arguments)]
#![allow(
clippy::module_inception,
clippy::too_many_arguments,
clippy::needless_raw_string_hashes
)]

mod new;
mod queries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod update_many {

is_one_of!(
query_number_operation(&runner, "optInt", "increment", "10").await?,
vec![
[
r#"{"data":{"findManyTestModel":[{"optInt":null},{"optInt":12},{"optInt":13}]}}"#,
r#"{"data":{"findManyTestModel":[{"optInt":10},{"optInt":12},{"optInt":13}]}}"#
]
Expand All @@ -140,7 +140,7 @@ mod update_many {
// optInts before this op are now: null/10, 12, 13
is_one_of!(
query_number_operation(&runner, "optInt", "decrement", "10").await?,
vec![
[
r#"{"data":{"findManyTestModel":[{"optInt":null},{"optInt":2},{"optInt":3}]}}"#,
r#"{"data":{"findManyTestModel":[{"optInt":0},{"optInt":2},{"optInt":3}]}}"#
]
Expand All @@ -149,7 +149,7 @@ mod update_many {
// optInts before this op are now: null/0, 2, 3
is_one_of!(
query_number_operation(&runner, "optInt", "multiply", "2").await?,
vec![
[
r#"{"data":{"findManyTestModel":[{"optInt":null},{"optInt":4},{"optInt":6}]}}"#,
r#"{"data":{"findManyTestModel":[{"optInt":0},{"optInt":4},{"optInt":6}]}}"#
]
Expand All @@ -160,7 +160,7 @@ mod update_many {
// optInts before this op are now: null/0, 4, 6
is_one_of!(
query_number_operation(&runner, "optInt", "divide", "3").await?,
vec![
[
r#"{"data":{"findManyTestModel":[{"optInt":null},{"optInt":1},{"optInt":2}]}}"#,
r#"{"data":{"findManyTestModel":[{"optInt":0},{"optInt":1},{"optInt":2}]}}"#
]
Expand All @@ -169,15 +169,15 @@ mod update_many {

is_one_of!(
query_number_operation(&runner, "optInt", "set", "5").await?,
vec![
[
r#"{"data":{"findManyTestModel":[{"optInt":5},{"optInt":5},{"optInt":5}]}}"#,
r#"{"data":{"findManyTestModel":[{"optInt":5},{"optInt":5},{"optInt":5}]}}"#
]
);

is_one_of!(
query_number_operation(&runner, "optInt", "set", "null").await?,
vec![
[
r#"{"data":{"findManyTestModel":[{"optInt":null},{"optInt":null},{"optInt":null}]}}"#,
r#"{"data":{"findManyTestModel":[{"optInt":null},{"optInt":null},{"optInt":null}]}}"#
]
Expand All @@ -196,7 +196,7 @@ mod update_many {

is_one_of!(
query_number_operation(&runner, "optInt", "increment", "10").await?,
vec![
[
r#"{"data":{"findManyTestModel":[{"optInt":null},{"optInt":12},{"optInt":13}]}}"#,
r#"{"data":{"findManyTestModel":[{"optInt":10},{"optInt":12},{"optInt":13}]}}"#
]
Expand All @@ -205,7 +205,7 @@ mod update_many {
// optInts before this op are now: null/10, 12, 13
is_one_of!(
query_number_operation(&runner, "optInt", "decrement", "10").await?,
vec![
[
r#"{"data":{"findManyTestModel":[{"optInt":null},{"optInt":2},{"optInt":3}]}}"#,
r#"{"data":{"findManyTestModel":[{"optInt":0},{"optInt":2},{"optInt":3}]}}"#
]
Expand All @@ -214,23 +214,23 @@ mod update_many {
// optInts before this op are now: null/0, 2, 3
is_one_of!(
query_number_operation(&runner, "optInt", "multiply", "2").await?,
vec![
[
r#"{"data":{"findManyTestModel":[{"optInt":null},{"optInt":4},{"optInt":6}]}}"#,
r#"{"data":{"findManyTestModel":[{"optInt":0},{"optInt":4},{"optInt":6}]}}"#
]
);

is_one_of!(
query_number_operation(&runner, "optInt", "set", "5").await?,
vec![
[
r#"{"data":{"findManyTestModel":[{"optInt":5},{"optInt":5},{"optInt":5}]}}"#,
r#"{"data":{"findManyTestModel":[{"optInt":5},{"optInt":5},{"optInt":5}]}}"#
]
);

is_one_of!(
query_number_operation(&runner, "optInt", "set", "null").await?,
vec![
[
r#"{"data":{"findManyTestModel":[{"optInt":null},{"optInt":null},{"optInt":null}]}}"#,
r#"{"data":{"findManyTestModel":[{"optInt":null},{"optInt":null},{"optInt":null}]}}"#
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl IntoBson for (&MongoDbType, PrismaValue) {
}

let mut bytes: [u8; 12] = [0x0; 12];
bytes.iter_mut().set_from(b.into_iter());
bytes.iter_mut().set_from(b);

Bson::ObjectId(ObjectId::from_bytes(bytes))
}
Expand Down
Loading

0 comments on commit f957933

Please sign in to comment.