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/CHANGELOG.md b/CHANGELOG.md
index 870da02e6fac..c42597aee20f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,12 @@ Increasing the minimal supported Rust version will always be coupled at least wi
 
 ## Unreleased 
 
+## [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.3] 2023-01-24
 
 ## Fixed
@@ -1982,3 +1988,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_derives/Cargo.toml b/diesel_derives/Cargo.toml
index 258f21d2a921..2c43f636d77a 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 9da55c748dea..753682155027 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::{parenthesized, Attribute, Ident, LitBool, LitStr, Path, Type, TypePath};
 
@@ -141,7 +141,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, _)
@@ -240,7 +240,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)
@@ -262,8 +262,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| {


Test patch:
diff --git a/diesel_tests/tests/select.rs b/diesel_tests/tests/select.rs
index ad0e3683fac1..309e86d4508a 100644
--- a/diesel_tests/tests/select.rs
+++ b/diesel_tests/tests/select.rs
@@ -1,4 +1,5 @@
 use super::schema::*;
+#[cfg(not(feature = "mysql"))]
 use crate::schema_dsl::*;
 use diesel::*;
 
@@ -214,7 +215,8 @@ table! {
     }
 }
 
-#[cfg(not(feature = "sqlite"))]
+// the test is somehow broken on some mariadb versions
+#[cfg(not(any(feature = "sqlite", feature = "mysql")))]
 #[test]
 fn select_for_update_locks_selected_rows() {
     use self::users_select_for_update::dsl::*;