Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy lint: temporary with significant Drop can be early dropped #2780

Closed
4 tasks done
madser123 opened this issue Apr 22, 2024 · 1 comment
Closed
4 tasks done

Clippy lint: temporary with significant Drop can be early dropped #2780

madser123 opened this issue Apr 22, 2024 · 1 comment
Labels
no bug The reported bug was confirmed nonexistent

Comments

@madser123
Copy link

madser123 commented Apr 22, 2024

Rocket Version

0.5.0

Operating System

Ubuntu 22.04

Rust Toolchain Version

rustc 1.77.2 (25ef9e3d8 2024-04-09)

What happened?

Whenever i use my Database-pool in a route, clippy warns me of a temporary with significant 'Drop' can be early dropped.

Test Case

/// Library "hipster":
use rocket_sync_db_pools::{database, diesel};

#[database("hipster")]
pub struct DBPool(diesel::PgConnection);

/// Rocket application:
#[get("/some/route")]
pub fn route(conn: hipster::DBPool) {
    conn.run(//do stuff...);
}

Log Output

warning: temporary with significant `Drop` can be early dropped
  --> bin/hipster-backend/src/web/api/mod.rs:69:35
   |
68 | #[get("/validate_credentials/<credentials>")]
   | --------------------------------------------- temporary `__rocket_conn` is currently being dropped at the end of its contained scope
69 | pub async fn validate_credentials(conn: hipster::DBPool, credentials: &str) -> Json<Validation> {
   |                                   ^^^^
   |
   = note: this might lead to unnecessary resource contention
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_tightening
   = note: `-W clippy::significant-drop-tightening` implied by `-W clippy::nursery`
   = help: to override `-W clippy::nursery` add `#[allow(clippy::significant_drop_tightening)]`
help: merge the temporary construction with its single usage
   |
69 ~ pub async fn validate_credentials(conn: 
70 ~ let Json = hipster.;::DBPool, credentials: &str) -> Json<Validation> {
   |
help: remove separated single usage
   |
69 - pub async fn validate_credentials(conn: hipster::DBPool, credentials: &str) -> Json<Validation> {
69 + pub async fn validate_credentials(conn: hipster::DBPool, credentials: &str) -> <Validation> {
   |

Additional Context

The warning is one out of many - It warns with every route i use my pool on.

System Checks

  • My bug report relates to functionality.
  • I have tested against the latest Rocket release or a recent git commit.
  • I have tested against the latest stable rustc toolchain.
  • I was unable to find this issue previously reported.
@madser123 madser123 added the triage A bug report being investigated label Apr 22, 2024
@SergioBenitez SergioBenitez removed the triage A bug report being investigated label Apr 23, 2024
@SergioBenitez
Copy link
Member

I don't believe the lint is correct in this case. This is likely why it's a "nursery" lint.

The generated code looks like:

                let __rocket__db: DBPool = match <DBPool as ::rocket::request::FromRequest>::from_request( __req,) .await
                {
                    ::rocket::outcome::Outcome::Success(__v) => __v,
                    ::rocket::outcome::Outcome::Forward(__e) => {
                        return ::rocket::outcome::Outcome::Forward((__data, __e));
                    }
                    ::rocket::outcome::Outcome::Error((__c, __e)) => {
                        return ::rocket::outcome::Outcome::Error(__c);
                    }
                };

                let ___responder = route(__rocket__db);

So the value is not being dropped at the end of the scope.

There's nothing we can do here. This is an issue with clippy.

@SergioBenitez SergioBenitez closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2024
@SergioBenitez SergioBenitez added the no bug The reported bug was confirmed nonexistent label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no bug The reported bug was confirmed nonexistent
Projects
None yet
Development

No branches or pull requests

2 participants