-
Notifications
You must be signed in to change notification settings - Fork 1.7k
lint String::as_str() #874
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
Comments
I am giving a shot to this but I am lost at making sure the lint is not applied to higher-order functions. Is there a standard way to check if we are inside a closure in some higher order function or I need to make up one? |
If the function is directly called (match on MethodCall with ident + 0th argument type), you can be quite sure it was called. Perhaps add a macro check for good measure. |
What's the status of this? |
Feel free to work on it if you want to. (If someone has claimed an issue and not shown activity for months just feel free to claim it yourself) |
I was stuck on it and then had no time to try again. Feel free to work on it. It is outdated now, but this is what I had https://github.com/mseri/rust-clippy/commits/string_as_str (I was not able to distinguish being inside a higher order function or not, I did not push the few attempts I made) |
I think it should be possible to just check if the method is immediately called instead of checking if it's inside a higher-order function. I'll implement it. |
I think this lint should still trigger on something like |
I just realized that How do I deal with this case? |
I'd generalize this as |
Using
my_string.as_str()
is noisy and adds no value in comparison to&my_string
. This lint should not apply to using it in a.map(_)
or some other higher-order stuff, just calling the function directly.The text was updated successfully, but these errors were encountered: