-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Lint suggestion: Path construction using format! #8812
Comments
Welcome to clippy 👋 Yes, the basic idea is the same. You have to find a format macro where the output is used to create a |
Hey @jplatte, I've started in the review for the lint and found several examples of paths like The main reason I could think of would be the support for |
I find it less readable and for portability it could also be better to use the platform default separator. The For absolute paths like the example you showed I agree that there isn't much of a point as those are already almost certainly platform-specific. Maybe the lint shouldn't fire if the path is known to be absolute? |
IDK, it seems like |
Raw paths on windows |
@Jarcho I'm still not 100% sure I understand all the edge cases correctly. Could you maybe explain why it makes a difference if the path is rooted? There is another thing, which I'm unsure about. In the PR there is a check to allow cases, where the format is only used for the filename extension like this I feel like I'm lacking some knowledge, since I haven't worked with paths too much in this regard 😅 |
Paths on windows can take a few forms. As a partial list you have:
There's a few others as well, but they aren't important here. For the first three forms slashes and backslashes are treated the same way. Verbatim paths are sent to the filesystem driver without being interpreted. In general, this results in only backslashes working as a separator with slashes being interpreted as part of the component's name. This results in |
The PR #8833 is a good start for this lint. It was just closed due to inactivity. |
What it does
Suggest to create
PathBuf
s usingPath::join
(or maybePathBuf::push
in some circumstances) instead of string formatting.Lint Name
path_format
Category
suspicious
Example
could be written as
The text was updated successfully, but these errors were encountered: