diff --git a/.travis.yml b/.travis.yml index 3c0d6e224a1e..fc76eaac5e87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,8 +43,9 @@ matrix: allow_failures: - rust: nightly include: - - rust: nightly-2019-02-26 + - rust: nightly-2019-08-01 name: "Compile tests" + env: RUSTFLAGS="--cap-lints=warn" script: - (cd diesel_compile_tests && cargo +$TRAVIS_RUST_VERSION test) - rust: 1.34.0 diff --git a/_build/azure-pipelines-template.yml b/_build/azure-pipelines-template.yml index dcacda1ec165..068376ca3b4a 100644 --- a/_build/azure-pipelines-template.yml +++ b/_build/azure-pipelines-template.yml @@ -20,46 +20,63 @@ jobs: parameters: platform: ${{parameters.name}} rust_version: $(RUSTUP_TOOLCHAIN) - - bash: | - echo $PATH - echo $MYSQLCLIENT_LIB_DIR - displayName: Sanity check path - - bash: | - if [[ "$RUSTUP_TOOLCHAIN" == nightly* ]]; then + - template: failable_step.yml + parameters: + rust_version: $(RUSTUP_TOOLCHAIN) + displayName: Test diesel + bash: | + if [[ "$RUSTUP_TOOLCHAIN" == nightly* ]]; then (cd diesel && cargo test --no-default-features --features "unstable extras $BACKEND") - else + else (cd diesel && cargo test --no-default-features --features "extras $BACKEND") - fi && - (cd diesel && cargo test --no-default-features --features "extras with-deprecated $BACKEND") - displayName: Test diesel - - bash: | - (cd diesel_derives && cargo test --features "diesel/$BACKEND") && - if [[ "$RUSTUP_TOOLCHAIN" == nightly* ]]; then + fi && + (cd diesel && cargo test --no-default-features --features "extras with-deprecated $BACKEND") + - template: failable_step.yml + parameters: + rust_version: $(RUSTUP_TOOLCHAIN) + bash: | + (cd diesel_derives && cargo test --features "diesel/$BACKEND") && + if [[ "$RUSTUP_TOOLCHAIN" == nightly* ]]; then (cd diesel_derives && cargo test --features "diesel/unstable diesel/$BACKEND") - fi - displayName: Test diesel-derives - - bash: | - (cd "examples/$BACKEND" && ./test_all) - displayName: Test diesel examples - - bash: | - (cd diesel_cli && cargo test --no-default-features --features "$BACKEND") - displayName: Test diesel-cli - - bash: | - (cd diesel_migrations/migrations_internals && cargo test ) && - (cd diesel_migrations/migrations_macros && cargo test ) && - (cd diesel_migrations/ && cargo test --features "$BACKEND diesel/$BACKEND" ) - displayName: Test diesel-migrations - - bash: | - if [[ "$RUSTUP_TOOLCHAIN" == nightly* ]]; then - (cd diesel_tests && cargo test --no-default-features --features "unstable $BACKEND") - else - (cd diesel_tests && cargo test --no-default-features --features "$BACKEND") - fi - displayName: Run diesel tests - - bash: | - if [[ "$RUSTUP_TOOLCHAIN" == nightly* ]]; then - (cd diesel && cargo doc --no-deps --features "$BACKEND unstable") - else - (cd diesel && cargo doc --no-deps --features "$BACKEND") - fi - displayName: Run rustdoc + fi + displayName: Test diesel-derives + - template: failable_step.yml + parameters: + rust_version: $(RUSTUP_TOOLCHAIN) + bash: | + (cd "examples/$BACKEND" && ./test_all) + displayName: Test diesel examples + - template: failable_step.yml + parameters: + rust_version: $(RUSTUP_TOOLCHAIN) + bash: | + (cd diesel_cli && cargo test --no-default-features --features "$BACKEND") + displayName: Test diesel-cli + - template: failable_step.yml + parameters: + rust_version: $(RUSTUP_TOOLCHAIN) + bash: | + (cd diesel_migrations/migrations_internals && cargo test ) && + (cd diesel_migrations/migrations_macros && cargo test ) && + (cd diesel_migrations/ && cargo test --features "$BACKEND diesel/$BACKEND" ) + displayName: Test diesel-migrations + - template: failable_step.yml + parameters: + rust_version: $(RUSTUP_TOOLCHAIN) + bash: | + if [[ "$RUSTUP_TOOLCHAIN" == nightly* ]]; then + (cd diesel_tests && cargo test --no-default-features --features "unstable $BACKEND") + else + (cd diesel_tests && cargo test --no-default-features --features "$BACKEND") + fi + displayName: Run diesel tests + - template: failable_step.yml + parameters: + rust_version: $(RUSTUP_TOOLCHAIN) + bash: | + if [[ "$RUSTUP_TOOLCHAIN" == nightly* ]]; then + (cd diesel && cargo doc --no-deps --features "$BACKEND unstable") + else + (cd diesel && cargo doc --no-deps --features "$BACKEND") + fi + displayName: Run rustdoc diff --git a/_build/failable_step.yml b/_build/failable_step.yml new file mode 100644 index 000000000000..31b44bafcc9b --- /dev/null +++ b/_build/failable_step.yml @@ -0,0 +1,29 @@ +parameters: + rust_version: '' + +steps: + - bash: | + if [[ "$RUST_VERSION" == nightly* ]]; then + export RUSTFLAGS='--cap-lints=warn' + (${{ parameters.bash }}) 2>&1 | tee log + export EXIT_CODE=${PIPESTATUS[0]} + echo "The exit code is $EXIT_CODE" + if grep -q "warning:" log; then + echo -e "\043#vso[task.logissue type=warning;]${{ parameters.displayName}} contains new warnings" + fi + if [[ $EXIT_CODE -eq 0 ]]; then + true + else + false + fi + else + ${{ parameters.bash }} + fi + displayName: ${{ parameters.displayName }} + env: + RUST_VERSION: ${{parameters.rust_version}} + condition: | + or( + startsWith(variables['parameters.rust_version'], 'nightly'), + succeeded() + ) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5cc8d21449d6..c9be8b763757 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -178,13 +178,15 @@ jobs: - template: _build/install-rust.yml parameters: platform: Linux - rust_version: nightly-2019-02-26 + rust_version: nightly-2019-08-01 - bash: | sudo apt-get update && sudo apt-get -y install libsqlite3-dev libpq-dev libmysqlclient-dev displayName: Install build dependencies - bash: | (cd diesel_compile_tests && cargo test) + env: + RUSTFLAGS: '--cap-lints=warn' displayName: Run compile tests - job: RUSTFMT_AND_CLIPPY diff --git a/diesel/src/expression/operators.rs b/diesel/src/expression/operators.rs index 30e86be9443d..48492a4496a2 100644 --- a/diesel/src/expression/operators.rs +++ b/diesel/src/expression/operators.rs @@ -1,5 +1,3 @@ -#![cfg_attr(rustfmt, rustfmt_skip)] // https://github.com/rust-lang-nursery/rustfmt/issues/2755 - #[macro_export] #[doc(hidden)] macro_rules! __diesel_operator_body { @@ -361,7 +359,6 @@ macro_rules! diesel_prefix_operator { } } -infix_operator!(Concat, " || ", ReturnBasedOnArgs); infix_operator!(And, " AND "); infix_operator!(Between, " BETWEEN "); infix_operator!(Escape, " ESCAPE "); @@ -409,3 +406,44 @@ where Eq::new(self.left, &self.right).values() } } + +#[derive(Debug, Clone, Copy, QueryId, DieselNumericOps, NonAggregate)] +#[doc(hidden)] +pub struct Concat { + pub(crate) left: L, + pub(crate) right: R, +} + +impl Concat { + pub fn new(left: L, right: R) -> Self { + Self { left, right } + } +} + +impl ::expression::Expression for Concat +where + L: ::expression::Expression, + R: ::expression::Expression, +{ + type SqlType = ST; +} + +impl_selectable_expression!(Concat); + +impl ::query_builder::QueryFragment for Concat +where + L: ::query_builder::QueryFragment, + R: ::query_builder::QueryFragment, + DB: ::backend::Backend, +{ + fn walk_ast(&self, mut out: ::query_builder::AstPass) -> ::result::QueryResult<()> { + // Those brackets are required because mysql is broken + // https://github.com/diesel-rs/diesel/issues/2133#issuecomment-517432317 + out.push_sql("("); + self.left.walk_ast(out.reborrow())?; + out.push_sql(" || "); + self.right.walk_ast(out.reborrow())?; + out.push_sql(")"); + Ok(()) + } +} diff --git a/diesel_compile_tests/Cargo.toml b/diesel_compile_tests/Cargo.toml index 9aa618d43468..a5b66b661da8 100644 --- a/diesel_compile_tests/Cargo.toml +++ b/diesel_compile_tests/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Sean Griffin "] [dependencies] diesel = { version = "1.4.0", default-features = false, features = ["extras", "sqlite", "postgres", "mysql", "unstable"] } -compiletest_rs = "=0.3.17" +compiletest_rs = "=0.3.22" [replace] "diesel:1.4.2" = { path = "../diesel" } diff --git a/diesel_compile_tests/rust-toolchain b/diesel_compile_tests/rust-toolchain index 907057cce5ed..4390c8a28437 100644 --- a/diesel_compile_tests/rust-toolchain +++ b/diesel_compile_tests/rust-toolchain @@ -1 +1 @@ -nightly-2019-02-26 +nightly-2019-08-01 diff --git a/diesel_compile_tests/tests/compile-fail/table_invalid_syntax_3.rs b/diesel_compile_tests/tests/compile-fail/table_invalid_syntax_3.rs deleted file mode 100644 index b1432e4e5627..000000000000 --- a/diesel_compile_tests/tests/compile-fail/table_invalid_syntax_3.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[macro_use] extern crate diesel; - -table! { - #[foobar] - posts { - id -> Integer, - } -} -// error-pattern: E0658 - -fn main() {} diff --git a/diesel_compile_tests/tests/ui/as_changeset_bad_column_name.stderr b/diesel_compile_tests/tests/ui/as_changeset_bad_column_name.stderr index 9cea6d124577..69a484617492 100644 --- a/diesel_compile_tests/tests/ui/as_changeset_bad_column_name.stderr +++ b/diesel_compile_tests/tests/ui/as_changeset_bad_column_name.stderr @@ -40,5 +40,5 @@ error[E0601]: `main` function not found in crate `as_changeset_bad_column_name` error: aborting due to 7 previous errors -Some errors occurred: E0412, E0425, E0601. +Some errors have detailed explanations: E0412, E0425, E0601. For more information about an error, try `rustc --explain E0412`. diff --git a/diesel_compile_tests/tests/ui/as_changeset_bad_column_name_syntax.stderr b/diesel_compile_tests/tests/ui/as_changeset_bad_column_name_syntax.stderr index 16f2abbc6ff5..3dbd44a60a30 100644 --- a/diesel_compile_tests/tests/ui/as_changeset_bad_column_name_syntax.stderr +++ b/diesel_compile_tests/tests/ui/as_changeset_bad_column_name_syntax.stderr @@ -22,5 +22,5 @@ error[E0601]: `main` function not found in crate `as_changeset_bad_column_name_s error: aborting due to 4 previous errors -Some errors occurred: E0412, E0425, E0601. +Some errors have detailed explanations: E0412, E0425, E0601. For more information about an error, try `rustc --explain E0412`. 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 1d8b36c3225c..8b042119f194 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 @@ -4,7 +4,7 @@ error: Expected `bar` found `bar = "baz"` 12 | #[primary_key(id, bar = "baz", qux(id))] | ^^^ -error: Expected `qux` found `qux ( id )` +error: Expected `qux` found `qux (id)` --> $DIR/as_changeset_bad_primary_key_syntax.rs:12:32 | 12 | #[primary_key(id, bar = "baz", qux(id))] diff --git a/diesel_compile_tests/tests/ui/as_changeset_missing_column_name_tuple_struct.stderr b/diesel_compile_tests/tests/ui/as_changeset_missing_column_name_tuple_struct.stderr index 7c325a664894..7b355a3b58ac 100644 --- a/diesel_compile_tests/tests/ui/as_changeset_missing_column_name_tuple_struct.stderr +++ b/diesel_compile_tests/tests/ui/as_changeset_missing_column_name_tuple_struct.stderr @@ -40,5 +40,5 @@ error[E0601]: `main` function not found in crate `as_changeset_missing_column_na error: aborting due to 7 previous errors -Some errors occurred: E0412, E0425, E0601. +Some errors have detailed explanations: E0412, E0425, E0601. For more information about an error, try `rustc --explain E0412`. diff --git a/diesel_compile_tests/tests/ui/as_changeset_struct_with_only_primary_key.stderr b/diesel_compile_tests/tests/ui/as_changeset_struct_with_only_primary_key.stderr index bbf69795b7f3..a58d53346a67 100644 --- a/diesel_compile_tests/tests/ui/as_changeset_struct_with_only_primary_key.stderr +++ b/diesel_compile_tests/tests/ui/as_changeset_struct_with_only_primary_key.stderr @@ -19,5 +19,5 @@ error[E0277]: the trait bound `(): diesel::query_builder::AsChangeset` is not sa error: aborting due to 3 previous errors -Some errors occurred: E0277, E0601. +Some errors have detailed explanations: E0277, E0601. For more information about an error, try `rustc --explain E0277`. 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 59ea32d2f9d4..bbfe4ce0dcdc 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 @@ -48,5 +48,5 @@ error[E0425]: cannot find value `bar_id` in module `foo` error: aborting due to 8 previous errors -Some errors occurred: E0412, E0425. +Some errors have detailed explanations: E0412, E0425. For more information about an error, try `rustc --explain E0412`. 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 80d09a76f37b..de44efcfbab5 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 @@ -36,5 +36,5 @@ error[E0425]: cannot find value `name` in module `users` error: aborting due to 6 previous errors -Some errors occurred: E0412, E0425, E0433. +Some errors have detailed explanations: E0412, E0425, E0433. For more information about an error, try `rustc --explain E0412`.