Skip to content

Commit fd9d5a5

Browse files
committed
Merge remote-tracking branch 'upstream/master' into faillible_queryable_stillgeneric
2 parents 9275b9a + 538d2df commit fd9d5a5

30 files changed

Lines changed: 272 additions & 305 deletions
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
110
<!--
2-
If you want to report a bug, we added some points below you can fill out. If you want to request a feature, feel free to remove all the irrelevant text. In addition to this [issue tracker](https://github.com/diesel-rs/diesel/issues), you can also talk to Diesel maintainers and users on [Gitter](https://gitter.im/diesel-rs/diesel).
11+
If you want to report a bug, we added some points below which help us track down the problem faster.
312
-->
413

514
## Setup
@@ -33,16 +42,22 @@ If you want to report a bug, we added some points below you can fill out. If you
3342
### Steps to reproduce
3443

3544
<!--
36-
Please include as much of your codebase as needed to reproduce the error. If the relevant files are large, please consider linking to a public repository or a [Gist](https://gist.github.com/).
45+
Please include as much of your codebase as needed to reproduce the error. If the relevant files are large, please consider linking to a public repository or a [Gist](https://gist.github.com/). This includes normally the following parts:
3746
38-
Please post as much of your database schema as necessary. If you are using `infer_schema!`, you can use `diesel print-schema` and post the relevant parts from that.
47+
* The exact code where your hit the problem
48+
* Relevant parts your schema, so any `table!` macro calls required for the
49+
* Any other type definitions involved in the code, which produces your problem
3950
-->
4051

4152
## Checklist
4253

43-
- [ ] I have already looked over the [issue tracker](https://github.com/diesel-rs/diesel/issues) for similar issues.
54+
- [ ] I have already looked over the [issue tracker](https://github.com/diesel-rs/diesel/issues) and the [disussion forum](https://github.com/diesel-rs/diesel/discussions) for similar possible closed issues.
55+
<!--
56+
If you are unsure if your issue is a duplicate of an existing issue please link the issue in question here
57+
-->
4458
- [ ] This issue can be reproduced on Rust's stable channel. (Your issue will be
4559
closed if this is not the case)
60+
- [ ] This issue can be reproduced without requiring a third party crate
4661

4762
<!--
4863
Thank you for your submission! You're helping make Diesel more robust 🎉

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: Compiler error while compiling diesel
4+
url: https://github.com/diesel-rs/diesel/issues?q=is%3Aissue+ld+returned+1+exit+status+
5+
about: Failed to compile diesel? Have a look at existing issues. You've likely miss some required dependency.
6+
- name: Simple Questions
7+
url: https://gitter.im/diesel-rs/diesel
8+
about: If you have a simple question please use our gitter channel.
9+
- name: Complex Questions
10+
url: https://github.com/diesel-rs/diesel/discussions/categories/q-a
11+
about: Do you have a larger question? Ask in our forum.
12+
- name: Feature Requests
13+
url: https://github.com/diesel-rs/diesel/discussions/categories/ideas
14+
about: If you want to suggest a new feature please create a new topic in our discussions forum

CONTRIBUTING.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ Thank you! We'll try to respond as quickly as possible.
3636

3737
## Submitting feature requests
3838

39-
If you can't find an issue (open or closed) describing your idea on our [issue
40-
tracker], open an issue. Adding answers to the following
41-
questions in your description is +1:
39+
Diesel's issue tracker is meant to represent our current roadmap. An open issue represents either a bug, or a new feature that a member of the Diesel team is actively working on.
4240

43-
- What do you want to do, and how do you expect Diesel to support you with that?
44-
- How might this be added to Diesel?
45-
- What are possible alternatives?
46-
- Are there any disadvantages?
41+
This means that you should not submit a feature request to our issue tracker, unless you were asked to do so by a member of the Diesel team. Feature requests should instead be posted in
42+
our [discussion forum](https://github.com/diesel-rs/diesel/discussions/categories/ideas).
4743

48-
Thank you! We'll try to respond as quickly as possible.
44+
If you can't find thread describing your idea on our forum, create a new one. Adding answers to the following questions in your description is +1:
45+
46+
- What do you want to do, and how do you expect Diesel to support you with that?
47+
- How might this be added to Diesel?
48+
- What are possible alternatives?
49+
- Are there any disadvantages?
4950

51+
Thank you! We'll try to respond as quickly as possible.
5052

5153
## Contribute code to Diesel
5254

diesel/src/expression/count.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::{Expression, ValidGrouping};
33
use crate::backend::Backend;
44
use crate::query_builder::*;
55
use crate::result::QueryResult;
6-
use crate::sql_types::{BigInt, DieselNumericOps, Nullable, SingleValue, SqlType};
6+
use crate::sql_types::{BigInt, DieselNumericOps, SingleValue, SqlType};
77

88
sql_function! {
99
/// Creates a SQL `COUNT` expression
@@ -25,7 +25,7 @@ sql_function! {
2525
/// # }
2626
/// ```
2727
#[aggregate]
28-
fn count<T: SqlType + SingleValue>(expr: Nullable<T>) -> BigInt;
28+
fn count<T: SqlType + SingleValue>(expr: T) -> BigInt;
2929
}
3030

3131
/// Creates a SQL `COUNT(*)` expression

diesel/src/expression/functions/aggregate_folding.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::expression::functions::sql_function;
2-
use crate::sql_types::{Foldable, Nullable};
2+
use crate::sql_types::Foldable;
33

44
sql_function! {
55
/// Represents a SQL `SUM` function. This function can only take types which are
@@ -18,7 +18,7 @@ sql_function! {
1818
/// # }
1919
/// ```
2020
#[aggregate]
21-
fn sum<ST: Foldable>(expr: Nullable<ST>) -> ST::Sum;
21+
fn sum<ST: Foldable>(expr: ST) -> ST::Sum;
2222
}
2323

2424
sql_function! {
@@ -64,5 +64,5 @@ sql_function! {
6464
/// # Ok(())
6565
/// # }
6666
#[aggregate]
67-
fn avg<ST: Foldable>(expr: Nullable<ST>) -> ST::Avg;
67+
fn avg<ST: Foldable>(expr: ST) -> ST::Avg;
6868
}

diesel/src/expression/functions/aggregate_ordering.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use crate::expression::functions::sql_function;
2-
use crate::sql_types::{IntoNullable, Nullable, SingleValue, SqlOrd, SqlType};
2+
use crate::sql_types::{IntoNullable, SingleValue, SqlOrd, SqlType};
33

44
pub trait SqlOrdAggregate: SingleValue {
55
type Ret: SqlType + SingleValue;
66
}
77

8-
impl<ST> SqlOrdAggregate for ST
8+
impl<T> SqlOrdAggregate for T
99
where
10-
ST: SqlOrd + SingleValue + IntoNullable,
11-
ST::Nullable: SingleValue,
10+
T: SqlOrd + IntoNullable + SingleValue,
11+
T::Nullable: SqlType + SingleValue,
1212
{
13-
type Ret = <Self as IntoNullable>::Nullable;
13+
type Ret = T::Nullable;
1414
}
1515

1616
sql_function! {
@@ -29,7 +29,7 @@ sql_function! {
2929
/// assert_eq!(Ok(Some(8)), animals.select(max(legs)).first(&connection));
3030
/// # }
3131
#[aggregate]
32-
fn max<ST: SqlOrdAggregate>(expr: Nullable<ST>) -> ST::Ret;
32+
fn max<ST: SqlOrdAggregate>(expr: ST) -> ST::Ret;
3333
}
3434

3535
sql_function! {
@@ -48,5 +48,5 @@ sql_function! {
4848
/// assert_eq!(Ok(Some(4)), animals.select(min(legs)).first(&connection));
4949
/// # }
5050
#[aggregate]
51-
fn min<ST: SqlOrdAggregate>(expr: Nullable<ST>) -> ST::Ret;
51+
fn min<ST: SqlOrdAggregate>(expr: ST) -> ST::Ret;
5252
}

diesel/src/expression/functions/date_and_time.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::backend::Backend;
2+
use crate::expression::coerce::Coerce;
23
use crate::expression::functions::sql_function;
3-
#[cfg(feature = "postgres")]
4-
use crate::expression::{coerce::Coerce, AsExpression};
5-
use crate::expression::{Expression, ValidGrouping};
4+
use crate::expression::{AsExpression, Expression, ValidGrouping};
65
use crate::query_builder::*;
76
use crate::result::QueryResult;
87
use crate::sql_types::*;
@@ -47,6 +46,14 @@ sql_function! {
4746
fn date(expr: Timestamp) -> Date;
4847
}
4948

49+
impl AsExpression<Nullable<Timestamp>> for now {
50+
type Expression = Coerce<now, Nullable<Timestamp>>;
51+
52+
fn as_expression(self) -> Self::Expression {
53+
Coerce::new(self)
54+
}
55+
}
56+
5057
#[cfg(feature = "postgres")]
5158
impl AsExpression<Timestamptz> for now {
5259
type Expression = Coerce<now, Timestamptz>;
@@ -85,3 +92,11 @@ impl_selectable_expression!(today);
8592

8693
operator_allowed!(today, Add, add);
8794
operator_allowed!(today, Sub, sub);
95+
96+
impl AsExpression<Nullable<Date>> for today {
97+
type Expression = Coerce<today, Nullable<Date>>;
98+
99+
fn as_expression(self) -> Self::Expression {
100+
Coerce::new(self)
101+
}
102+
}

diesel/src/expression/functions/helper_types.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#![allow(non_camel_case_types)]
22

3-
use crate::dsl::{AsExprOf, SqlTypeOf};
3+
use crate::dsl::SqlTypeOf;
44
use crate::expression::grouped::Grouped;
55
use crate::expression::operators;
6-
use crate::sql_types::{Bool, Nullable};
76

87
/// The return type of [`not(expr)`](../dsl/fn.not.html)
9-
pub type not<Expr> = operators::Not<Grouped<AsExprOf<Expr, Nullable<Bool>>>>;
8+
pub type not<Expr> = operators::Not<Grouped<Expr>>;
109

1110
/// The return type of [`max(expr)`](../dsl/fn.max.html)
1211
pub type max<Expr> = super::aggregate_ordering::max::HelperType<SqlTypeOf<Expr>, Expr>;

diesel/src/expression/helper_types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ pub type Nullable<Expr> = super::nullable::Nullable<Expr>;
8989

9090
/// The return type of
9191
/// [`lhs.and(rhs)`](../expression_methods/trait.BoolExpressionMethods.html#method.and)
92-
pub type And<Lhs, Rhs> = Grouped<super::operators::And<Nullable<Lhs>, AsExpr<Rhs, Nullable<Lhs>>>>;
92+
pub type And<Lhs, Rhs, ST = sql_types::Bool> =
93+
Grouped<super::operators::And<Lhs, AsExprOf<Rhs, ST>>>;
9394

9495
/// The return type of
9596
/// [`lhs.or(rhs)`](../expression_methods/trait.BoolExpressionMethods.html#method.or)
96-
pub type Or<Lhs, Rhs> = Grouped<super::operators::Or<Lhs, AsExpr<Rhs, Nullable<Lhs>>>>;
97+
pub type Or<Lhs, Rhs, ST = sql_types::Bool> = Grouped<super::operators::Or<Lhs, AsExprOf<Rhs, ST>>>;
9798

9899
/// The return type of
99100
/// [`lhs.escape('x')`](../expression_methods/trait.EscapeExpressionMethods.html#method.escape)

diesel/src/expression/mod.rs

Lines changed: 6 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub use self::sql_literal::{SqlLiteral, UncheckedBind};
8282

8383
use crate::backend::Backend;
8484
use crate::dsl::AsExprOf;
85-
use crate::sql_types::{HasSqlType, IntoNotNullable, SingleValue, SqlType};
85+
use crate::sql_types::{HasSqlType, SingleValue, SqlType};
8686

8787
/// Represents a typed fragment of SQL.
8888
///
@@ -208,101 +208,14 @@ pub use diesel_derives::AsExpression;
208208

209209
impl<T, ST> AsExpression<ST> for T
210210
where
211-
ST: SqlType + IntoNotNullable + TypedExpressionType,
212-
ST::NotNullable: SingleValue,
213-
self::as_expression_impl::ExpressionImplHelper<T, ST::IsNull, <T::SqlType as SqlType>::IsNull>:
214-
self::as_expression_impl::AsExpressionHelper<ST>,
215-
T: Expression,
216-
T::SqlType: SqlType,
211+
T: Expression<SqlType = ST>,
212+
ST: SqlType + TypedExpressionType,
217213
{
218-
type Expression = <self::as_expression_impl::ExpressionImplHelper<
219-
T,
220-
ST::IsNull,
221-
<T::SqlType as SqlType>::IsNull,
222-
> as self::as_expression_impl::AsExpressionHelper<ST>>::Expression;
223-
224-
fn as_expression(self) -> Self::Expression {
225-
use self::as_expression_impl::AsExpressionHelper;
226-
227-
let t = self::as_expression_impl::ExpressionImplHelper::<
228-
_,
229-
ST::IsNull,
230-
<T::SqlType as SqlType>::IsNull,
231-
>(self, std::marker::PhantomData);
232-
t.as_expression()
233-
}
234-
}
235-
236-
mod as_expression_impl {
237-
use super::*;
238-
use crate::sql_types::is_nullable;
214+
type Expression = Self;
239215

240-
#[allow(missing_debug_implementations)]
241-
pub struct ExpressionImplHelper<T, IsNullExpr, IsNullAsExpr>(
242-
pub T,
243-
pub std::marker::PhantomData<(IsNullExpr, IsNullAsExpr)>,
244-
);
245-
246-
// We could use `AsExpression` here instead of defining a new trait in theory
247-
// in practice we hit https://github.com/rust-lang/rust/issues/77446 then
248-
// when defining a custom type in a third party crate
249-
pub trait AsExpressionHelper<ST: TypedExpressionType> {
250-
type Expression: Expression<SqlType = ST>;
251-
252-
fn as_expression(self) -> Self::Expression;
216+
fn as_expression(self) -> Self {
217+
self
253218
}
254-
255-
// This impl is for accepting a not nullable expression in a position where
256-
// a not nullable expression is expected
257-
impl<T, ST> AsExpressionHelper<ST>
258-
for ExpressionImplHelper<T, is_nullable::NotNull, is_nullable::NotNull>
259-
where
260-
ST: SqlType<IsNull = is_nullable::NotNull> + TypedExpressionType,
261-
T: Expression<SqlType = ST>,
262-
{
263-
type Expression = T;
264-
265-
fn as_expression(self) -> Self::Expression {
266-
self.0
267-
}
268-
}
269-
270-
// This impl is for accepting a not nullable expression in a position where
271-
// a nullable expression is expected
272-
impl<T, ST> AsExpressionHelper<ST>
273-
for ExpressionImplHelper<T, is_nullable::IsNullable, is_nullable::NotNull>
274-
where
275-
ST: SqlType<IsNull = is_nullable::IsNullable> + IntoNotNullable + TypedExpressionType,
276-
ST::NotNullable: TypedExpressionType + SqlType,
277-
T: Expression<SqlType = ST::NotNullable>,
278-
super::nullable::Nullable<T>: Expression<SqlType = ST>,
279-
{
280-
type Expression = super::nullable::Nullable<T>;
281-
282-
fn as_expression(self) -> Self::Expression {
283-
super::nullable::Nullable::new(self.0)
284-
}
285-
}
286-
287-
// This impl is for accepting a nullable expression in a position where
288-
// a nullable expression is expected
289-
impl<T, ST> AsExpressionHelper<ST>
290-
for ExpressionImplHelper<T, is_nullable::IsNullable, is_nullable::IsNullable>
291-
where
292-
ST: SqlType<IsNull = is_nullable::IsNullable> + TypedExpressionType,
293-
T: Expression<SqlType = ST>,
294-
{
295-
type Expression = T;
296-
297-
fn as_expression(self) -> Self::Expression {
298-
self.0
299-
}
300-
}
301-
302-
// impl<T, ST> AsExpressionHelper<ST> for
303-
// ExpressionImplHelper<T, is_nullable::NotNull, is_nullable::IsNullable>
304-
// is missing because we don't want to accept a nullable expression in possition where
305-
// where a not nullable expression is expected
306219
}
307220

308221
/// Converts a type to its representation for use in Diesel's query builder.

0 commit comments

Comments
 (0)