Conversation
|
Thanks for the pull request, and welcome! You should hear from one of our reviewers after this PR gets at least 2 reviews from the community. Please see the contribution instructions for more information. |
| // in case of `Path::new("") == Path::new("")` the lint doesn't make much sense | ||
| if !(left_path_new_empty_string ^ right_path_new_empty_string) { |
There was a problem hiding this comment.
gotta love a nice XOR! 👍🏻
There was a problem hiding this comment.
usually, we try a bit to more split than the very long fn main.
Could you split this up into a few functions for the different cases in an mod main?
This way everything is organised.
Also, please add a test to ensure that macro expansions are correctly handled like in the rest of the codebase. I am not sure if the last part needs an return from the fn, I think we do.
I also suspect that there might be testcase missing when the path is coming from an const.
Co-authored-by: Gri-ffin <82527700+Gri-ffin@users.noreply.github.com>
| /// ``` | ||
| #[clippy::version = "1.100.0"] | ||
| pub PATH_COMPARISON_TO_EMPTY, | ||
| style, |
There was a problem hiding this comment.
this is also a performance improvement, suggest the performant category instead
There was a problem hiding this comment.
That is supprisingly true, rustc seens to not be able to see past this
There was a problem hiding this comment.
Yea, the reason why using Path::is_empty is faster than doing path equality in this case is because you don't have to go through doing component based equality using Path::components (which is a bit more involved than just checking the length of the path). I'm currently working on optimizing it for Unix/non-prefixed based platforms here, but regardless Path::is_empty is better to use over path == Path::new("").
Which reminds me that I should swap out the path == Path::new("") for path.is_empty() in the create_dir_all update PR I was working on
|
☔ The latest upstream changes (possibly #17644) made this pull request unmergeable. Please resolve the merge conflicts. |
|
I agree with @Gri-ffin that the lint could benefit from checking assert_eq!(Path::new("//"), "/");succeeds. You can see that in this rust playground link. Internally, they all end up triggering Technically, all the empty string variations (e.g. |
changelog: [
path_comparison_to_empty] Added a new lintpath_comparison_to_empty, which checks for comparing a path toPath::new("")orPathBuf::new()and suggests to useis_emptyfixes: #17615