Auto merge of #51278 - EPashkin:fix_mod_with_multilevel_paths_on_windows, r=nikomatsakis

Fix processing mod with multi-level path on Windows

Fix error in [rustfmt](https://github.com/rust-lang-nursery/rustfmt/issues/1754) because libsyntax can not handle `mod` with multilevel path on Windows.

Alternative is do almost same in https://github.com/rust-lang/rust/blob/master/src/libstd/sys/windows/fs.rs#L717 to allow work on paths with different separators, Ex. "\\\\?\\c:\\windows/temp"
This commit is contained in:
bors 2018-06-19 02:17:52 +00:00
commit ed39523406
4 changed files with 62 additions and 1 deletions

View file

@ -6128,7 +6128,19 @@ impl<'a> Parser<'a> {
}
pub fn submod_path_from_attr(attrs: &[Attribute], dir_path: &Path) -> Option<PathBuf> {
attr::first_attr_value_str_by_name(attrs, "path").map(|d| dir_path.join(&d.as_str()))
if let Some(s) = attr::first_attr_value_str_by_name(attrs, "path") {
let s = s.as_str();
// On windows, the base path might have the form
// `\\?\foo\bar` in which case it does not tolerate
// mixed `/` and `\` separators, so canonicalize
// `/` to `\`.
#[cfg(windows)]
let s = s.replace("/", "\\");
Some(dir_path.join(s))
} else {
None
}
}
/// Returns either a path to a module, or .