diff --git a/diesel/src/expression_methods/bool_expression_methods.rs b/diesel/src/expression_methods/bool_expression_methods.rs index c67756bfcf0e..dcc5ba03ddd5 100644 --- a/diesel/src/expression_methods/bool_expression_methods.rs +++ b/diesel/src/expression_methods/bool_expression_methods.rs @@ -41,7 +41,7 @@ pub trait BoolExpressionMethods: Expression + Sized { fn and(self, other: T) -> dsl::And where Self::SqlType: SqlType, - ST: SqlType + TypedExpressionType, + ST: SqlType + TypedExpressionType + BoolOrNullableBool, T: AsExpression, And: Expression, { @@ -89,7 +89,7 @@ pub trait BoolExpressionMethods: Expression + Sized { fn or(self, other: T) -> dsl::Or where Self::SqlType: SqlType, - ST: SqlType + TypedExpressionType, + ST: SqlType + TypedExpressionType + BoolOrNullableBool, T: AsExpression, Or: Expression, { diff --git a/diesel_compile_tests/tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.rs b/diesel_compile_tests/tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.rs new file mode 100644 index 000000000000..35e32c01d569 --- /dev/null +++ b/diesel_compile_tests/tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.rs @@ -0,0 +1,19 @@ +extern crate diesel; + +use diesel::prelude::*; + +table! { + users { + id -> Integer, + name -> VarChar, + } +} + +fn main() { + let conn = &mut PgConnection::establish("…").unwrap(); + users::table + .filter(users::id.eq(1).and(users::id).or(users::id)) + .select(users::id) + .execute(conn) + .unwrap(); +} diff --git a/diesel_compile_tests/tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.stderr b/diesel_compile_tests/tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.stderr new file mode 100644 index 000000000000..1f0c9ad6ea2c --- /dev/null +++ b/diesel_compile_tests/tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.stderr @@ -0,0 +1,37 @@ +error[E0277]: `diesel::sql_types::Integer` is neither `diesel::sql_types::Bool` nor `diesel::sql_types::Nullable` + --> tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.rs:15:33 + | +15 | .filter(users::id.eq(1).and(users::id).or(users::id)) + | ^^^ the trait `BoolOrNullableBool` is not implemented for `diesel::sql_types::Integer` + | + = note: try to provide an expression that produces one of the expected sql types + = help: the following other types implement trait `BoolOrNullableBool`: + Bool + Nullable +note: required by a bound in `diesel::BoolExpressionMethods::and` + --> $DIESEL/src/expression_methods/bool_expression_methods.rs + | + | fn and(self, other: T) -> dsl::And + | --- required by a bound in this associated function +... + | ST: SqlType + TypedExpressionType + BoolOrNullableBool, + | ^^^^^^^^^^^^^^^^^^ required by this bound in `BoolExpressionMethods::and` + +error[E0277]: `diesel::sql_types::Integer` is neither `diesel::sql_types::Bool` nor `diesel::sql_types::Nullable` + --> tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.rs:15:48 + | +15 | .filter(users::id.eq(1).and(users::id).or(users::id)) + | ^^ the trait `BoolOrNullableBool` is not implemented for `diesel::sql_types::Integer` + | + = note: try to provide an expression that produces one of the expected sql types + = help: the following other types implement trait `BoolOrNullableBool`: + Bool + Nullable +note: required by a bound in `diesel::BoolExpressionMethods::or` + --> $DIESEL/src/expression_methods/bool_expression_methods.rs + | + | fn or(self, other: T) -> dsl::Or + | -- required by a bound in this associated function +... + | ST: SqlType + TypedExpressionType + BoolOrNullableBool, + | ^^^^^^^^^^^^^^^^^^ required by this bound in `BoolExpressionMethods::or`