Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Lints #156

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Lints #156

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .buildkite/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ docker run -w /build --network test-net -v $BUILDKITE_BUILD_CHECKOUT_PATH:/build
-e TEST_MYSQL=mysql://prisma:prisma@test-mysql:3306/prisma \
-e TEST_PSQL=postgres://prisma:prisma@test-postgres:5432/prisma \
-e TEST_MSSQL="sqlserver://test-mssql:1433;user=SA;password=$MSSQL_SA_PASSWORD;trustServerCertificate=true" \
-e RUSTFLAGS="-Dwarnings" \
Copy link
Contributor Author

@yoshuawuyts yoshuawuyts Jul 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures we don't ship warnings to our main branch, but allows them to exist during local development.

prismagraphql/build:test cargo test --features full,json-1,uuid-0_8,chrono-0_4,tracing-log,serde-support

exit_code=$?
Expand Down
2 changes: 1 addition & 1 deletion src/ast/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ where
}

impl<'a> PartialEq for Column<'a> {
fn eq(&self, other: &Column) -> bool {
fn eq(&self, other: &Column<'_>) -> bool {
self.name == other.name && self.table == other.table
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ast/grouping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ pub trait IntoGroupByDefinition<'a> {

impl<'a> IntoGroupByDefinition<'a> for &'a str {
fn into_group_by_definition(self) -> GroupByDefinition<'a> {
let column: Column = self.into();
let column: Column<'_> = self.into();
column.into()
}
}

impl<'a> IntoGroupByDefinition<'a> for (&'a str, &'a str) {
fn into_group_by_definition(self) -> GroupByDefinition<'a> {
let column: Column = self.into();
let column: Column<'_> = self.into();
column.into()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ast/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<'a> IndexDefinition<'a> {
}

/// True if the index definition contains the given column.
pub fn contains(&self, column: &Column) -> bool {
pub fn contains(&self, column: &Column<'_>) -> bool {
match self {
Self::Single(ref c) if c == column => true,
Self::Compound(ref cols) if cols.iter().any(|c| c == column) => true,
Expand Down
4 changes: 2 additions & 2 deletions src/ast/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Table<'a> {
}

impl<'a> PartialEq for Table<'a> {
fn eq(&self, other: &Table) -> bool {
fn eq(&self, other: &Table<'_>) -> bool {
self.typ == other.typ && self.database == other.database
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ impl<'a> Table<'a> {
Some(dual_col.equals(column.clone()).into())
};

Ok::<Option<ConditionTree>, Error>(cond)
Ok::<Option<ConditionTree<'_>>, Error>(cond)
};

for index in self.index_definitions.iter() {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) enum UnionType {
}

impl fmt::Display for UnionType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
UnionType::All => write!(f, "UNION ALL"),
UnionType::Distinct => write!(f, "UNION"),
Expand Down
2 changes: 1 addition & 1 deletion src/connector/connection_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl ConnectionInfo {
}

/// The provided database user name. This will be `None` on SQLite.
pub fn username(&self) -> Option<Cow<str>> {
pub fn username(&self) -> Option<Cow<'_, str>> {
match self {
#[cfg(feature = "postgresql")]
ConnectionInfo::Postgres(url) => Some(url.username()),
Expand Down
4 changes: 2 additions & 2 deletions src/connector/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl MysqlUrl {
}

/// The percent-decoded database username.
pub fn username(&self) -> Cow<str> {
pub fn username(&self) -> Cow<'_, str> {
match percent_decode(self.url.username().as_bytes()).decode_utf8() {
Ok(username) => username,
Err(_) => {
Expand All @@ -61,7 +61,7 @@ impl MysqlUrl {
}

/// The percent-decoded database password.
pub fn password(&self) -> Option<Cow<str>> {
pub fn password(&self) -> Option<Cow<'_, str>> {
match self
.url
.password()
Expand Down
10 changes: 5 additions & 5 deletions src/connector/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl PostgresUrl {
}

/// The percent-decoded database username.
pub fn username(&self) -> Cow<str> {
pub fn username(&self) -> Cow<'_, str> {
match percent_decode(self.url.username().as_bytes()).decode_utf8() {
Ok(username) => username,
Err(_) => {
Expand Down Expand Up @@ -191,7 +191,7 @@ impl PostgresUrl {
}

/// The percent-decoded database password.
pub fn password(&self) -> Cow<str> {
pub fn password(&self) -> Cow<'_, str> {
match self
.url
.password()
Expand Down Expand Up @@ -667,7 +667,7 @@ mod tests {
assert!(res.is_empty());
}

#[allow(unused)]
#[allow(dead_code)]
const TABLE_DEF: &str = r#"
CREATE TABLE "user"(
id int4 PRIMARY KEY NOT NULL,
Expand All @@ -677,13 +677,13 @@ mod tests {
);
"#;

#[allow(unused)]
#[allow(dead_code)]
const CREATE_USER: &str = r#"
INSERT INTO "user" (id, name, age, salary)
VALUES (1, 'Joe', 27, 20000.00 );
"#;

#[allow(unused)]
#[allow(dead_code)]
const DROP_TABLE: &str = "DROP TABLE IF EXISTS \"user\";";

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions src/connector/result_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ impl ResultSet {
}

/// Returns the first row of the `ResultSet`, or None if the set is empty.
pub fn first(&self) -> Option<ResultRowRef> {
pub fn first(&self) -> Option<ResultRowRef<'_>> {
self.get(0)
}

/// Returns a reference to a row in a given position.
pub fn get(&self, index: usize) -> Option<ResultRowRef> {
pub fn get(&self, index: usize) -> Option<ResultRowRef<'_>> {
self.rows.get(index).map(|row| ResultRowRef {
columns: Arc::clone(&self.columns),
values: row,
Expand Down
4 changes: 2 additions & 2 deletions src/connector/result_set/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ mod private {
}

impl ValueIndex<ResultRowRef<'_>, Value<'static>> for usize {
fn index_into<'v>(self, row: &'v ResultRowRef) -> &'v Value<'static> {
fn index_into<'v>(self, row: &'v ResultRowRef<'_>) -> &'v Value<'static> {
row.at(self).unwrap()
}
}

impl ValueIndex<ResultRowRef<'_>, Value<'static>> for &str {
fn index_into<'v>(self, row: &'v ResultRowRef) -> &'v Value<'static> {
fn index_into<'v>(self, row: &'v ResultRowRef<'_>) -> &'v Value<'static> {
row.get(self).unwrap()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/connector/result_set/result_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl ResultRow {
}

/// Make a referring [ResultRowRef](struct.ResultRowRef.html).
pub fn as_ref(&self) -> ResultRowRef {
pub fn as_ref(&self) -> ResultRowRef<'_> {
ResultRowRef {
columns: Arc::clone(&self.columns),
values: &self.values,
Expand Down
4 changes: 2 additions & 2 deletions src/connector/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ mod tests {
}
}

#[allow(unused)]
#[allow(dead_code)]
const TABLE_DEF: &str = r#"
CREATE TABLE USER (
ID INT PRIMARY KEY NOT NULL,
Expand All @@ -340,7 +340,7 @@ mod tests {
);
"#;

#[allow(unused)]
#[allow(dead_code)]
const CREATE_USER: &str = r#"
INSERT INTO USER (ID,NAME,AGE,SALARY)
VALUES (1, 'Joe', 27, 20000.00 );
Expand Down
2 changes: 1 addition & 1 deletion src/connector/sqlite/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<'a> ToColumnNames for SqliteRows<'a> {
}

impl<'a> ToSql for Value<'a> {
fn to_sql(&self) -> Result<ToSqlOutput, RusqlError> {
fn to_sql(&self) -> Result<ToSqlOutput<'_>, RusqlError> {
let value = match self {
Value::Integer(integer) => integer.map(|i| ToSqlOutput::from(i)),
Value::Real(d) => d.map(|d| ToSqlOutput::from(d.to_f64().expect("Decimal is not a f64."))),
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Error {
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.kind.fmt(f)
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
//! # Ok(())
//! # }
//! ```

#![forbid(unsafe_code, future_incompatible, rust_2018_idioms)]
#![deny(missing_debug_implementations, nonstandard_style)]
#![warn(missing_docs, unreachable_pub)]

Comment on lines +106 to +110
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the set of lints introduced. This includes linting for rust_2018_idioms which are things that are disallowed in the current edition and can prevent us from using rust 2018 in the future. And future_incompatible which are things that will be disallowed in a future edition (due next year).

#[macro_use]
mod macros;

Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ macro_rules! aliasable {
where
T: Into<Cow<'a, str>>,
{
let table: Table = self.into();
let table: Table<'_> = self.into();
table.alias(alias)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/visitor/mysql.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
ast::*,
error::{Error, ErrorKind},
visitor::{self, Visitor},
error::{Error, ErrorKind},
};
use std::fmt::{self, Write};

Expand Down
2 changes: 1 addition & 1 deletion src/visitor/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
ast::*,
error::{Error, ErrorKind},
visitor::{self, Visitor},
error::{Error, ErrorKind},
};

use std::fmt::{self, Write};
Expand Down