diff --git a/.travis.yml b/.travis.yml index 4a31ef53c2bd..ba2f1d843011 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,13 +38,11 @@ matrix: allow_failures: - rust: nightly include: - - rust: nightly-2018-04-19 + - rust: nightly-2018-07-17 env: CLIPPY_AND_COMPILE_TESTS=YESPLEASE script: - - (cd diesel && cargo rustc --no-default-features --features "lint sqlite postgres mysql extras" -- -Zno-trans) - - (cd diesel_cli && cargo rustc --no-default-features --features "lint sqlite postgres mysql" -- -Zno-trans) - - (cd diesel_derives && cargo rustc --no-default-features --features "lint" -- -Zno-trans) - - (cd diesel_migrations && cargo rustc --no-default-features --features "lint dotenv sqlite postgres mysql" -- -Zno-trans) + - rustup component add clippy-preview + - cargo clippy - (cd diesel_compile_tests && travis-cargo test) - rust: 1.26.1 env: RUSTFMT=YESPLEASE diff --git a/bin/check b/bin/check deleted file mode 100755 index d505b4f77cc4..000000000000 --- a/bin/check +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -set -e - -BACKENDS="sqlite postgres mysql" - -check() { - cargo rustc --quiet --features "lint $BACKENDS $1" -- -Zno-trans -} - -(cd diesel_derives && - check && - echo "✔ derives crate looks good!") - -(cd diesel && - check "unstable extras" && - echo "✔ diesel core crate looks good!") - -(cd diesel_migrations && - check && - echo "✔ migrations crate looks good!") - -(cd diesel_cli && - check && - echo "✔ cli crate looks good!") diff --git a/bin/test b/bin/test index d031683abc19..51cf5a42f1da 100755 --- a/bin/test +++ b/bin/test @@ -1,8 +1,6 @@ #!/usr/bin/env bash set -e -CLIPPY="lint" - if [ "$1" = "integration" ]; then if [ "$2" ]; then BACKEND="$2" @@ -14,32 +12,32 @@ if [ "$1" = "integration" ]; then if [ "$BACKEND" = "mysql" ]; then export RUST_TEST_THREADS=1 fi - (cd diesel_tests && cargo test --features "$CLIPPY $BACKEND" --no-default-features $*) + (cd diesel_tests && cargo test --features "$BACKEND" --no-default-features $*) elif [ "$1" = "compile" ]; then shift (cd diesel_compile_tests && cargo test $*) else - (cd diesel && cargo test --no-default-features --features "$CLIPPY extras sqlite postgres mysql" $*) + (cd diesel && cargo test --no-default-features --features "extras sqlite postgres mysql" $*) - (cd diesel_cli && cargo test --features "$CLIPPY sqlite" --no-default-features $*) - (cd diesel_migrations && cargo test --features "$CLIPPY sqlite" $*) - (cd diesel_derives && cargo test --features "$CLIPPY diesel/sqlite" $*) - (cd diesel_tests && cargo test --features "$CLIPPY sqlite" --no-default-features $*) + (cd diesel_cli && cargo test --features "sqlite" --no-default-features $*) + (cd diesel_migrations && cargo test --features "sqlite" $*) + (cd diesel_derives && cargo test --features "diesel/sqlite" $*) + (cd diesel_tests && cargo test --features "sqlite" --no-default-features $*) - (cd diesel_migrations && cargo test --features "$CLIPPY postgres" $*) - (cd diesel_derives && cargo test --features "$CLIPPY diesel/postgres" $*) - (cd diesel_cli && cargo test --features "$CLIPPY postgres" --no-default-features $*) - (cd diesel_tests && cargo test --features "$CLIPPY postgres" --no-default-features $*) + (cd diesel_migrations && cargo test --features "postgres" $*) + (cd diesel_derives && cargo test --features "diesel/postgres" $*) + (cd diesel_cli && cargo test --features "postgres" --no-default-features $*) + (cd diesel_tests && cargo test --features "postgres" --no-default-features $*) export RUST_TEST_THREADS=1 - (cd diesel_migrations && cargo test --features "$CLIPPY mysql" $*) - (cd diesel_derives && cargo test --features "$CLIPPY diesel/mysql" $*) - (cd diesel_cli && cargo test --features "$CLIPPY mysql" --no-default-features $*) - (cd diesel_tests && cargo test --features "$CLIPPY mysql" --no-default-features $*) + (cd diesel_migrations && cargo test --features "mysql" $*) + (cd diesel_derives && cargo test --features "diesel/mysql" $*) + (cd diesel_cli && cargo test --features "mysql" --no-default-features $*) + (cd diesel_tests && cargo test --features "mysql" --no-default-features $*) unset RUST_TEST_THREADS (cd diesel_compile_tests && cargo test $*) - (cd diesel_migrations/migrations_internals && cargo test --features "$CLIPPY" $*) - (cd diesel_migrations/migrations_macros && cargo test --features "$CLIPPY" $*) + (cd diesel_migrations/migrations_internals && cargo test $*) + (cd diesel_migrations/migrations_macros && cargo test $*) (cd examples && ./test_all $*) fi; diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index 568f981e8b85..603c566be984 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -15,7 +15,6 @@ categories = ["database"] byteorder = "1.0" diesel_derives = "~1.3.0" chrono = { version = "0.4", optional = true } -clippy = { optional = true, version = "=0.0.195" } libc = { version = "0.2.0", optional = true } libsqlite3-sys = { version = ">=0.8.0, <0.10.0", optional = true, features = ["min_sqlite_version_3_7_16"] } mysqlclient-sys = { version = ">=0.1.0, <0.3.0", optional = true } @@ -43,7 +42,6 @@ tempdir = "^0.3.4" default = ["with-deprecated", "32-column-tables"] extras = ["chrono", "serde_json", "uuid", "deprecated-time", "network-address", "numeric", "r2d2"] unstable = ["diesel_derives/nightly"] -lint = ["clippy"] large-tables = ["32-column-tables"] huge-tables = ["64-column-tables"] x32-column-tables = ["32-column-tables"] diff --git a/diesel/src/connection/statement_cache.rs b/diesel/src/connection/statement_cache.rs index 5aa8e9a875e0..fabb5bb34832 100644 --- a/diesel/src/connection/statement_cache.rs +++ b/diesel/src/connection/statement_cache.rs @@ -108,7 +108,7 @@ pub struct StatementCache { pub cache: RefCell, Statement>>, } -#[cfg_attr(feature = "clippy", allow(len_without_is_empty, new_without_default_derive))] +#[cfg_attr(feature = "cargo-clippy", allow(len_without_is_empty, new_without_default_derive))] impl StatementCache where DB: Backend, @@ -250,7 +250,7 @@ where Ok(x) => x, Err(e) => { error = Some(e); - #[cfg_attr(feature = "clippy", allow(invalid_ref))] + #[cfg_attr(feature = "cargo-clippy", allow(invalid_ref))] unsafe { mem::uninitialized() } diff --git a/diesel/src/lib.rs b/diesel/src/lib.rs index 5e483cbe5001..67273c3920f2 100644 --- a/diesel/src/lib.rs +++ b/diesel/src/lib.rs @@ -130,32 +130,29 @@ // Built-in Lints #![deny(warnings, missing_debug_implementations, missing_copy_implementations, missing_docs)] // Clippy lints -#![cfg_attr(feature = "clippy", allow(unstable_features))] -#![cfg_attr(feature = "clippy", feature(plugin))] -#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] #![cfg_attr( - feature = "clippy", + feature = "cargo-clippy", allow( option_map_unwrap_or_else, option_map_unwrap_or, match_same_arms, type_complexity, redundant_field_names ) )] #![cfg_attr( - feature = "clippy", + feature = "cargo-clippy", warn( option_unwrap_used, result_unwrap_used, print_stdout, wrong_pub_self_convention, mut_mut, non_ascii_literal, similar_names, unicode_not_nfc, enum_glob_use, if_not_else, items_after_statements, used_underscore_binding ) )] -#![cfg_attr(all(test, feature = "clippy"), allow(option_unwrap_used, result_unwrap_used))] +#![cfg_attr(all(test, feature = "cargo-clippy"), allow(option_unwrap_used, result_unwrap_used))] #[cfg(feature = "postgres")] #[macro_use] extern crate bitflags; extern crate byteorder; -// This is required to make `diesel_derives` re-export, but clippy thinks its unused -#[cfg_attr(feature = "clippy", allow(useless_attribute))] +// This is required to make `diesel_derives` re-export, but cargo-clippy thinks its unused +#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))] #[allow(unused_imports)] #[macro_use] extern crate diesel_derives; diff --git a/diesel/src/migration/errors.rs b/diesel/src/migration/errors.rs index 3edbba1a78d0..0f525be52b28 100644 --- a/diesel/src/migration/errors.rs +++ b/diesel/src/migration/errors.rs @@ -79,7 +79,7 @@ impl From for MigrationError { /// Errors that occur while running migrations #[derive(Debug, PartialEq)] -#[cfg_attr(feature = "clippy", allow(enum_variant_names))] +#[cfg_attr(feature = "cargo-clippy", allow(enum_variant_names))] pub enum RunMigrationsError { /// A general migration error occured MigrationError(MigrationError), diff --git a/diesel/src/mysql/connection/stmt/iterator.rs b/diesel/src/mysql/connection/stmt/iterator.rs index 58334d7206f3..29a22f353815 100644 --- a/diesel/src/mysql/connection/stmt/iterator.rs +++ b/diesel/src/mysql/connection/stmt/iterator.rs @@ -11,7 +11,7 @@ pub struct StatementIterator<'a> { output_binds: Binds, } -#[cfg_attr(feature = "clippy", allow(should_implement_trait))] // don't neet `Iterator` here +#[cfg_attr(feature = "cargo-clippy", allow(should_implement_trait))] // don't neet `Iterator` here impl<'a> StatementIterator<'a> { pub fn new(stmt: &'a mut Statement, types: Vec<(MysqlType, IsSigned)>) -> QueryResult { let mut output_binds = Binds::from_output_types(types); @@ -70,7 +70,7 @@ pub struct NamedStatementIterator<'a> { metadata: StatementMetadata, } -#[cfg_attr(feature = "clippy", allow(should_implement_trait))] // don't need `Iterator` here +#[cfg_attr(feature = "cargo-clippy", allow(should_implement_trait))] // don't need `Iterator` here impl<'a> NamedStatementIterator<'a> { pub fn new(stmt: &'a mut Statement) -> QueryResult { let metadata = stmt.metadata()?; diff --git a/diesel/src/mysql/types/date_and_time.rs b/diesel/src/mysql/types/date_and_time.rs index c7c41b2e146b..23a5f7c78810 100644 --- a/diesel/src/mysql/types/date_and_time.rs +++ b/diesel/src/mysql/types/date_and_time.rs @@ -26,7 +26,7 @@ macro_rules! mysql_time_impls { impl FromSql<$ty, Mysql> for ffi::MYSQL_TIME { // ptr::copy_nonoverlapping does not require aligned pointers - #[cfg_attr(feature = "clippy", allow(cast_ptr_alignment))] + #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result { let bytes = not_none!(bytes); let bytes_ptr = bytes.as_ptr() as *const ffi::MYSQL_TIME; diff --git a/diesel/src/pg/connection/mod.rs b/diesel/src/pg/connection/mod.rs index b14bd465c42b..29c70cb3eba9 100644 --- a/diesel/src/pg/connection/mod.rs +++ b/diesel/src/pg/connection/mod.rs @@ -136,7 +136,7 @@ impl PgConnection { TransactionBuilder::new(self) } - #[cfg_attr(feature = "clippy", allow(type_complexity))] + #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] fn prepare_query + QueryId>( &self, source: &T, diff --git a/diesel/src/pg/connection/raw.rs b/diesel/src/pg/connection/raw.rs index 13dda7b2b128..39fb1ebbea97 100644 --- a/diesel/src/pg/connection/raw.rs +++ b/diesel/src/pg/connection/raw.rs @@ -1,4 +1,4 @@ -#![cfg_attr(feature = "clippy", allow(too_many_arguments))] +#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] extern crate pq_sys; diff --git a/diesel/src/pg/connection/stmt/mod.rs b/diesel/src/pg/connection/stmt/mod.rs index 7f4e8da688aa..78aea39137e7 100644 --- a/diesel/src/pg/connection/stmt/mod.rs +++ b/diesel/src/pg/connection/stmt/mod.rs @@ -16,7 +16,7 @@ pub struct Statement { } impl Statement { - #[cfg_attr(feature = "clippy", allow(ptr_arg))] + #[cfg_attr(feature = "cargo-clippy", allow(ptr_arg))] pub fn execute( &self, conn: &RawConnection, @@ -48,7 +48,7 @@ impl Statement { PgResult::new(internal_res?) } - #[cfg_attr(feature = "clippy", allow(ptr_arg))] + #[cfg_attr(feature = "cargo-clippy", allow(ptr_arg))] pub fn prepare( conn: &RawConnection, sql: &str, diff --git a/diesel/src/pg/types/date_and_time/std_time.rs b/diesel/src/pg/types/date_and_time/std_time.rs index 6dd5d5b456cf..3a1eb7b4ddd6 100644 --- a/diesel/src/pg/types/date_and_time/std_time.rs +++ b/diesel/src/pg/types/date_and_time/std_time.rs @@ -51,6 +51,8 @@ fn usecs_to_duration(usecs_passed: u64) -> Duration { Duration::new(seconds, subseconds) } +// FIXME: Remove this when our minimum Rust version is >= 1.27 +#[cfg_attr(feature = "cargo-clippy", allow(duration_subsec))] fn duration_to_usecs(duration: Duration) -> u64 { let seconds = duration.as_secs() * USEC_PER_SEC; let subseconds = duration.subsec_nanos() / NANO_PER_USEC; diff --git a/diesel/src/pg/types/record.rs b/diesel/src/pg/types/record.rs index c0c940600652..abfdc362e64a 100644 --- a/diesel/src/pg/types/record.rs +++ b/diesel/src/pg/types/record.rs @@ -23,7 +23,7 @@ macro_rules! tuple_impls { // Yes, we're relying on the order of evaluation of subexpressions // but the only other option would be to use `mem::uninitialized` // and `ptr::write`. - #[cfg_attr(feature = "clippy", allow(eval_order_dependence))] + #[cfg_attr(feature = "cargo-clippy", allow(eval_order_dependence))] fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result { let mut bytes = not_none!(bytes); let num_elements = bytes.read_i32::()?; diff --git a/diesel/src/query_builder/ast_pass.rs b/diesel/src/query_builder/ast_pass.rs index 7bdab56e96a7..9babe82c3207 100644 --- a/diesel/src/query_builder/ast_pass.rs +++ b/diesel/src/query_builder/ast_pass.rs @@ -36,7 +36,7 @@ where DB: Backend, { #[doc(hidden)] - #[cfg_attr(feature = "clippy", allow(wrong_self_convention))] + #[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))] pub fn to_sql(query_builder: &'a mut DB::QueryBuilder) -> Self { AstPass { internals: AstPassInternals::ToSql(query_builder), @@ -90,7 +90,7 @@ where /// done explicitly. This method matches the semantics of what Rust would do /// implicitly if you were passing a mutable reference // Clippy is wrong, this cannot be expressed with pointer casting - #[cfg_attr(feature = "clippy", allow(transmute_ptr_to_ptr))] + #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ptr))] pub fn reborrow(&mut self) -> AstPass { use self::AstPassInternals::*; let internals = match self.internals { diff --git a/diesel/src/query_builder/bind_collector.rs b/diesel/src/query_builder/bind_collector.rs index add7c6256f75..14d04c801ee8 100644 --- a/diesel/src/query_builder/bind_collector.rs +++ b/diesel/src/query_builder/bind_collector.rs @@ -42,7 +42,7 @@ pub struct RawBytesBindCollector { pub binds: Vec>>, } -#[cfg_attr(feature = "clippy", allow(new_without_default_derive))] +#[cfg_attr(feature = "cargo-clippy", allow(new_without_default_derive))] impl RawBytesBindCollector { /// Construct an empty `RawBytesBindCollector` pub fn new() -> Self { diff --git a/diesel/src/query_builder/debug_query.rs b/diesel/src/query_builder/debug_query.rs index 23d6189e54cd..12b1a6eec94e 100644 --- a/diesel/src/query_builder/debug_query.rs +++ b/diesel/src/query_builder/debug_query.rs @@ -82,7 +82,7 @@ where T: QueryFragment, { // Clippy is wrong, this cannot be expressed with pointer casting - #[cfg_attr(feature = "clippy", allow(transmute_ptr_to_ptr))] + #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ptr))] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut list = f.debug_list(); { diff --git a/diesel/src/query_builder/select_statement/boxed.rs b/diesel/src/query_builder/select_statement/boxed.rs index beeb6ec83282..e479c57d3e24 100644 --- a/diesel/src/query_builder/select_statement/boxed.rs +++ b/diesel/src/query_builder/select_statement/boxed.rs @@ -34,7 +34,7 @@ pub struct BoxedSelectStatement<'a, ST, QS, DB> { } impl<'a, ST, QS, DB> BoxedSelectStatement<'a, ST, QS, DB> { - #[cfg_attr(feature = "clippy", allow(too_many_arguments))] + #[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] pub fn new( select: Box + 'a>, from: QS, diff --git a/diesel/src/query_builder/select_statement/mod.rs b/diesel/src/query_builder/select_statement/mod.rs index 300d00baf4cd..b14d05ea4938 100644 --- a/diesel/src/query_builder/select_statement/mod.rs +++ b/diesel/src/query_builder/select_statement/mod.rs @@ -59,7 +59,7 @@ pub struct SelectStatement< } impl SelectStatement { - #[cfg_attr(feature = "clippy", allow(too_many_arguments))] + #[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] pub fn new( select: S, from: F, diff --git a/diesel/src/result.rs b/diesel/src/result.rs index 061d6722ed56..8e49f4eab614 100644 --- a/diesel/src/result.rs +++ b/diesel/src/result.rs @@ -6,7 +6,7 @@ use std::ffi::NulError; use std::fmt::{self, Display}; #[derive(Debug)] -#[cfg_attr(feature = "clippy", allow(enum_variant_names))] +#[cfg_attr(feature = "cargo-clippy", allow(enum_variant_names))] /// Represents all the ways that a query can fail. /// /// This type is not intended to be exhaustively matched, and new variants may diff --git a/diesel/src/serialize.rs b/diesel/src/serialize.rs index 6223fca5dff8..f9a55752e824 100644 --- a/diesel/src/serialize.rs +++ b/diesel/src/serialize.rs @@ -76,7 +76,7 @@ impl Output<'static, Vec, DB> { /// Unsafe to use for testing types which perform dynamic metadata lookup. pub fn test() -> Self { use std::mem; - #[cfg_attr(feature = "clippy", allow(invalid_ref))] + #[cfg_attr(feature = "cargo-clippy", allow(invalid_ref))] Self::new(Vec::new(), unsafe { mem::uninitialized() }) } } diff --git a/diesel/src/sqlite/connection/serialized_value.rs b/diesel/src/sqlite/connection/serialized_value.rs index bea34265cbe7..c49b26879799 100644 --- a/diesel/src/sqlite/connection/serialized_value.rs +++ b/diesel/src/sqlite/connection/serialized_value.rs @@ -14,7 +14,7 @@ pub struct SerializedValue { impl SerializedValue { // We are always reading potentially misaligned pointers with // `ptr::read_unaligned` - #[cfg_attr(feature = "clippy", allow(cast_ptr_alignment))] + #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] pub(crate) fn bind_to(self, stmt: NonNull, idx: libc::c_int) -> libc::c_int { // This unsafe block assumes the following invariants: // @@ -65,7 +65,7 @@ impl SerializedValue { // We are always reading potentially misaligned pointers with // `ptr::read_unaligned` - #[cfg_attr(feature = "clippy", allow(cast_ptr_alignment))] + #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] pub fn result_of(self, ctx: *mut ffi::sqlite3_context) { // This unsafe block assumes the following invariants: // diff --git a/diesel_cli/Cargo.toml b/diesel_cli/Cargo.toml index 5dbc05b9692e..cf6b479aadf7 100644 --- a/diesel_cli/Cargo.toml +++ b/diesel_cli/Cargo.toml @@ -17,7 +17,6 @@ path = "src/main.rs" [dependencies] chrono = "0.4" clap = "2.27" -clippy = { optional = true, version = "=0.0.195" } diesel = { version = "~1.3.0", default-features = false } dotenv = ">=0.8, <0.11" migrations_internals = "~1.3.0" @@ -36,7 +35,6 @@ url = { version = "1.4.0" } [features] default = ["postgres", "sqlite", "mysql"] -lint = ["clippy"] postgres = ["diesel/postgres", "url", "uses_information_schema"] sqlite = ["diesel/sqlite"] mysql = ["diesel/mysql", "url", "uses_information_schema"] diff --git a/diesel_cli/src/config.rs b/diesel_cli/src/config.rs index 4df4f221cf56..fa4bc9269671 100644 --- a/diesel_cli/src/config.rs +++ b/diesel_cli/src/config.rs @@ -1,5 +1,5 @@ -// FIXME: https://github.com/rust-lang-nursery/rust-clippy/issues/2910 -#![cfg_attr(feature = "clippy", allow(useless_attribute))] +// FIXME: https://github.com/rust-lang-nursery/rust-cargo-clippy/issues/2910 +#![cfg_attr(feature = "cargo-clippy", allow(useless_attribute))] use clap::ArgMatches; use std::env; diff --git a/diesel_cli/src/database.rs b/diesel_cli/src/database.rs index 02066e349398..9928d9dec130 100644 --- a/diesel_cli/src/database.rs +++ b/diesel_cli/src/database.rs @@ -175,7 +175,7 @@ fn create_default_migration_if_needed( } #[allow(unreachable_patterns)] - #[cfg_attr(feature = "clippy", allow(single_match))] + #[cfg_attr(feature = "cargo-clippy", allow(single_match))] match Backend::for_url(database_url) { #[cfg(feature = "postgres")] Backend::Pg => { @@ -336,7 +336,7 @@ fn change_database_of_url(database_url: &str, default_database: &str) -> (String (database, new_url.into_string()) } -#[cfg_attr(feature = "clippy", allow(needless_pass_by_value))] +#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] fn handle_error(error: E) -> T { println!("{}", error); ::std::process::exit(1); diff --git a/diesel_cli/src/infer_schema_internals/foreign_keys.rs b/diesel_cli/src/infer_schema_internals/foreign_keys.rs index c5c214813f11..8b20378a2935 100644 --- a/diesel_cli/src/infer_schema_internals/foreign_keys.rs +++ b/diesel_cli/src/infer_schema_internals/foreign_keys.rs @@ -1,3 +1,5 @@ +#![cfg_attr(feature = "cargo-clippy", allow(expect_fun_call))] // My calls are so fun + use super::data_structures::ForeignKeyConstraint; use super::inference::get_primary_keys; use super::table_data::TableName; diff --git a/diesel_cli/src/infer_schema_internals/information_schema.rs b/diesel_cli/src/infer_schema_internals/information_schema.rs index 45329af5d597..4b6e1fd75a0f 100644 --- a/diesel_cli/src/infer_schema_internals/information_schema.rs +++ b/diesel_cli/src/infer_schema_internals/information_schema.rs @@ -60,7 +60,7 @@ impl UsesInformationSchema for Mysql { } } -#[cfg_attr(feature = "clippy", allow(module_inception))] +#[cfg_attr(feature = "cargo-clippy", allow(module_inception))] mod information_schema { table! { information_schema.tables (table_schema, table_name) { @@ -195,7 +195,7 @@ where Ok(table_names) } -#[cfg_attr(feature = "clippy", allow(similar_names))] +#[cfg_attr(feature = "cargo-clippy", allow(similar_names))] #[cfg(feature = "postgres")] pub fn load_foreign_key_constraints( connection: &Conn, diff --git a/diesel_cli/src/main.rs b/diesel_cli/src/main.rs index c487ba82a545..acbecf36fb4b 100644 --- a/diesel_cli/src/main.rs +++ b/diesel_cli/src/main.rs @@ -1,18 +1,15 @@ // Built-in Lints #![deny(warnings, missing_copy_implementations)] // Clippy lints -#![cfg_attr(feature = "clippy", allow(unstable_features))] -#![cfg_attr(feature = "clippy", feature(plugin))] -#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] -#![cfg_attr(feature = "clippy", allow(option_map_unwrap_or_else, option_map_unwrap_or))] +#![cfg_attr(feature = "cargo-clippy", allow(option_map_unwrap_or_else, option_map_unwrap_or))] #![cfg_attr( - feature = "clippy", + feature = "cargo-clippy", warn( wrong_pub_self_convention, mut_mut, non_ascii_literal, similar_names, unicode_not_nfc, if_not_else, items_after_statements, used_underscore_binding ) )] -#![cfg_attr(all(test, feature = "clippy"), allow(result_unwrap_used))] +#![cfg_attr(all(test, feature = "cargo-clippy"), allow(result_unwrap_used))] extern crate chrono; extern crate clap; @@ -70,6 +67,8 @@ fn main() { } } +// https://github.com/rust-lang-nursery/rust-clippy/issues/2927#issuecomment-405705595 +#[cfg_attr(feature = "cargo-clippy", allow(similar_names))] fn run_migration_command(matches: &ArgMatches) -> Result<(), Box> { match matches.subcommand() { ("run", Some(_)) => { @@ -311,7 +310,7 @@ fn should_redo_migration_in_transaction(_t: &Any) -> bool { true } -#[cfg_attr(feature = "clippy", allow(needless_pass_by_value))] +#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] fn handle_error(error: E) -> T { println!("{}", error); ::std::process::exit(1); diff --git a/diesel_compile_tests/tests/ui/as_changeset_bad_options.stderr b/diesel_compile_tests/tests/ui/as_changeset_bad_options.stderr index c1d8409899d6..40a0401a5057 100644 --- a/diesel_compile_tests/tests/ui/as_changeset_bad_options.stderr +++ b/diesel_compile_tests/tests/ui/as_changeset_bad_options.stderr @@ -1,38 +1,38 @@ error: `treat_none_as_null` must be in the form `treat_none_as_null = "true"` - --> :1:1 - | -1 | #[changeset_options(treat_none_as_null("true"))] - | ^ + --> $DIR/as_changeset_bad_options.rs:11:10 + | +11 | #[derive(AsChangeset)] + | ^^^^^^^^^^^ error: `treat_none_as_null` must be in the form `treat_none_as_null = "true"` - --> :1:1 - | -1 | #[changeset_options(treat_none_as_null)] - | ^ + --> $DIR/as_changeset_bad_options.rs:19:10 + | +19 | #[derive(AsChangeset)] + | ^^^^^^^^^^^ error: `treat_none_as_null` must be in the form `treat_none_as_null = "true"` - --> :1:1 - | -1 | #[changeset_options(treat_none_as_null = "foo")] - | ^ + --> $DIR/as_changeset_bad_options.rs:27:10 + | +27 | #[derive(AsChangeset)] + | ^^^^^^^^^^^ error: Missing required option treat_none_as_null - --> :1:1 - | -1 | #[changeset_options()] - | ^ + --> $DIR/as_changeset_bad_options.rs:35:10 + | +35 | #[derive(AsChangeset)] + | ^^^^^^^^^^^ error: `changeset_options` must be in the form `changeset_options(...)` - --> :1:1 - | -1 | #[changeset_options = "treat_none_as_null"] - | ^ + --> $DIR/as_changeset_bad_options.rs:43:10 + | +43 | #[derive(AsChangeset)] + | ^^^^^^^^^^^ error: `changeset_options` must be in the form `changeset_options(...)` - --> :1:1 - | -1 | #[changeset_options] - | ^ + --> $DIR/as_changeset_bad_options.rs:51:10 + | +51 | #[derive(AsChangeset)] + | ^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/diesel_compile_tests/tests/ui/as_changeset_bad_primary_key_syntax.stderr b/diesel_compile_tests/tests/ui/as_changeset_bad_primary_key_syntax.stderr index 2f91e12583ab..33134d4780a9 100644 --- a/diesel_compile_tests/tests/ui/as_changeset_bad_primary_key_syntax.stderr +++ b/diesel_compile_tests/tests/ui/as_changeset_bad_primary_key_syntax.stderr @@ -1,14 +1,14 @@ error: Expected `bar` found `bar = "baz"` - --> :1:1 - | -1 | #[primary_key(id, bar = "baz", qux(id))] - | ^ + --> $DIR/as_changeset_bad_primary_key_syntax.rs:11:10 + | +11 | #[derive(AsChangeset)] + | ^^^^^^^^^^^ error: Expected `qux` found `qux ( id )` - --> :1:1 - | -1 | #[primary_key(id, bar = "baz", qux(id))] - | ^ + --> $DIR/as_changeset_bad_primary_key_syntax.rs:11:10 + | +11 | #[derive(AsChangeset)] + | ^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/diesel_compile_tests/tests/ui/as_changeset_deprecated_column_name.stderr b/diesel_compile_tests/tests/ui/as_changeset_deprecated_column_name.stderr index e1e1d668c1c6..200b1f8a6b9b 100644 --- a/diesel_compile_tests/tests/ui/as_changeset_deprecated_column_name.stderr +++ b/diesel_compile_tests/tests/ui/as_changeset_deprecated_column_name.stderr @@ -1,8 +1,8 @@ warning: The form `table_name(value)` is deprecated. Use `table_name = "value"` instead - --> :1:1 - | -1 | #[table_name(users)] - | ^ + --> $DIR/as_changeset_deprecated_column_name.rs:11:10 + | +11 | #[derive(AsChangeset)] + | ^^^^^^^^^^^ warning: The form `column_name(value)` is deprecated. Use `column_name = "value"` instead --> $DIR/as_changeset_deprecated_column_name.rs:15:7 diff --git a/diesel_compile_tests/tests/ui/as_changeset_missing_table_import.stderr b/diesel_compile_tests/tests/ui/as_changeset_missing_table_import.stderr index 554fa6cca591..ff8fdad0b702 100644 --- a/diesel_compile_tests/tests/ui/as_changeset_missing_table_import.stderr +++ b/diesel_compile_tests/tests/ui/as_changeset_missing_table_import.stderr @@ -5,10 +5,10 @@ error[E0433]: failed to resolve. Use of undeclared type or module `users` | ^^^^ Use of undeclared type or module `users` error[E0433]: failed to resolve. Use of undeclared type or module `users` - --> :1:1 - | -1 | #[table_name = "users"] - | ^ Use of undeclared type or module `users` + --> $DIR/as_changeset_missing_table_import.rs:10:10 + | +10 | #[derive(AsChangeset)] + | ^^^^^^^^^^^ Use of undeclared type or module `users` error: aborting due to 2 previous errors diff --git a/diesel_compile_tests/tests/ui/as_expression_bad_sql_type.stderr b/diesel_compile_tests/tests/ui/as_expression_bad_sql_type.stderr index 900acc8d35a9..0fbed64e2fa0 100644 --- a/diesel_compile_tests/tests/ui/as_expression_bad_sql_type.stderr +++ b/diesel_compile_tests/tests/ui/as_expression_bad_sql_type.stderr @@ -1,26 +1,14 @@ error: `sql_type` must be in the form `sql_type = "value"` - --> :1:1 + --> $DIR/as_expression_bad_sql_type.rs:4:10 | -1 | #[sql_type(Foo)] - | ^ - -error: `sql_type` must be in the form `sql_type = "value"` - --> :1:1 - | -1 | #[sql_type] - | ^ - -error: Invalid Rust type - --> :1:1 - | -1 | #[sql_type = "@%&&*"] - | ^ +4 | #[derive(AsExpression)] + | ^^^^^^^^^^^^ error: Invalid Rust type - --> :1:1 + --> $DIR/as_expression_bad_sql_type.rs:4:10 | -1 | #[sql_type = "1omg"] - | ^ +4 | #[derive(AsExpression)] + | ^^^^^^^^^^^^ -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors diff --git a/diesel_compile_tests/tests/ui/belongs_to_invalid_option_syntax.stderr b/diesel_compile_tests/tests/ui/belongs_to_invalid_option_syntax.stderr index cc45bcfa72d2..216ccb0b7ba0 100644 --- a/diesel_compile_tests/tests/ui/belongs_to_invalid_option_syntax.stderr +++ b/diesel_compile_tests/tests/ui/belongs_to_invalid_option_syntax.stderr @@ -1,48 +1,34 @@ error: `belongs_to` must be in the form `belongs_to(...)` - --> :1:1 - | -1 | #[belongs_to] - | ^ - -error: `belongs_to` must be in the form `belongs_to(...)` - --> :1:1 - | -1 | #[belongs_to = "Bar"] - | ^ - -error: Expected a struct name - --> :1:1 - | -1 | #[belongs_to()] - | ^ - | - = help: e.g. `#[belongs_to(User)]` + --> $DIR/belongs_to_invalid_option_syntax.rs:22:10 + | +22 | #[derive(Associations)] + | ^^^^^^^^^^^^ error: Expected a struct name - --> :1:1 - | -1 | #[belongs_to(foreign_key = "bar_id")] - | ^ - | - = help: e.g. `#[belongs_to(User)]` + --> $DIR/belongs_to_invalid_option_syntax.rs:22:10 + | +22 | #[derive(Associations)] + | ^^^^^^^^^^^^ + | + = help: e.g. `#[belongs_to(User)]` error: `foreign_key` must be in the form `foreign_key = "value"` - --> :1:1 - | -1 | #[belongs_to(Bar, foreign_key)] - | ^ + --> $DIR/belongs_to_invalid_option_syntax.rs:22:10 + | +22 | #[derive(Associations)] + | ^^^^^^^^^^^^ warning: The form `foreign_key(value)` is deprecated. Use `foreign_key = "value"` instead - --> :1:1 - | -1 | #[belongs_to(Bar, foreign_key(bar_id))] - | ^ + --> $DIR/belongs_to_invalid_option_syntax.rs:22:10 + | +22 | #[derive(Associations)] + | ^^^^^^^^^^^^ warning: Unrecognized option random_option - --> :1:1 - | -1 | #[belongs_to(Baz, foreign_key = "bar_id", random_option)] - | ^ + --> $DIR/belongs_to_invalid_option_syntax.rs:22:10 + | +22 | #[derive(Associations)] + | ^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors diff --git a/diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_column.stderr b/diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_column.stderr index db8b131eabcb..d43a60a5aa44 100644 --- a/diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_column.stderr +++ b/diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_column.stderr @@ -1,50 +1,50 @@ error[E0412]: cannot find type `bar_id` in module `foo` - --> :1:1 - | -1 | #[belongs_to(Bar)] - | ^ not found in `foo` + --> $DIR/belongs_to_missing_foreign_key_column.rs:12:10 + | +12 | #[derive(Associations)] + | ^^^^^^^^^^^^ not found in `foo` error[E0425]: cannot find value `bar_id` in module `foo` - --> :1:1 - | -1 | #[belongs_to(Bar)] - | ^ not found in `foo` + --> $DIR/belongs_to_missing_foreign_key_column.rs:12:10 + | +12 | #[derive(Associations)] + | ^^^^^^^^^^^^ not found in `foo` error[E0412]: cannot find type `bar_id` in module `foo` - --> :1:1 - | -1 | #[belongs_to(Bar, foreign_key = "bar_id")] - | ^ not found in `foo` + --> $DIR/belongs_to_missing_foreign_key_column.rs:19:10 + | +19 | #[derive(Associations)] + | ^^^^^^^^^^^^ not found in `foo` error[E0425]: cannot find value `bar_id` in module `foo` - --> :1:1 - | -1 | #[belongs_to(Bar, foreign_key = "bar_id")] - | ^ not found in `foo` + --> $DIR/belongs_to_missing_foreign_key_column.rs:19:10 + | +19 | #[derive(Associations)] + | ^^^^^^^^^^^^ not found in `foo` error[E0412]: cannot find type `bar_id` in module `foo` - --> :1:1 - | -1 | #[belongs_to(Bar)] - | ^ not found in `foo` + --> $DIR/belongs_to_missing_foreign_key_column.rs:26:10 + | +26 | #[derive(Associations)] + | ^^^^^^^^^^^^ not found in `foo` error[E0425]: cannot find value `bar_id` in module `foo` - --> :1:1 - | -1 | #[belongs_to(Bar)] - | ^ not found in `foo` + --> $DIR/belongs_to_missing_foreign_key_column.rs:26:10 + | +26 | #[derive(Associations)] + | ^^^^^^^^^^^^ not found in `foo` error[E0412]: cannot find type `bar_id` in module `foo` - --> :1:1 - | -1 | #[belongs_to(Bar, foreign_key = "bar_id")] - | ^ not found in `foo` + --> $DIR/belongs_to_missing_foreign_key_column.rs:34:10 + | +34 | #[derive(Associations)] + | ^^^^^^^^^^^^ not found in `foo` error[E0425]: cannot find value `bar_id` in module `foo` - --> :1:1 - | -1 | #[belongs_to(Bar, foreign_key = "bar_id")] - | ^ not found in `foo` + --> $DIR/belongs_to_missing_foreign_key_column.rs:34:10 + | +34 | #[derive(Associations)] + | ^^^^^^^^^^^^ not found in `foo` error: aborting due to 8 previous errors diff --git a/diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_field.stderr b/diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_field.stderr index 711199035cd9..b166b752613b 100644 --- a/diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_field.stderr +++ b/diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_field.stderr @@ -1,26 +1,14 @@ error: No field with column name bar_id - --> :1:1 + --> $DIR/belongs_to_missing_foreign_key_field.rs:6:10 | -1 | #[belongs_to(Bar)] - | ^ +6 | #[derive(Associations)] + | ^^^^^^^^^^^^ error: No field with column name bar_id - --> :1:1 - | -1 | #[belongs_to(Bar, foreign_key = "bar_id")] - | ^ - -error: No field with column name bar_id - --> :1:1 - | -1 | #[belongs_to(Bar)] - | ^ - -error: No field with column name bar_id - --> :1:1 - | -1 | #[belongs_to(Bar, foreign_key = "bar_id")] - | ^ + --> $DIR/belongs_to_missing_foreign_key_field.rs:11:10 + | +11 | #[derive(Associations)] + | ^^^^^^^^^^^^ -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors diff --git a/diesel_compile_tests/tests/ui/belongs_to_missing_parent_import.stderr b/diesel_compile_tests/tests/ui/belongs_to_missing_parent_import.stderr index bfffe6222f71..ebf7d775c256 100644 --- a/diesel_compile_tests/tests/ui/belongs_to_missing_parent_import.stderr +++ b/diesel_compile_tests/tests/ui/belongs_to_missing_parent_import.stderr @@ -1,8 +1,8 @@ error[E0412]: cannot find type `Bar` in this scope - --> :1:1 - | -1 | #[belongs_to(Bar)] - | ^ not found in this scope + --> $DIR/belongs_to_missing_parent_import.rs:11:10 + | +11 | #[derive(Associations)] + | ^^^^^^^^^^^^ not found in this scope error: aborting due to previous error diff --git a/diesel_compile_tests/tests/ui/identifiable_missing_pk_field.stderr b/diesel_compile_tests/tests/ui/identifiable_missing_pk_field.stderr index af0fce34e18f..5d27e3053b8f 100644 --- a/diesel_compile_tests/tests/ui/identifiable_missing_pk_field.stderr +++ b/diesel_compile_tests/tests/ui/identifiable_missing_pk_field.stderr @@ -11,28 +11,28 @@ error: No field with column name id | ^^^^^^^^^^^^ error: No field with column name bar - --> :1:1 - | -1 | #[primary_key(bar)] - | ^ + --> $DIR/identifiable_missing_pk_field.rs:22:10 + | +22 | #[derive(Identifiable)] + | ^^^^^^^^^^^^ error: No field with column name baz - --> :1:1 - | -1 | #[primary_key(baz)] - | ^ + --> $DIR/identifiable_missing_pk_field.rs:28:10 + | +28 | #[derive(Identifiable)] + | ^^^^^^^^^^^^ error: No field with column name bar - --> :1:1 - | -1 | #[primary_key(foo, bar)] - | ^ + --> $DIR/identifiable_missing_pk_field.rs:36:10 + | +36 | #[derive(Identifiable)] + | ^^^^^^^^^^^^ error: No field with column name bar - --> :1:1 - | -1 | #[primary_key(foo, bar)] - | ^ + --> $DIR/identifiable_missing_pk_field.rs:43:10 + | +43 | #[derive(Identifiable)] + | ^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/diesel_compile_tests/tests/ui/insertable_missing_table_or_column.stderr b/diesel_compile_tests/tests/ui/insertable_missing_table_or_column.stderr index 8566d95f52f1..0f258a7c7e96 100644 --- a/diesel_compile_tests/tests/ui/insertable_missing_table_or_column.stderr +++ b/diesel_compile_tests/tests/ui/insertable_missing_table_or_column.stderr @@ -5,10 +5,10 @@ error[E0433]: failed to resolve. Use of undeclared type or module `posts` | ^^^^ Use of undeclared type or module `posts` error[E0433]: failed to resolve. Use of undeclared type or module `posts` - --> :1:1 - | -1 | #[table_name = "posts"] - | ^ Use of undeclared type or module `posts` + --> $DIR/insertable_missing_table_or_column.rs:15:10 + | +15 | #[derive(Insertable)] + | ^^^^^^^^^^ Use of undeclared type or module `posts` error[E0412]: cannot find type `name` in module `users` --> $DIR/insertable_missing_table_or_column.rs:21:10 diff --git a/diesel_compile_tests/tests/ui/sql_type_bad_options.stderr b/diesel_compile_tests/tests/ui/sql_type_bad_options.stderr index cac61be1912e..a89e921f8beb 100644 --- a/diesel_compile_tests/tests/ui/sql_type_bad_options.stderr +++ b/diesel_compile_tests/tests/ui/sql_type_bad_options.stderr @@ -1,52 +1,52 @@ error: Missing required options - --> :1:1 + --> $DIR/sql_type_bad_options.rs:4:10 | -1 | #[postgres] - | ^ +4 | #[derive(SqlType)] + | ^^^^^^^ | = help: Valid options are `type_name` or `oid` and `array_oid` warning: Option oid has no effect - --> :1:1 + --> $DIR/sql_type_bad_options.rs:8:10 | -1 | #[postgres(type_name = "foo", oid = "2", array_oid = "3")] - | ^ +8 | #[derive(SqlType)] + | ^^^^^^^ warning: Option array_oid has no effect - --> :1:1 + --> $DIR/sql_type_bad_options.rs:8:10 | -1 | #[postgres(type_name = "foo", oid = "2", array_oid = "3")] - | ^ +8 | #[derive(SqlType)] + | ^^^^^^^ error: Missing required option array_oid - --> :1:1 - | -1 | #[postgres(oid = "2")] - | ^ + --> $DIR/sql_type_bad_options.rs:12:10 + | +12 | #[derive(SqlType)] + | ^^^^^^^ error: Expected a number - --> :1:1 - | -1 | #[postgres(oid = "NaN", array_oid = "1")] - | ^ + --> $DIR/sql_type_bad_options.rs:16:10 + | +16 | #[derive(SqlType)] + | ^^^^^^^ warning: Option ary_oid has no effect - --> :1:1 - | -1 | #[postgres(oid = "NaN", ary_oid = "1")] - | ^ + --> $DIR/sql_type_bad_options.rs:20:10 + | +20 | #[derive(SqlType)] + | ^^^^^^^ error: Missing required option array_oid - --> :1:1 - | -1 | #[postgres(oid = "NaN", ary_oid = "1")] - | ^ + --> $DIR/sql_type_bad_options.rs:20:10 + | +20 | #[derive(SqlType)] + | ^^^^^^^ error: Expected a number - --> :1:1 - | -1 | #[postgres(oid = "NaN", ary_oid = "1")] - | ^ + --> $DIR/sql_type_bad_options.rs:20:10 + | +20 | #[derive(SqlType)] + | ^^^^^^^ error: aborting due to 5 previous errors diff --git a/diesel_derives/Cargo.toml b/diesel_derives/Cargo.toml index 9b24e2003d04..9204e71b3f77 100644 --- a/diesel_derives/Cargo.toml +++ b/diesel_derives/Cargo.toml @@ -9,10 +9,9 @@ homepage = "https://diesel.rs" repository = "https://github.com/diesel-rs/diesel/tree/master/diesel_derives" [dependencies] -syn = { version = "0.13.0", features = ["full", "fold"] } -quote = "0.5.0" -clippy = { optional = true, version = "=0.0.195" } -proc-macro2 = "0.3.0" +syn = { version = "0.14.0", features = ["full", "fold"] } +quote = "0.6.0" +proc-macro2 = "0.4.0" [dev-dependencies] cfg-if = "0.1.0" @@ -27,7 +26,6 @@ name = "tests" [features] default = [] -lint = ["clippy"] nightly = ["proc-macro2/nightly"] postgres = [] sqlite = [] diff --git a/diesel_derives/src/as_changeset.rs b/diesel_derives/src/as_changeset.rs index 0897af08dc07..4890890c7196 100644 --- a/diesel_derives/src/as_changeset.rs +++ b/diesel_derives/src/as_changeset.rs @@ -1,5 +1,5 @@ +use proc_macro2; use proc_macro2::Span; -use quote; use syn; use diagnostic_shim::*; @@ -8,7 +8,7 @@ use meta::*; use model::*; use util::*; -pub fn derive(item: syn::DeriveInput) -> Result { +pub fn derive(item: syn::DeriveInput) -> Result { let treat_none_as_null = MetaItem::with_name(&item.attrs, "changeset_options") .map(|meta| { meta.warn_if_other_options(&["treat_none_as_null"]); @@ -33,20 +33,20 @@ pub fn derive(item: syn::DeriveInput) -> Result { let ref_changeset_ty = fields_for_update.iter().map(|field| { field_changeset_ty( field, - table_name, + &table_name, treat_none_as_null, Some(quote!(&'update)), ) }); let ref_changeset_expr = fields_for_update .iter() - .map(|field| field_changeset_expr(field, table_name, treat_none_as_null, Some(quote!(&)))); + .map(|field| field_changeset_expr(field, &table_name, treat_none_as_null, Some(quote!(&)))); let direct_changeset_ty = fields_for_update .iter() - .map(|field| field_changeset_ty(field, table_name, treat_none_as_null, None)); + .map(|field| field_changeset_ty(field, &table_name, treat_none_as_null, None)); let direct_changeset_expr = fields_for_update .iter() - .map(|field| field_changeset_expr(field, table_name, treat_none_as_null, None)); + .map(|field| field_changeset_expr(field, &table_name, treat_none_as_null, None)); if fields_for_update.is_empty() { Span::call_site() @@ -91,9 +91,9 @@ pub fn derive(item: syn::DeriveInput) -> Result { fn field_changeset_ty( field: &Field, - table_name: syn::Ident, + table_name: &syn::Ident, treat_none_as_null: bool, - lifetime: Option, + lifetime: Option, ) -> syn::Type { let column_name = field.column_name(); if !treat_none_as_null && is_option_ty(&field.ty) { @@ -107,9 +107,9 @@ fn field_changeset_ty( fn field_changeset_expr( field: &Field, - table_name: syn::Ident, + table_name: &syn::Ident, treat_none_as_null: bool, - lifetime: Option, + lifetime: Option, ) -> syn::Expr { let field_access = field.name.access(); let column_name = field.column_name(); diff --git a/diesel_derives/src/as_expression.rs b/diesel_derives/src/as_expression.rs index 38d292b9400c..577d4c07bfbf 100644 --- a/diesel_derives/src/as_expression.rs +++ b/diesel_derives/src/as_expression.rs @@ -1,14 +1,11 @@ -use quote; +use proc_macro2::{self, Ident, Span}; use syn; use meta::*; use util::*; -pub fn derive(item: syn::DeriveInput) -> Result { - let dummy_mod = format!( - "_impl_as_expression_for_{}", - item.ident.as_ref().to_lowercase() - ); +pub fn derive(item: syn::DeriveInput) -> Result { + let dummy_mod = format!("_impl_as_expression_for_{}", item.ident,).to_lowercase(); let flags = MetaItem::with_name(&item.attrs, "diesel").unwrap_or_else(|| MetaItem::empty("diesel")); let is_sized = !flags.has_flag("not_sized"); @@ -106,7 +103,7 @@ pub fn derive(item: syn::DeriveInput) -> Result { if any_sql_types { Ok(wrap_in_dummy_mod( - dummy_mod.into(), + Ident::new(&dummy_mod, Span::call_site()), quote! { use diesel::expression::AsExpression; use diesel::expression::bound::Bound; diff --git a/diesel_derives/src/associations.rs b/diesel_derives/src/associations.rs index e2882fc6fbc0..c6b5812e231e 100644 --- a/diesel_derives/src/associations.rs +++ b/diesel_derives/src/associations.rs @@ -1,4 +1,4 @@ -use quote; +use proc_macro2; use syn; use diagnostic_shim::*; @@ -6,7 +6,7 @@ use meta::*; use model::*; use util::*; -pub fn derive(item: syn::DeriveInput) -> Result { +pub fn derive(item: syn::DeriveInput) -> Result { let model = Model::from_item(&item)?; let tokens = MetaItem::all_with_name(&item.attrs, "belongs_to") .into_iter() @@ -30,15 +30,15 @@ fn derive_belongs_to( model: &Model, generics: &syn::Generics, meta: MetaItem, -) -> Result { +) -> Result { let AssociationOptions { parent_struct, foreign_key, } = AssociationOptions::from_meta(meta)?; let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); - let foreign_key_field = model.find_column(foreign_key)?; - let struct_name = model.name; + let foreign_key_field = model.find_column(&foreign_key)?; + let struct_name = &model.name; let foreign_key_access = foreign_key_field.name.access(); let foreign_key_ty = inner_of_option_ty(&foreign_key_field.ty); let table_name = model.table_name(); @@ -86,7 +86,7 @@ impl AssociationOptions { let foreign_key = meta.nested_item("foreign_key") .ok() .map(|i| i.ident_value()) - .unwrap_or_else(|| Ok(infer_foreign_key(parent_struct)))?; + .unwrap_or_else(|| Ok(infer_foreign_key(&parent_struct)))?; let unrecognized_options = meta.nested()?.skip(1).filter(|n| n.name() != "foreign_key"); for ignored in unrecognized_options { @@ -103,7 +103,7 @@ impl AssociationOptions { } } -fn infer_foreign_key(name: syn::Ident) -> syn::Ident { - let snake_case = camel_to_snake(name.as_ref()); +fn infer_foreign_key(name: &syn::Ident) -> syn::Ident { + let snake_case = camel_to_snake(&name.to_string()); syn::Ident::new(&format!("{}_id", snake_case), name.span()) } diff --git a/diesel_derives/src/diesel_numeric_ops.rs b/diesel_derives/src/diesel_numeric_ops.rs index b1a1a2285d92..09534018e044 100644 --- a/diesel_derives/src/diesel_numeric_ops.rs +++ b/diesel_derives/src/diesel_numeric_ops.rs @@ -1,10 +1,10 @@ -use quote; +use proc_macro2::{self, Ident, Span}; use syn; use util::*; -pub fn derive(mut item: syn::DeriveInput) -> Result { - let struct_name = item.ident; +pub fn derive(mut item: syn::DeriveInput) -> Result { + let struct_name = &item.ident; { let where_clause = item.generics @@ -21,7 +21,7 @@ pub fn derive(mut item: syn::DeriveInput) -> Result { let dummy_name = format!("_impl_diesel_numeric_ops_for_{}", item.ident); Ok(wrap_in_dummy_mod( - dummy_name.to_lowercase().into(), + Ident::new(&dummy_name.to_lowercase(), Span::call_site()), quote! { use diesel::expression::{ops, Expression, AsExpression}; use diesel::sql_types::ops::{Add, Sub, Mul, Div}; diff --git a/diesel_derives/src/field.rs b/diesel_derives/src/field.rs index bf0c4aa3aec8..a46fe39444e9 100644 --- a/diesel_derives/src/field.rs +++ b/diesel_derives/src/field.rs @@ -1,5 +1,5 @@ -use proc_macro2::Span; -use quote; +use proc_macro2::{self, Ident, Span}; +use quote::ToTokens; use syn; use syn::spanned::Spanned; @@ -19,7 +19,7 @@ impl Field { pub fn from_struct_field(field: &syn::Field, index: usize) -> Self { let column_name_from_attribute = MetaItem::with_name(&field.attrs, "column_name").map(|m| m.expect_ident_value()); - let name = match field.ident { + let name = match field.ident.clone() { Some(mut x) => { // https://github.com/rust-lang/rust/issues/47983#issuecomment-362817105 let span = x.span(); @@ -50,15 +50,16 @@ impl Field { pub fn column_name(&self) -> syn::Ident { self.column_name_from_attribute + .clone() .unwrap_or_else(|| match self.name { - FieldName::Named(x) => x, + FieldName::Named(ref x) => x.clone(), _ => { self.span .error( "All fields of tuple structs must be annotated with `#[column_name]`", ) .emit(); - "unknown_column".into() + Ident::new("unknown_column", self.span) } }) } @@ -81,7 +82,7 @@ impl FieldName { parse_quote!(#tokens) } - pub fn access(&self) -> quote::Tokens { + pub fn access(&self) -> proc_macro2::TokenStream { let span = self.span(); // Span of the dot is important due to // https://github.com/rust-lang/rust/issues/47312 @@ -90,16 +91,16 @@ impl FieldName { pub fn span(&self) -> Span { match *self { - FieldName::Named(x) => x.span(), + FieldName::Named(ref x) => x.span(), FieldName::Unnamed(ref x) => x.span, } } } -impl quote::ToTokens for FieldName { - fn to_tokens(&self, tokens: &mut quote::Tokens) { +impl ToTokens for FieldName { + fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { match *self { - FieldName::Named(x) => x.to_tokens(tokens), + FieldName::Named(ref x) => x.to_tokens(tokens), FieldName::Unnamed(ref x) => x.to_tokens(tokens), } } diff --git a/diesel_derives/src/from_sql_row.rs b/diesel_derives/src/from_sql_row.rs index 25d23379868a..4eae4a77c95e 100644 --- a/diesel_derives/src/from_sql_row.rs +++ b/diesel_derives/src/from_sql_row.rs @@ -1,10 +1,10 @@ -use quote::Tokens; +use proc_macro2::*; use syn; use meta::*; use util::*; -pub fn derive(mut item: syn::DeriveInput) -> Result { +pub fn derive(mut item: syn::DeriveInput) -> Result { let flags = MetaItem::with_name(&item.attrs, "diesel").unwrap_or_else(|| MetaItem::empty("diesel")); let struct_ty = ty_for_foreign_derive(&item, &flags)?; @@ -24,12 +24,9 @@ pub fn derive(mut item: syn::DeriveInput) -> Result { } let (impl_generics, _, where_clause) = item.generics.split_for_impl(); - let dummy_mod = format!( - "_impl_from_sql_row_for_{}", - item.ident.as_ref().to_lowercase() - ).into(); + let dummy_mod = format!("_impl_from_sql_row_for_{}", item.ident,).to_lowercase(); Ok(wrap_in_dummy_mod( - dummy_mod, + Ident::new(&dummy_mod, Span::call_site()), quote! { use diesel::deserialize::{self, FromSql, FromSqlRow, Queryable}; diff --git a/diesel_derives/src/identifiable.rs b/diesel_derives/src/identifiable.rs index 99368daaf9af..c425bb1c8485 100644 --- a/diesel_derives/src/identifiable.rs +++ b/diesel_derives/src/identifiable.rs @@ -1,12 +1,12 @@ -use quote; +use proc_macro2; use syn; use model::*; use util::*; -pub fn derive(item: syn::DeriveInput) -> Result { +pub fn derive(item: syn::DeriveInput) -> Result { let model = Model::from_item(&item)?; - let struct_name = model.name; + let struct_name = &model.name; let table_name = model.table_name(); let (impl_generics, ty_generics, where_clause) = item.generics.split_for_impl(); @@ -17,7 +17,7 @@ pub fn derive(item: syn::DeriveInput) -> Result { let (field_ty, field_access): (Vec<_>, Vec<_>) = model .primary_key_names .iter() - .filter_map(|&pk| model.find_column(pk).emit_error()) + .filter_map(|pk| model.find_column(pk).emit_error()) .map(|f| (&f.ty, f.name.access())) .unzip(); diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index 1c33dd47d713..c2319d0edb82 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -1,12 +1,12 @@ +use proc_macro2; use proc_macro2::Span; -use quote; use syn; use field::*; use model::*; use util::*; -pub fn derive(item: syn::DeriveInput) -> Result { +pub fn derive(item: syn::DeriveInput) -> Result { let model = Model::from_item(&item)?; if model.fields().is_empty() { @@ -18,8 +18,8 @@ pub fn derive(item: syn::DeriveInput) -> Result { ))); } - let table_name = model.table_name(); - let struct_name = item.ident; + let table_name = &model.table_name(); + let struct_name = &item.ident; let (_, ty_generics, where_clause) = item.generics.split_for_impl(); let mut impl_generics = item.generics.clone(); @@ -85,7 +85,11 @@ pub fn derive(item: syn::DeriveInput) -> Result { )) } -fn field_ty(field: &Field, table_name: syn::Ident, lifetime: Option) -> syn::Type { +fn field_ty( + field: &Field, + table_name: &syn::Ident, + lifetime: Option, +) -> syn::Type { if field.has_flag("embed") { let field_ty = &field.ty; parse_quote!(#lifetime #field_ty) @@ -101,7 +105,11 @@ fn field_ty(field: &Field, table_name: syn::Ident, lifetime: Option) -> syn::Expr { +fn field_expr( + field: &Field, + table_name: &syn::Ident, + lifetime: Option, +) -> syn::Expr { let field_access = field.name.access(); if field.has_flag("embed") { parse_quote!(#lifetime self#field_access) diff --git a/diesel_derives/src/lib.rs b/diesel_derives/src/lib.rs index cbd7482de9c9..60c521a0ff5b 100644 --- a/diesel_derives/src/lib.rs +++ b/diesel_derives/src/lib.rs @@ -2,18 +2,16 @@ // Built-in Lints #![deny(warnings, missing_copy_implementations)] // Clippy lints -#![cfg_attr(feature = "clippy", allow(needless_pass_by_value))] -#![cfg_attr(feature = "clippy", feature(plugin))] -#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] -#![cfg_attr(feature = "clippy", allow(option_map_unwrap_or_else, option_map_unwrap_or))] +#![cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] +#![cfg_attr(feature = "cargo-clippy", allow(option_map_unwrap_or_else, option_map_unwrap_or))] #![cfg_attr( - feature = "clippy", + feature = "cargo-clippy", warn( wrong_pub_self_convention, mut_mut, non_ascii_literal, similar_names, unicode_not_nfc, if_not_else, items_after_statements, used_underscore_binding ) )] -#![cfg_attr(feature = "nightly", feature(proc_macro))] +#![cfg_attr(feature = "nightly", feature(proc_macro_diagnostic, proc_macro_span))] extern crate proc_macro; extern crate proc_macro2; @@ -104,7 +102,7 @@ pub fn derive_sql_type(input: TokenStream) -> TokenStream { fn expand_derive( input: TokenStream, - f: fn(syn::DeriveInput) -> Result, + f: fn(syn::DeriveInput) -> Result, ) -> TokenStream { let item = syn::parse(input).unwrap(); match f(item) { diff --git a/diesel_derives/src/meta.rs b/diesel_derives/src/meta.rs index 204d532df249..7de6a1afa7cd 100644 --- a/diesel_derives/src/meta.rs +++ b/diesel_derives/src/meta.rs @@ -1,4 +1,4 @@ -use proc_macro2::Span; +use proc_macro2::{Ident, Span}; use syn; use syn::fold::Fold; use syn::spanned::Spanned; @@ -30,7 +30,7 @@ impl MetaItem { pub fn empty(name: &str) -> Self { Self { meta: syn::Meta::List(syn::MetaList { - ident: name.into(), + ident: Ident::new(name, Span::call_site()), paren_token: Default::default(), nested: Default::default(), }), @@ -100,7 +100,7 @@ impl MetaItem { use syn::Meta::*; match self.meta { - Word(x) => Ok(x), + Word(ref x) => Ok(x.clone()), _ => { let meta = &self.meta; Err(self.span().error(format!( @@ -197,7 +197,7 @@ impl MetaItem { Ok(x) => x, Err(_) => return, }; - let unrecognized_options = nested.filter(|n| !options.contains(&n.name().as_ref())); + let unrecognized_options = nested.filter(|n| !options.iter().any(|&o| n.name() == o)); for ignored in unrecognized_options { ignored .span() @@ -210,7 +210,7 @@ impl MetaItem { use syn::Meta::*; match self.meta { - Word(ident) => ident.span(), + Word(ref ident) => ident.span(), List(ref meta) => meta.nested.span(), NameValue(ref meta) => meta.lit.span(), } diff --git a/diesel_derives/src/model.rs b/diesel_derives/src/model.rs index b41f1528f81f..25722a8103c3 100644 --- a/diesel_derives/src/model.rs +++ b/diesel_derives/src/model.rs @@ -1,4 +1,4 @@ -use proc_macro2::Span; +use proc_macro2::{Ident, Span}; use syn; use diagnostic_shim::*; @@ -19,10 +19,10 @@ impl Model { MetaItem::with_name(&item.attrs, "table_name").map(|m| m.expect_ident_value()); let primary_key_names = MetaItem::with_name(&item.attrs, "primary_key") .map(|m| Ok(m.nested()?.map(|m| m.expect_word()).collect())) - .unwrap_or_else(|| Ok(vec!["id".into()]))?; + .unwrap_or_else(|| Ok(vec![Ident::new("id", Span::call_site())]))?; let fields = fields_from_item_data(&item.data)?; Ok(Self { - name: item.ident, + name: item.ident.clone(), table_name_from_attribute, primary_key_names, fields, @@ -30,27 +30,27 @@ impl Model { } pub fn table_name(&self) -> syn::Ident { - self.table_name_from_attribute.unwrap_or_else(|| { + self.table_name_from_attribute.clone().unwrap_or_else(|| { syn::Ident::new( - &infer_table_name(self.name.as_ref()), + &infer_table_name(&self.name.to_string()), self.name.span().resolved_at(Span::call_site()), ) }) } pub fn dummy_mod_name(&self, trait_name: &str) -> syn::Ident { - let name = self.name.as_ref().to_lowercase(); - format!("_impl_{}_for_{}", trait_name, name).into() + let name = format!("_impl_{}_for_{}", trait_name, self.name).to_lowercase(); + Ident::new(&name, Span::call_site()) } pub fn fields(&self) -> &[Field] { &self.fields } - pub fn find_column(&self, column_name: syn::Ident) -> Result<&Field, Diagnostic> { + pub fn find_column(&self, column_name: &syn::Ident) -> Result<&Field, Diagnostic> { self.fields() .iter() - .find(|f| f.column_name() == column_name) + .find(|f| &f.column_name() == column_name) .ok_or_else(|| { column_name .span() diff --git a/diesel_derives/src/query_id.rs b/diesel_derives/src/query_id.rs index b7fe4550e399..296b6e971a14 100644 --- a/diesel_derives/src/query_id.rs +++ b/diesel_derives/src/query_id.rs @@ -1,28 +1,29 @@ -use quote; +use proc_macro2; +use proc_macro2::*; use syn; use util::*; -pub fn derive(mut item: syn::DeriveInput) -> Result { +pub fn derive(mut item: syn::DeriveInput) -> Result { for ty_param in item.generics.type_params_mut() { ty_param.bounds.push(parse_quote!(QueryId)); } let (impl_generics, ty_generics, where_clause) = item.generics.split_for_impl(); - let struct_name = item.ident; + let struct_name = &item.ident; let lifetimes = item.generics.lifetimes(); let query_id_ty_params = item.generics .type_params() - .map(|ty_param| ty_param.ident) + .map(|ty_param| &ty_param.ident) .map(|ty_param| quote!(<#ty_param as QueryId>::QueryId)); let has_static_query_id = item.generics .type_params() - .map(|ty_param| ty_param.ident) + .map(|ty_param| &ty_param.ident) .map(|ty_param| quote!(<#ty_param as QueryId>::HAS_STATIC_QUERY_ID)); - let dummy_mod = format!("_impl_query_id_for_{}", item.ident.as_ref().to_lowercase()); + let dummy_mod = format!("_impl_query_id_for_{}", item.ident).to_lowercase(); Ok(wrap_in_dummy_mod( - dummy_mod.into(), + Ident::new(&dummy_mod, Span::call_site()), quote! { use diesel::query_builder::QueryId; diff --git a/diesel_derives/src/queryable.rs b/diesel_derives/src/queryable.rs index 3f0bc99529c9..cd47172b7b03 100644 --- a/diesel_derives/src/queryable.rs +++ b/diesel_derives/src/queryable.rs @@ -1,13 +1,13 @@ -use quote; +use proc_macro2; use syn; use model::*; use util::*; -pub fn derive(item: syn::DeriveInput) -> Result { +pub fn derive(item: syn::DeriveInput) -> Result { let model = Model::from_item(&item)?; - let struct_name = item.ident; + let struct_name = &item.ident; let field_ty = model.fields().iter().map(|f| &f.ty).collect::>(); let field_ty = &field_ty; let build_expr = model.fields().iter().enumerate().map(|(i, f)| { diff --git a/diesel_derives/src/queryable_by_name.rs b/diesel_derives/src/queryable_by_name.rs index 0c082e3c5650..ece23091eeb4 100644 --- a/diesel_derives/src/queryable_by_name.rs +++ b/diesel_derives/src/queryable_by_name.rs @@ -1,14 +1,14 @@ -use quote; +use proc_macro2::{self, Ident, Span}; use syn; use field::*; use model::*; use util::*; -pub fn derive(item: syn::DeriveInput) -> Result { +pub fn derive(item: syn::DeriveInput) -> Result { let model = Model::from_item(&item)?; - let struct_name = item.ident; + let struct_name = &item.ident; let field_expr = model.fields().iter().map(|f| field_expr(f, &model)); let (_, ty_generics, ..) = item.generics.split_for_impl(); @@ -78,8 +78,8 @@ fn sql_type(field: &Field, model: &Model) -> syn::Type { parse_quote!(diesel::dsl::SqlTypeOf<#table_name::#column_name>) } else { let field_name = match field.name { - FieldName::Named(ref x) => x.as_ref(), - _ => "field", + FieldName::Named(ref x) => x.clone(), + _ => Ident::new("field", Span::call_site()), }; field .span diff --git a/diesel_derives/src/sql_type.rs b/diesel_derives/src/sql_type.rs index cd36cd8ff94b..74f28dfb877b 100644 --- a/diesel_derives/src/sql_type.rs +++ b/diesel_derives/src/sql_type.rs @@ -1,11 +1,12 @@ -use quote; +use proc_macro2; +use proc_macro2::*; use syn; use meta::*; use util::*; -pub fn derive(item: syn::DeriveInput) -> Result { - let struct_name = item.ident; +pub fn derive(item: syn::DeriveInput) -> Result { + let struct_name = &item.ident; let (impl_generics, ty_generics, where_clause) = item.generics.split_for_impl(); let sqlite_tokens = sqlite_tokens(&item); @@ -14,7 +15,7 @@ pub fn derive(item: syn::DeriveInput) -> Result { let dummy_name = format!("_impl_sql_type_for_{}", item.ident); Ok(wrap_in_dummy_mod( - dummy_name.to_lowercase().into(), + Ident::new(&dummy_name.to_lowercase(), Span::call_site()), quote! { impl #impl_generics diesel::sql_types::NotNull for #struct_name #ty_generics @@ -35,7 +36,7 @@ pub fn derive(item: syn::DeriveInput) -> Result { )) } -fn sqlite_tokens(item: &syn::DeriveInput) -> Option { +fn sqlite_tokens(item: &syn::DeriveInput) -> Option { MetaItem::with_name(&item.attrs, "sqlite_type") .map(|attr| attr.expect_ident_value()) .and_then(|ty| { @@ -43,7 +44,7 @@ fn sqlite_tokens(item: &syn::DeriveInput) -> Option { return None; } - let struct_name = item.ident; + let struct_name = &item.ident; let (impl_generics, ty_generics, where_clause) = item.generics.split_for_impl(); Some(quote! { @@ -59,7 +60,7 @@ fn sqlite_tokens(item: &syn::DeriveInput) -> Option { }) } -fn mysql_tokens(item: &syn::DeriveInput) -> Option { +fn mysql_tokens(item: &syn::DeriveInput) -> Option { MetaItem::with_name(&item.attrs, "mysql_type") .map(|attr| attr.expect_ident_value()) .and_then(|ty| { @@ -67,7 +68,7 @@ fn mysql_tokens(item: &syn::DeriveInput) -> Option { return None; } - let struct_name = item.ident; + let struct_name = &item.ident; let (impl_generics, ty_generics, where_clause) = item.generics.split_for_impl(); Some(quote! { @@ -83,7 +84,7 @@ fn mysql_tokens(item: &syn::DeriveInput) -> Option { }) } -fn pg_tokens(item: &syn::DeriveInput) -> Option { +fn pg_tokens(item: &syn::DeriveInput) -> Option { MetaItem::with_name(&item.attrs, "postgres") .and_then(|attr| { get_type_name(&attr) @@ -101,7 +102,7 @@ fn pg_tokens(item: &syn::DeriveInput) -> Option { return None; } - let struct_name = item.ident; + let struct_name = &item.ident; let (impl_generics, ty_generics, where_clause) = item.generics.split_for_impl(); let metadata_fn = match ty { diff --git a/diesel_derives/src/util.rs b/diesel_derives/src/util.rs index d9927328bd17..886720b1560d 100644 --- a/diesel_derives/src/util.rs +++ b/diesel_derives/src/util.rs @@ -1,14 +1,13 @@ -use proc_macro2::Span; -use quote::Tokens; +use proc_macro2::*; use syn::*; pub use diagnostic_shim::*; use meta::*; -pub fn wrap_in_dummy_mod(const_name: Ident, item: Tokens) -> Tokens { +pub fn wrap_in_dummy_mod(const_name: Ident, item: TokenStream) -> TokenStream { quote! { #[allow(non_snake_case, unused_extern_crates, unused_imports)] - mod #const_name { + fn #const_name() { // https://github.com/rust-lang/rust/issues/47314 extern crate std; use diesel; @@ -60,14 +59,20 @@ pub fn ty_for_foreign_derive(item: &DeriveInput, flags: &MetaItem) -> Result Span { +pub fn fix_span(maybe_bad_span: Span, mut fallback: Span) -> Span { let bad_span_debug = "#0 bytes(0..0)"; + + if format!("{:?}", fallback) == bad_span_debug { + // On recent rust nightlies, even our fallback span is bad. + fallback = Span::call_site(); + } + if format!("{:?}", maybe_bad_span) == bad_span_debug { fallback } else { diff --git a/diesel_migrations/Cargo.toml b/diesel_migrations/Cargo.toml index 1bd5483ac651..7f27e33a06c3 100644 --- a/diesel_migrations/Cargo.toml +++ b/diesel_migrations/Cargo.toml @@ -9,7 +9,6 @@ homepage = "http://diesel.rs" [dependencies] -clippy = { optional = true, version = "=0.0.195" } migrations_internals = "~1.3.0" migrations_macros = "~1.3.0" @@ -20,7 +19,6 @@ cfg-if = "0.1.0" [features] default = [] -lint = ["clippy"] sqlite = [] postgres = [] mysql = [] diff --git a/diesel_migrations/migrations_internals/Cargo.toml b/diesel_migrations/migrations_internals/Cargo.toml index 8f7d24b86436..7d8373277abf 100644 --- a/diesel_migrations/migrations_internals/Cargo.toml +++ b/diesel_migrations/migrations_internals/Cargo.toml @@ -7,7 +7,6 @@ description = "Internal implementation of diesels migration mechanism" homepage = "http://diesel.rs" [dependencies] -clippy = { optional = true, version = "=0.0.195" } diesel = { version = "~1.3.0", default-features = false } barrel = { version = "<= 0.2.0", optional = true, features = ["diesel-filled"] } @@ -16,4 +15,3 @@ tempdir = "0.3.4" [features] default = [] -lint = ["clippy"] diff --git a/diesel_migrations/migrations_internals/src/lib.rs b/diesel_migrations/migrations_internals/src/lib.rs index b73cb7fc64b0..f89da0bf1a41 100644 --- a/diesel_migrations/migrations_internals/src/lib.rs +++ b/diesel_migrations/migrations_internals/src/lib.rs @@ -1,22 +1,19 @@ // Built-in Lints #![deny(warnings, missing_debug_implementations, missing_copy_implementations)] // Clippy lints -#![cfg_attr(feature = "clippy", allow(unstable_features))] -#![cfg_attr(feature = "clippy", feature(plugin))] -#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../../clippy.toml")))] #![cfg_attr( - feature = "clippy", + feature = "cargo-clippy", allow(option_map_unwrap_or_else, option_map_unwrap_or, match_same_arms, type_complexity) )] #![cfg_attr( - feature = "clippy", + feature = "cargo-clippy", warn( option_unwrap_used, result_unwrap_used, print_stdout, wrong_pub_self_convention, mut_mut, non_ascii_literal, similar_names, unicode_not_nfc, enum_glob_use, if_not_else, items_after_statements, used_underscore_binding ) )] -#![cfg_attr(all(test, feature = "clippy"), allow(option_unwrap_used, result_unwrap_used))] +#![cfg_attr(all(test, feature = "cargo-clippy"), allow(option_unwrap_used, result_unwrap_used))] //! Provides functions for maintaining database schema. //! //! A database migration always provides procedures to update the schema, as well as to revert diff --git a/diesel_migrations/migrations_internals/src/migration.rs b/diesel_migrations/migrations_internals/src/migration.rs index 0d25c271ea2d..3ab781ad12f7 100644 --- a/diesel_migrations/migrations_internals/src/migration.rs +++ b/diesel_migrations/migrations_internals/src/migration.rs @@ -74,7 +74,7 @@ fn file_names(path: &Path) -> Result, MigrationError> { #[doc(hidden)] pub fn version_from_path(path: &Path) -> Result { path.file_name() - .expect(&format!("Can't get file name from path `{:?}`", path)) + .unwrap_or_else(|| panic!("Can't get file name from path `{:?}`", path)) .to_string_lossy() .split('_') .nth(0) diff --git a/diesel_migrations/migrations_macros/Cargo.toml b/diesel_migrations/migrations_macros/Cargo.toml index 6731c48fc7dd..1b4312c55ee4 100644 --- a/diesel_migrations/migrations_macros/Cargo.toml +++ b/diesel_migrations/migrations_macros/Cargo.toml @@ -8,7 +8,6 @@ documentation = "http://docs.diesel.rs" homepage = "http://diesel.rs" [dependencies] -clippy = { optional = true, version = "=0.0.195" } migrations_internals = "~1.3.0" syn = { version = "0.11.4", features = ["aster"] } quote = "0.3.12" @@ -21,4 +20,3 @@ proc-macro = true [features] default = [] -lint = ["clippy"] diff --git a/diesel_migrations/migrations_macros/src/lib.rs b/diesel_migrations/migrations_macros/src/lib.rs index ccf9ba372232..63ea72f846ad 100644 --- a/diesel_migrations/migrations_macros/src/lib.rs +++ b/diesel_migrations/migrations_macros/src/lib.rs @@ -1,22 +1,19 @@ // Built-in Lints #![deny(warnings, missing_debug_implementations, missing_copy_implementations)] // Clippy lints -#![cfg_attr(feature = "clippy", allow(unstable_features))] -#![cfg_attr(feature = "clippy", feature(plugin))] -#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../../clippy.toml")))] #![cfg_attr( - feature = "clippy", + feature = "cargo-clippy", allow(option_map_unwrap_or_else, option_map_unwrap_or, match_same_arms, type_complexity) )] #![cfg_attr( - feature = "clippy", + feature = "cargo-clippy", warn( option_unwrap_used, print_stdout, wrong_pub_self_convention, mut_mut, non_ascii_literal, similar_names, unicode_not_nfc, enum_glob_use, if_not_else, items_after_statements, used_underscore_binding ) )] -#![cfg_attr(all(test, feature = "clippy"), allow(option_unwrap_used, result_unwrap_used))] +#![cfg_attr(all(test, feature = "cargo-clippy"), allow(option_unwrap_used, result_unwrap_used))] extern crate migrations_internals; extern crate proc_macro; #[macro_use] diff --git a/diesel_migrations/src/lib.rs b/diesel_migrations/src/lib.rs index f62675210e13..caa3d94a4c97 100644 --- a/diesel_migrations/src/lib.rs +++ b/diesel_migrations/src/lib.rs @@ -1,12 +1,10 @@ // Built-in Lints #![deny(warnings, missing_copy_implementations)] // Clippy lints -#![cfg_attr(feature = "clippy", allow(needless_pass_by_value))] -#![cfg_attr(feature = "clippy", feature(plugin))] -#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] -#![cfg_attr(feature = "clippy", allow(option_map_unwrap_or_else, option_map_unwrap_or))] +#![cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] +#![cfg_attr(feature = "cargo-clippy", allow(option_map_unwrap_or_else, option_map_unwrap_or))] #![cfg_attr( - feature = "clippy", + feature = "cargo-clippy", warn( wrong_pub_self_convention, mut_mut, non_ascii_literal, similar_names, unicode_not_nfc, if_not_else, items_after_statements, used_underscore_binding @@ -75,7 +73,7 @@ //! ``` extern crate migrations_internals; -#[cfg_attr(feature = "clippy", allow(useless_attribute))] +#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))] #[allow(unused_imports)] #[macro_use] extern crate migrations_macros; diff --git a/diesel_tests/Cargo.toml b/diesel_tests/Cargo.toml index 49fc58fea2e9..b93ad824c3ad 100644 --- a/diesel_tests/Cargo.toml +++ b/diesel_tests/Cargo.toml @@ -29,7 +29,6 @@ unstable = ["diesel/unstable"] postgres = ["diesel/postgres", "diesel_infer_schema/postgres"] sqlite = ["diesel/sqlite", "diesel_infer_schema/sqlite"] mysql = ["diesel/mysql", "diesel_infer_schema/mysql"] -lint = ["diesel/lint"] [[test]] name = "integration_tests" diff --git a/examples/postgres/advanced-blog-cli/src/comment.rs b/examples/postgres/advanced-blog-cli/src/comment.rs index 033603d64915..8bf77f6f2118 100644 --- a/examples/postgres/advanced-blog-cli/src/comment.rs +++ b/examples/postgres/advanced-blog-cli/src/comment.rs @@ -25,6 +25,6 @@ pub fn render(comments_and_post_title: &[(Comment, String)]) { comment.id ); println!("{}", comment.body); - print!("===============\n\n"); + println!("===============\n"); } } diff --git a/examples/postgres/advanced-blog-cli/src/post.rs b/examples/postgres/advanced-blog-cli/src/post.rs index e3ca008d57b8..0a00b33a7ab2 100644 --- a/examples/postgres/advanced-blog-cli/src/post.rs +++ b/examples/postgres/advanced-blog-cli/src/post.rs @@ -53,8 +53,7 @@ pub fn render(post: &Post, user: &User, comments: &[(Comment, User)]) { } Published { at } => println!("Published at {}", at.format("%F %T")), } - print!("\n"); - println!("{}", post.body); + println!("\n{}", post.body); if !comments.is_empty() { println!("---------------\n"); @@ -66,9 +65,9 @@ pub fn render(post: &Post, user: &User, comments: &[(Comment, User)]) { let edited = comment.updated_at.format("%F %T"); print!(" (last edited {})", edited); } - print!("\n{}\n", comment.body); + println!("\n{}", comment.body); } } - print!("===============\n\n"); + println!("===============\n"); }