Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and/or function argument to compile check bool expression #4345

Merged
merged 4 commits into from
Nov 15, 2024
Merged
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
4 changes: 2 additions & 2 deletions diesel/src/expression_methods/bool_expression_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub trait BoolExpressionMethods: Expression + Sized {
fn and<T, ST>(self, other: T) -> dsl::And<Self, T, ST>
where
Self::SqlType: SqlType,
ST: SqlType + TypedExpressionType,
ST: SqlType + TypedExpressionType + BoolOrNullableBool,
T: AsExpression<ST>,
And<Self, T::Expression>: Expression,
{
Expand Down Expand Up @@ -89,7 +89,7 @@ pub trait BoolExpressionMethods: Expression + Sized {
fn or<T, ST>(self, other: T) -> dsl::Or<Self, T, ST>
where
Self::SqlType: SqlType,
ST: SqlType + TypedExpressionType,
ST: SqlType + TypedExpressionType + BoolOrNullableBool,
T: AsExpression<ST>,
Or<Self, T::Expression>: Expression,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error[E0277]: `diesel::sql_types::Integer` is neither `diesel::sql_types::Bool` nor `diesel::sql_types::Nullable<Bool>`
--> 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<Bool>
note: required by a bound in `diesel::BoolExpressionMethods::and`
--> $DIESEL/src/expression_methods/bool_expression_methods.rs
|
| fn and<T, ST>(self, other: T) -> dsl::And<Self, T, ST>
| --- 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<Bool>`
--> 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<Bool>
note: required by a bound in `diesel::BoolExpressionMethods::or`
--> $DIESEL/src/expression_methods/bool_expression_methods.rs
|
| fn or<T, ST>(self, other: T) -> dsl::Or<Self, T, ST>
| -- required by a bound in this associated function
...
| ST: SqlType + TypedExpressionType + BoolOrNullableBool,
| ^^^^^^^^^^^^^^^^^^ required by this bound in `BoolExpressionMethods::or`
Loading