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

Issue:
the trait bound `FieldAttr: ToTokens` is not satisfied (Installing the CLI)
<!--
If you want to report a bug, we added some points below which help us track down the problem faster.
-->

## Setup

### Versions

- **Rust:** 1.68.0 (2c8cc3432 2023-03-06)
- **Diesel:** 2.0.0
- **Database:** Postgres 
- **Operating System** MacOS arm64

### Feature Flags

- **diesel:**

## Problem Description

I get an error while trying to install the CLI (as described on the setup guide at [this link](https://diesel.rs/guides/getting-started.html)). 

### What are you trying to accomplish?

To setup diesel, to install the CLI tool.

### What is the expected output?

A success message?

### What is the actual output?

```
cargo install diesel_cli --no-default-features --features postgres
    Updating crates.io index
  Installing diesel_cli v2.0.1
   Compiling proc-macro2 v1.0.52
   Compiling unicode-ident v1.0.8
   Compiling quote v1.0.24
   Compiling syn v1.0.109
   Compiling autocfg v1.1.0
   Compiling serde_derive v1.0.155
   Compiling serde v1.0.155
   Compiling version_check v0.9.4
   Compiling memchr v2.5.0
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling libc v0.2.140
   Compiling num-traits v0.2.15
   Compiling indexmap v1.9.2
   Compiling tinyvec_macros v0.1.1
   Compiling pq-sys v0.4.7
   Compiling bitflags v1.3.2
   Compiling core-foundation-sys v0.8.3
   Compiling tinyvec v1.6.0
   Compiling num-integer v0.1.45
   Compiling hashbrown v0.12.3
   Compiling os_str_bytes v6.4.1
   Compiling clap_lex v0.2.4
   Compiling atty v0.2.14
   Compiling aho-corasick v0.7.20
   Compiling unicode-bidi v0.3.11
   Compiling unicode-normalization v0.1.22
   Compiling termcolor v1.2.0
   Compiling regex-syntax v0.6.28
   Compiling itoa v1.0.6
   Compiling byteorder v1.4.3
   Compiling textwrap v0.16.0
   Compiling overload v0.1.1
   Compiling percent-encoding v2.2.0
   Compiling strsim v0.10.0
   Compiling nu-ansi-term v0.46.0
   Compiling clap v3.2.23
   Compiling form_urlencoded v1.1.0
   Compiling idna v0.3.0
   Compiling iana-time-zone v0.1.53
   Compiling diffy v0.3.0
   Compiling regex v1.7.1
   Compiling chrono v0.4.24
   Compiling clap_complete v3.2.5
   Compiling url v2.3.1
   Compiling diesel_derives v2.0.1
error[E0277]: the trait bound `FieldAttr: ToTokens` is not satisfied
   --> /Users/harry/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel_derives-2.0.1/src/attrs.rs:143:18
    |
143 | impl Spanned for FieldAttr {
    |                  ^^^^^^^^^ the trait `ToTokens` is not implemented for `FieldAttr`
    |
    = help: the following other types implement trait `ToTokens`:
              &'a T
              &'a mut T
              Abi
              Abstract
              AndAnd
              AndEq
              AngleBracketedGenericArguments
              Arm
            and 312 others
    = note: required for `FieldAttr` to implement `quote::spanned::private::Sealed`
note: required by a bound in `quote::spanned::Spanned`
   --> /Users/harry/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-1.0.24/src/spanned.rs:6:20
    |
6   | pub trait Spanned: private::Sealed {
    |                    ^^^^^^^^^^^^^^^ required by this bound in `Spanned`

error[E0277]: the trait bound `StructAttr: ToTokens` is not satisfied
   --> /Users/harry/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel_derives-2.0.1/src/attrs.rs:242:18
    |
242 | impl Spanned for StructAttr {
    |                  ^^^^^^^^^^ the trait `ToTokens` is not implemented for `StructAttr`
    |
    = help: the following other types implement trait `ToTokens`:
              &'a T
              &'a mut T
              Abi
              Abstract
              AndAnd
              AndEq
              AngleBracketedGenericArguments
              Arm
            and 312 others
    = note: required for `StructAttr` to implement `quote::spanned::private::Sealed`
note: required by a bound in `quote::spanned::Spanned`
   --> /Users/harry/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-1.0.24/src/spanned.rs:6:20
    |
6   | pub trait Spanned: private::Sealed {
    |                    ^^^^^^^^^^^^^^^ required by this bound in `Spanned`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `diesel_derives` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile `diesel_cli v2.0.1`, intermediate artifacts can be found at `/var/folders/wx/y49q6sc950v5mhfvqkrc09100000gn/T/cargo-installYNdmN4`
```

### Are you seeing any additional errors?

No

### Steps to reproduce

The steps that are on the website. 

## Checklist

- [X] 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.
<!--
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:
I'm getting the same thing trying to install `diesel`

**Versions**
- **Rust:** 1.68.0 (2c8cc3432 2023-03-06)
- **Diesel:** 2.0.3
- **Database:** MySQL
- **Operating System:** Windows 11

Looks to be caused by a Quote update https://github.com/dtolnay/quote
```
cargo update -p quote --precise 1.0.23
```

This works in the meantime, in case people are currently blocked.
I tried forking the repo and changing the version in `diesel_derives` and `migrations_macros` to `1.0.23` with no luck. I still get the error while installing the CLI. These crates are the only two with a direct dependency on the `quote` crate. `diesel_derives` actually uses version `1.0.9` so why is it even being affected?

<https://github.com/diesel-rs/diesel/blob/25afffb6f0d1537a496ffbc1842102aba7936dce/diesel_derives/Cargo.toml#L15> <https://github.com/diesel-rs/diesel/blob/25afffb6f0d1537a496ffbc1842102aba7936dce/diesel_migrations/migrations_macros/Cargo.toml#L11>

### Versions

- **Rust**: 1.67.0 (fc594f156 2023-01-24) (overridden by `rust-toolchain`)
- **Diesel**: `master` branch
- **Database**: N/A
- **Operating System**: Fedora Silverblue (inside and outside Toolbox container)
Hey it's HonbraDev! I believe it's because by default cargo allows and installs the latest patch version (^X.X.X) as it's not supposed to be breaking, there's a way to set explicit versions (`=X.X.X`)  

It's not recommended to explicitly mark dependencies because other projects depending on diesel will also be forced to use the same version if I remember correctly.
Oh hey, you replied while I was editing my reply.

I was making a temporary solution for myself because I'm currently high on caffeine (it's currently 1 AM) and desperately want to build something.  Here's the edit I was just about to post:

> I don't know how, I don't know why, but the above sommand somehow fixed it when I ran it in the repo root. Someone please tell me I'm not crazy.
+1
> ```
> cargo update -p quote --precise 1.0.23
> ```
> 
> This works in the meantime, in case people are currently blocked.

For me it still fails. It seems still using the version 1.0.25 of quote  :
note: required by a bound in `quote::spanned::Spanned`
   --> /home/randrade/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-1.0.25/src/spanned.rs:6:20


Sorry, I am new to rust. Is there some way to force it to use the quote 1.0.23 instead ?
> > ```
> > cargo update -p quote --precise 1.0.23
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > This works in the meantime, in case people are currently blocked.
> 
> For me it still fails. It seems still using the version 1.0.25 of quote : note: required by a bound in `quote::spanned::Spanned` --> /home/randrade/.cargo/registry/src/github.com-1ecc6299db9ec823/quote-1.0.25/src/spanned.rs:6:20
> 
> Sorry, I am new to rust. Is there some way to force it to use the quote 1.0.23 instead ?

There is a way, but it's less good.  You can point to the commit that matches the version tag like this in your root Cargo.toml.

```toml
[patch.crates-io]
quote = { git = 'https://github.com/dtolnay/quote', rev="550af67" }
```

If there was a branch that represented the version, we could have pointed at that instead.
I see that in `diesel_derives` deps it has `quote = "1.0.9"` still. Don't know how could this happen. Set `quote` to `1.0.23` is working for me though but this seems just a temporary fix, isn't it?
This is happening due to a breaking change in quote. It seems like diesel accidentally depends on an API they consider as not public. See https://github.com/dtolnay/quote/issues/241 for details.
I will try to publish a patch release fixing this issues soon.
In the mean time you can use the following workarounds:

For installing diesel_cli: `cargo install diesel_cli --locked`
For projects depending on diesel add the following line to your `Cargo.toml`: `quote = "=1.0.23"`.

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index aec4ffcc5504..056a38f177d0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -341,8 +341,8 @@ jobs:
 
       - name: Remove potential newer clippy.toml from dependencies
         run: |
-          cargo update
-          cargo fetch
+          cargo +stable update
+          cargo +stable fetch
           find ~/.cargo/registry -iname "*clippy.toml" -delete
 
       - name: Run clippy
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5f827404d3aa..acf0b28d1d7c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,12 @@ Increasing the minimal supported Rust version will always be coupled at least wi
   on the difference between your database and the provided `schema.rs` file
 * Add a `ON CONFLICT (...) DO UPDATE ... [WHERE ...]` conditional clause support for PostgreSQL.
 
+## [diesel_derives 2.0.2] 2023-03-13 
+
+## Fixed 
+
+* Fixing the fallout of a breaking change from `quote` by not using their internal API
+
 ## [2.0.2] 2022-10-11
 
 ### Fixed
@@ -1989,3 +1995,4 @@ queries or set `PIPES_AS_CONCAT` manually.
 [2.0.0]: https://github.com/diesel-rs/diesel/compare/v.1.4.0...v2.0.0
 [2.0.1]: https://github.com/diesel-rs/diesel/compare/v.2.0.0...v2.0.1
 [2.0.2]: https://github.com/diesel-rs/diesel/compare/v.2.0.1...v2.0.2
+[diesel_derives 2.0.2]: https://github.com/diesel-rs/diesel/compare/v.2.0.2...diesel_derives_v2.0.2
diff --git a/diesel/src/insertable.rs b/diesel/src/insertable.rs
index e3f90cc1dbfc..4747dce5f9c6 100644
--- a/diesel/src/insertable.rs
+++ b/diesel/src/insertable.rs
@@ -147,6 +147,7 @@ impl<T> QueryId for DefaultableColumnInsertValue<T> {
     const HAS_STATIC_QUERY_ID: bool = false;
 }
 
+#[allow(clippy::derivable_impls)] // that's not supported on rust 1.65
 impl<T> Default for DefaultableColumnInsertValue<T> {
     fn default() -> Self {
         DefaultableColumnInsertValue::Default
diff --git a/diesel_cli/src/print_schema.rs b/diesel_cli/src/print_schema.rs
index d02ca00afd61..6f40c72c0ac9 100644
--- a/diesel_cli/src/print_schema.rs
+++ b/diesel_cli/src/print_schema.rs
@@ -20,6 +20,7 @@ pub enum Filtering {
     None,
 }
 
+#[allow(clippy::derivable_impls)] // that's not supported on rust 1.65
 impl Default for Filtering {
     fn default() -> Self {
         Filtering::None
@@ -49,6 +50,7 @@ pub enum ColumnSorting {
     Name,
 }
 
+#[allow(clippy::derivable_impls)] // that's not supported on rust 1.65
 impl Default for ColumnSorting {
     fn default() -> Self {
         ColumnSorting::OrdinalPosition
@@ -62,6 +64,7 @@ pub enum DocConfig {
     NoDocComments,
 }
 
+#[allow(clippy::derivable_impls)] // that's not supported on rust 1.65
 impl Default for DocConfig {
     fn default() -> Self {
         DocConfig::NoDocComments
diff --git a/diesel_derives/Cargo.toml b/diesel_derives/Cargo.toml
index 1ed48aa864ac..4408693e2516 100644
--- a/diesel_derives/Cargo.toml
+++ b/diesel_derives/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "diesel_derives"
-version = "2.0.1"
+version = "2.0.2"
 license = "MIT OR Apache-2.0"
 description = "You should not use this crate directly, it is internal to Diesel."
 documentation = "https://diesel.rs/guides/"
diff --git a/diesel_derives/src/attrs.rs b/diesel_derives/src/attrs.rs
index 45599cf2e727..8dc5d88567b7 100644
--- a/diesel_derives/src/attrs.rs
+++ b/diesel_derives/src/attrs.rs
@@ -2,11 +2,11 @@ use std::fmt::{Display, Formatter};
 
 use proc_macro2::{Span, TokenStream};
 use proc_macro_error::ResultExt;
-use quote::spanned::Spanned;
 use quote::ToTokens;
 use syn::parse::discouraged::Speculative;
 use syn::parse::{Parse, ParseStream, Parser, Result};
 use syn::punctuated::Punctuated;
+use syn::spanned::Spanned;
 use syn::token::Comma;
 use syn::{Attribute, Ident, LitBool, LitStr, Path, Type, TypePath};
 
@@ -153,7 +153,7 @@ impl Parse for FieldAttr {
 }
 
 impl Spanned for FieldAttr {
-    fn __span(&self) -> Span {
+    fn span(&self) -> Span {
         match self {
             FieldAttr::Embed(ident)
             | FieldAttr::ColumnName(ident, _)
@@ -257,7 +257,7 @@ impl Parse for StructAttr {
 }
 
 impl Spanned for StructAttr {
-    fn __span(&self) -> Span {
+    fn span(&self) -> Span {
         match self {
             StructAttr::Aggregate(ident)
             | StructAttr::NotSized(ident)
@@ -280,8 +280,6 @@ pub fn parse_attributes<T>(attrs: &[Attribute]) -> Vec<AttributeSpanWrapper<T>>
 where
     T: Parse + ParseDeprecated + Spanned,
 {
-    use syn::spanned::Spanned;
-
     attrs
         .iter()
         .flat_map(|attr| {
diff --git a/diesel_migrations/migrations_internals/src/lib.rs b/diesel_migrations/migrations_internals/src/lib.rs
index 6ab5e98cb108..a75195797d50 100644
--- a/diesel_migrations/migrations_internals/src/lib.rs
+++ b/diesel_migrations/migrations_internals/src/lib.rs
@@ -85,7 +85,7 @@ fn file_names(path: &Path) -> Result<Vec<OsString>, std::io::Error> {
 pub fn migrations_directories(
     path: &'_ Path,
 ) -> Result<impl Iterator<Item = Result<DirEntry, std::io::Error>> + '_, std::io::Error> {
-    Ok(path.read_dir()?.into_iter().filter_map(|entry_res| {
+    Ok(path.read_dir()?.filter_map(|entry_res| {
         entry_res
             .and_then(|entry| {
                 Ok(
diff --git a/rust-toolchain b/rust-toolchain
index 65ee0959841f..ee2f4ca91304 100644
--- a/rust-toolchain
+++ b/rust-toolchain
@@ -1,1 +1,1 @@
-1.67.0
+1.68.0


Test patch:
diff --git a/diesel_tests/tests/perf_details.rs b/diesel_tests/tests/perf_details.rs
index 7c8cbdd595cf..0975dd0cd81e 100644
--- a/diesel_tests/tests/perf_details.rs
+++ b/diesel_tests/tests/perf_details.rs
@@ -16,6 +16,7 @@ fn complex_queries_with_no_data_have_no_size() {
 }
 
 #[test]
+#[allow(clippy::size_of_ref)] // clippy is wrong here these tests fail otherwise
 fn queries_with_data_are_no_bigger_than_their_variable_data() {
     assert_eq!(
         mem::size_of_val(&"Sean"),