Skip to content

Commit b0dedad

Browse files
committed
Merge pull request #4345 from E-anae/master
Fix and/or function argument to compile check bool expression
1 parent 9baa6db commit b0dedad

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

diesel/src/expression_methods/bool_expression_methods.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub trait BoolExpressionMethods: Expression + Sized {
4141
fn and<T, ST>(self, other: T) -> dsl::And<Self, T, ST>
4242
where
4343
Self::SqlType: SqlType,
44-
ST: SqlType + TypedExpressionType,
44+
ST: SqlType + TypedExpressionType + BoolOrNullableBool,
4545
T: AsExpression<ST>,
4646
And<Self, T::Expression>: Expression,
4747
{
@@ -89,7 +89,7 @@ pub trait BoolExpressionMethods: Expression + Sized {
8989
fn or<T, ST>(self, other: T) -> dsl::Or<Self, T, ST>
9090
where
9191
Self::SqlType: SqlType,
92-
ST: SqlType + TypedExpressionType,
92+
ST: SqlType + TypedExpressionType + BoolOrNullableBool,
9393
T: AsExpression<ST>,
9494
Or<Self, T::Expression>: Expression,
9595
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
extern crate diesel;
2+
3+
use diesel::prelude::*;
4+
5+
table! {
6+
users {
7+
id -> Integer,
8+
name -> VarChar,
9+
}
10+
}
11+
12+
fn main() {
13+
let conn = &mut PgConnection::establish("…").unwrap();
14+
users::table
15+
.filter(users::id.eq(1).and(users::id).or(users::id))
16+
.select(users::id)
17+
.execute(conn)
18+
.unwrap();
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0277]: `diesel::sql_types::Integer` is neither `diesel::sql_types::Bool` nor `diesel::sql_types::Nullable<Bool>`
2+
--> tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.rs:15:33
3+
|
4+
15 | .filter(users::id.eq(1).and(users::id).or(users::id))
5+
| ^^^ the trait `BoolOrNullableBool` is not implemented for `diesel::sql_types::Integer`
6+
|
7+
= note: try to provide an expression that produces one of the expected sql types
8+
= help: the following other types implement trait `BoolOrNullableBool`:
9+
Bool
10+
Nullable<Bool>
11+
note: required by a bound in `diesel::BoolExpressionMethods::and`
12+
--> $DIESEL/src/expression_methods/bool_expression_methods.rs
13+
|
14+
| fn and<T, ST>(self, other: T) -> dsl::And<Self, T, ST>
15+
| --- required by a bound in this associated function
16+
...
17+
| ST: SqlType + TypedExpressionType + BoolOrNullableBool,
18+
| ^^^^^^^^^^^^^^^^^^ required by this bound in `BoolExpressionMethods::and`
19+
20+
error[E0277]: `diesel::sql_types::Integer` is neither `diesel::sql_types::Bool` nor `diesel::sql_types::Nullable<Bool>`
21+
--> tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.rs:15:48
22+
|
23+
15 | .filter(users::id.eq(1).and(users::id).or(users::id))
24+
| ^^ the trait `BoolOrNullableBool` is not implemented for `diesel::sql_types::Integer`
25+
|
26+
= note: try to provide an expression that produces one of the expected sql types
27+
= help: the following other types implement trait `BoolOrNullableBool`:
28+
Bool
29+
Nullable<Bool>
30+
note: required by a bound in `diesel::BoolExpressionMethods::or`
31+
--> $DIESEL/src/expression_methods/bool_expression_methods.rs
32+
|
33+
| fn or<T, ST>(self, other: T) -> dsl::Or<Self, T, ST>
34+
| -- required by a bound in this associated function
35+
...
36+
| ST: SqlType + TypedExpressionType + BoolOrNullableBool,
37+
| ^^^^^^^^^^^^^^^^^^ required by this bound in `BoolExpressionMethods::or`

0 commit comments

Comments
 (0)