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

Add support for windows-style paths in ignore patterns #3633

Merged
merged 4 commits into from
Jun 29, 2019

Conversation

calebcartwright
Copy link
Member

@calebcartwright calebcartwright commented Jun 18, 2019

Fixes #3537

I also checked on my windows machine and confirmed this works

src/ignore_path.rs Outdated Show resolved Hide resolved
src/ignore_path.rs Outdated Show resolved Hide resolved
ignore_builder.add_line(None, ignore_path.to_str().unwrap())?;
let ignore_line = ignore_path.to_str().unwrap();
if cfg!(windows) {
ignore_builder.add_line(None, &ignore_line.replace("\\", "/"))?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like one downside of only doing this on Windows is that projects utilizing ignore with these windows style paths could end up with different experiences with rustfmt on different platforms.

A cargo fmt -- --check could pass for a developer/CI engine on Windows but fail for a developer/CI engine on Mac, Linux, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this is a real concern. However, it seems that the #[path = "..."] attribute does not support Windows-style paths in other environments as well:

// error: couldn't read foo\bar.rs: No such file or directory (os error 2)
#[path = "foo\\bar.rs"]
mod foobar;

I will just take this behavior an excuse for rustfmt that it's ok not to support the Windows-style path outside of Windows 😉

While you are this, could you add some documentation in Configurations.md about this, please?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will just take this behavior an excuse for rustfmt that it's ok not to support the Windows-style path outside of Windows 😉

In that case, do you think that Windows-style paths should not be supported in rustfmt's ignore setting as well? Using regular / style paths in rustfmt ignore config works fine for me on both my Ubuntu and Windows machines, so I'd personally prefer to just use the / style that works on all platforms.

Instead of making this code change, could we just update the Configurations information to instruct users to use / paths for ignore setting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you mention it, I think that sounds more reasonable.

Instead of making this code change, could we just update the Configurations information to instruct users to use / paths for ignore setting?

Would you mind updating this PR with this direction? Sorry for multiple requests for changes, this should be the last one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries!

@topecongiro
Copy link
Contributor

Thank you!

@topecongiro topecongiro merged commit 1ee51a4 into rust-lang:master Jun 29, 2019
@calebcartwright calebcartwright deleted the windows-ignore-paths branch June 29, 2019 14:34
@topecongiro topecongiro added this to the 1.3.1 milestone Jun 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows paths in ignore setting no longer work
3 participants