Skip to content

Commit

Permalink
Merge pull request #3812 from weiznich/use_diagnostic_on_unimplemented
Browse files Browse the repository at this point in the history
Use `#[diagnostic::on_unimplemented]`
  • Loading branch information
weiznich authored Oct 4, 2023
2 parents 9174a25 + 10fc1f2 commit 0377c25
Show file tree
Hide file tree
Showing 111 changed files with 2,218 additions and 1,496 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ jobs:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-01-22
toolchain: nightly-2023-09-21
- name: Cache cargo registry
uses: actions/cache@v3
with:
Expand All @@ -318,7 +318,7 @@ jobs:
- name: Run compile tests
shell: bash
run: cargo +nightly-2023-01-22 test --manifest-path diesel_compile_tests/Cargo.toml
run: cargo +nightly-2023-09-21 test --manifest-path diesel_compile_tests/Cargo.toml

rustfmt_and_clippy:
name: Check rustfmt style && run clippy
Expand Down
7 changes: 3 additions & 4 deletions diesel/src/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ pub use diesel_derives::QueryableByName;
/// ```
#[cfg_attr(
feature = "nightly-error-messages",
rustc_on_unimplemented(
diagnostic::on_unimplemented(
message = "Cannot deserialize a value of the database type `{A}` as `{Self}`",
note = "Double check your type mappings via the documentation of `{A}`"
)
Expand Down Expand Up @@ -453,11 +453,10 @@ pub trait FromSql<A, DB: Backend>: Sized {
/// * [`QueryableByName`]
#[cfg_attr(
feature = "nightly-error-messages",
rustc_on_unimplemented(on(
ST = "diesel::sql_types::Untyped",
diagnostic::on_unimplemented(
note = "`diesel::sql_query` requires the loading target to column names for loading values.\n\
You need to provide a type that explicitly derives `diesel::deserialize::QueryableByName`",
))
)
)]
pub trait FromSqlRow<ST, DB: Backend>: Sized {
/// See the trait documentation.
Expand Down
2 changes: 1 addition & 1 deletion diesel/src/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ where
/// a left join, you must call `.nullable()` on it.
#[cfg_attr(
feature = "nightly-error-messages",
rustc_on_unimplemented(
diagnostic::on_unimplemented(
message = "Cannot select `{Self}` from `{QS}`",
note = "`{Self}` is no valid selection for `{QS}`"
)
Expand Down
3 changes: 2 additions & 1 deletion diesel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
//! various bugs in rustdoc. It can be used to check if you depend on any such hidden `#[deprecated]` item.
//! - `nightly-error-messages`: This feature enables the generation of improved compiler error messages for
//! common mistakes using diesel. This feature requires a nightly rust compiler and is considered to be unstable.
//! It requires adding `#![feature(diagnostic_namespace)]` to your crate.
//! We might remove it in future diesel versions without replacement or deprecation.
//!
//!
Expand All @@ -222,7 +223,7 @@
//! - `with-deprecated`
//! - `32-column-tables`

#![cfg_attr(feature = "nightly-error-messages", feature(rustc_attrs))]
#![cfg_attr(feature = "nightly-error-messages", feature(diagnostic_namespace))]
#![cfg_attr(feature = "unstable", feature(trait_alias))]
#![cfg_attr(doc_cfg, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(feature = "128-column-tables", recursion_limit = "256")]
Expand Down
8 changes: 8 additions & 0 deletions diesel/src/query_dsl/load_dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ mod private {
doc_cfg,
doc(cfg(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"))
)]
#[cfg_attr(
feature = "nightly-error-messages",
diagnostic::on_unimplemented(
note = "This is a mismatch between what your query returns and what your type expects the query to return\n\
Consider using `#[derive(Selectable)]` + `#[diesel(check_for_backend({DB}))]` on your struct `{U}` and \n\
in your query `.select({U}::as_select())` to get a better error message",
)
)]
pub trait CompatibleType<U, DB> {
type SqlType;
}
Expand Down
2 changes: 1 addition & 1 deletion diesel_compile_tests/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2023-01-22
nightly-2023-09-21
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(diagnostic_namespace)]
extern crate diesel;

use diesel::*;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error[E0271]: type mismatch resolving `<table as AppearsInFromClause<table>>::Co
--> tests/fail/any_is_only_selectable_if_inner_expr_is_selectable.rs:31:15
|
31 | .load(&mut conn);
| ---- ^^^^^^^^^ expected struct `Once`, found struct `Never`
| ---- ^^^^^^^^^ expected `Once`, found `Never`
| |
| required by a bound introduced by this call
|
Expand All @@ -27,6 +27,9 @@ note: required for `more_stuff::columns::names` to implement `AppearsOnTable<stu
note: required by a bound in `diesel::RunQueryDsl::load`
--> $DIESEL/src/query_dsl/mod.rs
|
| fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>
| ---- required by a bound in this associated function
| where
| Self: LoadQuery<'query, Conn, U>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::load`

Expand Down Expand Up @@ -59,5 +62,8 @@ note: required for `more_stuff::columns::names` to implement `AppearsOnTable<stu
note: required by a bound in `diesel::RunQueryDsl::load`
--> $DIESEL/src/query_dsl/mod.rs
|
| fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>
| ---- required by a bound in this associated function
| where
| Self: LoadQuery<'query, Conn, U>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::load`
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(diagnostic_namespace)]
extern crate diesel;

use diesel::dsl::*;
Expand Down
Loading

0 comments on commit 0377c25

Please sign in to comment.