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

temporary with significant Drop can be early dropped #12739

Open
madser123 opened this issue Apr 30, 2024 · 0 comments
Open

temporary with significant Drop can be early dropped #12739

madser123 opened this issue Apr 30, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@madser123
Copy link

Summary

Originally submitted for Rocket, as i thought it was the macro.

Lint Name

clippy::significant-drop-tightening

Reproducer

I tried this code:

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

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

/// Rocket application:
#[get("/some/route")] <-- This macro invokes the lint
pub fn route(conn: hipster::DBPool) {
    conn.run(//do stuff...);
}

The macro generates this code, which shouldn't warn, as mentioned here

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);

I saw this happen:

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> {
   |

I expected to see this happen: Nothing

Version

rustc 1.77.2 (25ef9e3d8 2024-04-09)
binary: rustc
commit-hash: 25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
commit-date: 2024-04-09
host: x86_64-unknown-linux-gnu
release: 1.77.2
LLVM version: 17.0.6

Additional Labels

No response

@madser123 madser123 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

1 participant