-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 lint recommends invalid code #3071
Comments
I may have a simpler example of the same issue: fn main() {
let msg = (|| return "Hello, world!")();
println!("{}", msg);
} |
One more clippy recommendation seems invalid, see: rust-lang/rust-clippy#3071 (comment)
I've just run into the issue with the following code sample: Playground |
Sadly this also matches the function signature of foo.map(|x| f(x)) with foo.map(f) even when |
I have run into another error with this lint: Clippy is suggesting for me to replace a call with a function that is not exported into my scope.
img is a Clippy's suggestion is not possible to implement without depending on an additional crate. |
Here's another example: type Constructor = unsafe extern "C" fn() -> *mut Foo;
// magically create an instance of "Constructor" (in my case I'm dynamically loading it)
let constructor: libloading::Symbol<Constructor> = ...;
let result: *mut Foo = std::panic::catch_unwind(|| constructor()).map_err(...)?; Clippy recommends passing "constructor" directly into // this does not compile
let result = std::panic::catch_unwind(*constructor).map_err(...)?; (I have since realized that it's useless to |
…lippy#3071 Signed-off-by: mwrock <matt@mattwrock.com>
I'm not sure that's the same issue, @snoyberg. Or, at least I'm not able to reproduce it with that code. When I run clippy on that in the playground, I get a
But implementing that suggestion works just fine. Am I missing something? |
I created a toy example of an issue I encountered today: |
Thanks for the example, but writing |
Apologies, it was apparently I that was missing something. I must have used improper syntax (likely appending a |
Just encountered the exact same issue, just with a bit different types. I have a function that takes a check on fn check_string_helper<F>(validate: F) where F: Fn(Cow<str>) -> bool {
let value: Cow<str> = Cow::Owned("foo".into());
if validate(value) {
println!("OK");
} else {
println!("Wrong");
}
} And I try pass it a validation function that takes generic pub fn validate_regex<S: AsRef<str>>(s: S) -> bool {
Regex::new(s.as_ref()).is_ok()
} Passing closure |
My case looks like the following: I'm using Yew and I'm having the same warning when writing: let set_current_tab_callback = self
.link
.callback(|next_tab: usize| Msg::SetActive(next_tab)); The warning thats being printed is:
And If I follow the warning, then I get:
|
Seems known as per rust-lang/rust-clippy#3071.
Workaround for: rust-lang/rust-clippy#3071
Workaround for: rust-lang/rust-clippy#3071
Workaround for: rust-lang/rust-clippy#3071
I've found an issue in the redundant_closure lint where it'll suggest a closure which won't actually compile.
I think what's happening is
clippy
sees a closure that just calls a function, and because the input/output types match up it thinks the closure is redundant. However, when you get rid of the closure it fails because of lifetimes/HKT.And
rustc
gives the following compilation error:(playground)
This may also be a simpler example for #1439.
The text was updated successfully, but these errors were encountered: