rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

`redundant_closure_for_method_calls` auto-fix used private module

Open danieljharvey opened this issue 8 months ago • 1 comments

Summary

Hello! Clippy fix mode used a private module directly in place of it's public re-export, and recommended I open an issue.

Here is the original output:


The following errors were reported:
error[E0603]: module `auth` is private
  --> crates/server/src/handlers/foo.rs:74:85
   |
74 |         ServerMode::Cloud { .. } => user_session.and_then(super::super::middleware::auth::types::UserSession::foo).map(f),
   |                                                                                     ^^^^ private module
   |
note: the module `auth` is defined here
  --> crates/server/src/middleware/mod.rs:1:1
   |
 1 | mod auth;
   | ^^^^^^^^^
help: consider importing this struct through its public re-export instead
   |
74 -         ServerMode::Cloud { .. } => user_session.and_then(super::super::middleware::auth::types::UserSession::foo).map(f),
74 +         ServerMode::Cloud { .. } => user_session.and_then(crate::UserSession::foo).map(f),
   |

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.
Original diagnostics will follow.

warning: redundant closure
  --> crates/server/src/handlers/foo.rs:74:59
   |
74 |         ServerMode::Cloud { .. } => user_session.and_then(|us| us.foo()).map(f),
   |                                                           ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `super::super::middleware::auth::types::UserSession::foo`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#redundant_closure_for_method_calls
   = note: `-W clippy::redundant-closure-for-method-calls` implied by `-W clippy::pedantic`
   = help: to override `-W clippy::pedantic` add `#[allow(clippy::redundant_closure_for_method_calls)]`

Reproducer

Code:

<code>

Current output:

Desired output:

Version

rustc 1.94.0 (4a4ef493e 2026-03-02)
binary: rustc
commit-hash: 4a4ef493e3a1488c6e321570238084b38948f6db
commit-date: 2026-03-02
host: aarch64-apple-darwin
release: 1.94.0
LLVM version: 21.1.8

Additional Labels

No response

danieljharvey avatar Mar 19 '26 10:03 danieljharvey

@rustbot claim

swjng avatar Apr 28 '26 06:04 swjng