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

redundant_closure_for_method_calls suggesting a private module/type #10095

Open
lyssieth opened this issue Dec 17, 2022 · 2 comments
Open

redundant_closure_for_method_calls suggesting a private module/type #10095

lyssieth opened this issue Dec 17, 2022 · 2 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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@lyssieth
Copy link

Summary

I noticed this bug while working on a project using https://github.com/lyssieth/htp/tree/lyssieth-time-support, specifically that it was trying to use a private module from that branch of htp

Lint Name

redundant_closure_for_method_calls

Reproducer

I tried this code:

// `expire` here is an Option<String> generally containing text like: `in 1 hour`, `in 50 min`, etc
let expire = match expire {
    Some(expire) => Some(htp::parse(&expire, OffsetDateTime::now_utc())?),
    None => None,
};

// this causes the false positive, since `unified` is an internal module for `htp`
// Converting the internal `htp::unified::DateTime` to a usable `time::OffsetDateTime` via the fn `as_time`
let expire = expire.and_then(|dt|dt.as_time());
// after application:
let expire = expire.and_then(htp::unified::DateTime::as_time);
// and this then causes an error.

I saw this happen:

warning: redundant closure
  --> src/main.rs:63:46
   |
63 |                 let expire = expire.and_then(|dt| dt.as_time());
   |                                              ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `htp::unified::DateTime::as_time`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
note: the lint level is defined here
  --> src/main.rs:1:9
   |
1  | #![warn(clippy::pedantic)]
   |         ^^^^^^^^^^^^^^^^
   = note: `#[warn(clippy::redundant_closure_for_method_calls)]` implied by `#[warn(clippy::pedantic)]`

I expected to see this happen:

It to not trigger, as if the lint is applied, it causes an error instead. htp::unified is a private module of htp.

Version

rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: x86_64-unknown-linux-gnu
release: 1.66.0
LLVM version: 15.0.2

Additional Labels

@rustbot label +I-suggestion-causes-error

@lyssieth lyssieth 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 Dec 17, 2022
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Dec 17, 2022
@lyssieth lyssieth changed the title redundant_closure_for_method_calls suggesting a private type redundant_closure_for_method_calls suggesting a private module/type Dec 17, 2022
@feniljain
Copy link
Contributor

I think the MRE should look something like this:

#![warn(clippy::pedantic)]

mod a {
    mod b {
        pub struct C(pub i32);

        impl C {
            pub fn get_val(&self) -> Option<i32> {
                Some(self.0)
            }
        }
    }

    pub fn get_c() -> b::C {
        b::C(0)
    }
}

fn main() {
	    let opt = Some(a::get_c());
		let _a = opt.and_then(|x| x.get_val());
}

Tho unfortunately it does not give this suggestion for me, maybe I am missing something, any ideas?

@lyssieth
Copy link
Author

I'll try to pull out a MRE from the project sometime later today or tomorrow, if one can't be figured out beforehand.

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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

3 participants