zero-to-production icon indicating copy to clipboard operation
zero-to-production copied to clipboard

Known issue with clippy and tracing in chapter 3

Open suryapandian opened this issue 4 years ago • 1 comments

In chapter 3, we create a function to insert subscribers

pub async fn insert_subscriber(pool: &PgPool, form: &FormData) -> Result<(), sqlx::Error> {
    sqlx::query!(
        r#"
    INSERT INTO subscriptions (id, email, name, subscribed_at)
    VALUES ($1, $2, $3, $4)
"#,
        Uuid::new_v4(),
        form.email,
        form.name,
        Utc::now()
    )
    .execute(pool)
    .await
    .map_err(|e| {
        tracing::error!("Failed to execute query: {:?}", e);
        e
    })?;
    Ok(())
}

However, clippy throws an error when we try to lint this. The error thrown by clippy is

error: used binding `_expr` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
  --> src/routes/subscriptions.rs:28:9
   |
28 |         Uuid::new_v4(),
   |         ^^^^
   |
   = note: `-D clippy::used-underscore-binding` implied by `-D warnings`

This is not an issue in the code. To avoid this error add #[allow(clippy::async_yields_async)] before the function.

The issue apparently is from https://github.com/tokio-rs/tracing

For more detail on the issue: https://github.com/tokio-rs/tracing/issues/1450

suryapandian avatar Aug 04 '21 17:08 suryapandian

I am posting this issue here for the reference of the readers. If you are trying out the examples in the book and have come across a similar error. please add #[allow(clippy::async_yields_async)] in a line above insert_subscriber

suryapandian avatar Aug 04 '21 17:08 suryapandian