Repository: diesel-rs/diesel (language: rust)

Issue:
Compile error in DateTimeProxy when no backend is enabled
<!--
If you want to report a bug, we added some points below which help us track down the problem faster.
-->

## Setup

### Versions

- **Rust:** 1.71.1
- **Diesel:** 2.1
- **Database:** None
- **Operating System** Linux

### Feature Flags

- **diesel:** time

## Problem Description

When the `time` feature is enabled without any database backend, compilation fails with the following error:

    error: At least one `sql_type` is needed for deriving `AsExpression` on a structure.
    --> /home/surban/.cargo/registry/src/index.crates.io-6f17d22bba15001f/diesel-2.1.0/src/type_impls/date_and_time.rs:82:14
      |
    82 |     #[derive(AsExpression, FromSqlRow)]
       |              ^^^^^^^^^^^^
      |
     = note: this error originates in the derive macro `AsExpression` (in Nightly builds, run with -Z macro-backtrace for more info)

As the error message says, no `sql_type` cfg_attr is active for [DateTimeProxy](https://github.com/diesel-rs/diesel/blob/7e2cd73e9c545b0f4fe41b95c209d2bb6f40ad2e/diesel/src/type_impls/date_and_time.rs#L51).

### What are you trying to accomplish?

For some build configurations of my Rust project it makes sense to include Diesel as a dependency but without any enabled backends. This worked until I enabled the `time` crate feature.

### What is the expected output?

Diesel compiles fine without any enabled backend.

### What is the actual output?

Diesel fails to compile.


## Checklist

- [X] I have already looked over the [issue tracker](https://github.com/diesel-rs/diesel/issues) and the [discussion forum](https://github.com/diesel-rs/diesel/discussions) for similar possible closed issues.
<!--
If you are unsure if your issue is a duplicate of an existing issue please link the issue in question here
--> 
- [X] This issue can be reproduced on Rust's stable channel. (Your issue will be
  closed if this is not the case)
- [X] This issue can be reproduced without requiring a third party crate

<!--
Thank you for your submission!  You're helping make Diesel more robust 🎉

We'll try to respond as quickly as possible.
-->



Discussion / hints:

Fix patch:
diff --git a/diesel/src/type_impls/date_and_time.rs b/diesel/src/type_impls/date_and_time.rs
index b189fc275e1e..651a2cc33c87 100644
--- a/diesel/src/type_impls/date_and_time.rs
+++ b/diesel/src/type_impls/date_and_time.rs
@@ -79,8 +79,16 @@ mod time {
     #[cfg_attr(feature = "mysql_backend", diesel(sql_type = crate::sql_types::Datetime))]
     struct NaiveDateTimeProxy(PrimitiveDateTime);
 
-    #[derive(AsExpression, FromSqlRow)]
+    #[derive(FromSqlRow)]
     #[diesel(foreign_derive)]
+    #[cfg_attr(
+        any(
+            feature = "postgres_backend",
+            feature = "sqlite",
+            feature = "mysql_backend"
+        ),
+        derive(AsExpression)
+    )]
     #[cfg_attr(
         feature = "postgres_backend",
         diesel(sql_type = crate::sql_types::Timestamptz)


Test patch: