Skip to content

Conversation

vdbe
Copy link

@vdbe vdbe commented May 23, 2025

Example of lint for HostHooks

$ RUSTFLAGS="-Zmacro-backtrace" cargo clippy
...
warning: temporary with significant `Drop` can be early dropped
   --> /.../libnss-0.9.0/src/host.rs:139:25
    |
109 |   macro_rules! libnss_host_hooks {
    |   ------------------------------ in this expansion of `libnss_host_hooks!`
...
138 |               extern "C" fn [<_nss_ $mod_ident _sethostent>]() -> c_int {
    |  _______________________________________________________________________-
139 | |                 let mut iter: MutexGuard<Iterator<Host>> = [<HOST_ $mod_ident _ITERATOR>].lock().unwrap();
    | |                         ^^^^
140 | |                 let status = match(<super::$hooks_ident as HostHooks>::get_all_entries()) {
141 | |                     Response::Success(entries) => iter.open(entries),
...   |
144 | |                 status as c_int
145 | |             }
    | |_____________- temporary `iter` is currently being dropped at the end of its contained scope
    |
   ::: src/lib.rs:14:1
    |
14  |   libnss_host_hooks!(custom_hosts, CustomHosts);
    |   --------------------------------------------- in this macro invocation
    |
    = 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)]`

warning: temporary with significant `Drop` can be early dropped
   --> /.../libnss-0.9.0/src/host.rs:156:25
    |
109 |   macro_rules! libnss_host_hooks {
    |   ------------------------------ in this expansion of `libnss_host_hooks!`
...
155 |                                                                     errnop: *mut c_int) -> c_int {
    |  ________________________________________________________________________________________________-
156 | |                 let mut iter: MutexGuard<Iterator<Host>> = [<HOST_ $mod_ident _ITERATOR>].lock().unwrap();
    | |                         ^^^^
157 | |                 let code: c_int = iter.next().to_c(result, buf, buflen, errnop) as c_int;
158 | |                 if code == NssStatus::TryAgain as c_int {
...   |
161 | |                 return code;
162 | |             }
    | |_____________- temporary `iter` is currently being dropped at the end of its contained scope
    |
   ::: src/lib.rs:14:1
    |
14  |   libnss_host_hooks!(custom_hosts, CustomHosts);
    |   --------------------------------------------- in this macro invocation
    |
    = 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
...

Example of lint for `HostHooks`
````
$ RUSTFLAGS="-Zmacro-backtrace" cargo clippy
...
warning: temporary with significant `Drop` can be early dropped
   --> /.../libnss-0.9.0/src/host.rs:139:25
    |
109 |   macro_rules! libnss_host_hooks {
    |   ------------------------------ in this expansion of `libnss_host_hooks!`
...
138 |               extern "C" fn [<_nss_ $mod_ident _sethostent>]() -> c_int {
    |  _______________________________________________________________________-
139 | |                 let mut iter: MutexGuard<Iterator<Host>> = [<HOST_ $mod_ident _ITERATOR>].lock().unwrap();
    | |                         ^^^^
140 | |                 let status = match(<super::$hooks_ident as HostHooks>::get_all_entries()) {
141 | |                     Response::Success(entries) => iter.open(entries),
...   |
144 | |                 status as c_int
145 | |             }
    | |_____________- temporary `iter` is currently being dropped at the end of its contained scope
    |
   ::: src/lib.rs:14:1
    |
14  |   libnss_host_hooks!(custom_hosts, CustomHosts);
    |   --------------------------------------------- in this macro invocation
    |
    = 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)]`

warning: temporary with significant `Drop` can be early dropped
   --> /.../libnss-0.9.0/src/host.rs:156:25
    |
109 |   macro_rules! libnss_host_hooks {
    |   ------------------------------ in this expansion of `libnss_host_hooks!`
...
155 |                                                                     errnop: *mut c_int) -> c_int {
    |  ________________________________________________________________________________________________-
156 | |                 let mut iter: MutexGuard<Iterator<Host>> = [<HOST_ $mod_ident _ITERATOR>].lock().unwrap();
    | |                         ^^^^
157 | |                 let code: c_int = iter.next().to_c(result, buf, buflen, errnop) as c_int;
158 | |                 if code == NssStatus::TryAgain as c_int {
...   |
161 | |                 return code;
162 | |             }
    | |_____________- temporary `iter` is currently being dropped at the end of its contained scope
    |
   ::: src/lib.rs:14:1
    |
14  |   libnss_host_hooks!(custom_hosts, CustomHosts);
    |   --------------------------------------------- in this macro invocation
    |
    = 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
...
````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant