Skip to content

Modules with path don't formated on Windows #1754

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

Closed
EPashkin opened this issue Jun 26, 2017 · 2 comments
Closed

Modules with path don't formated on Windows #1754

EPashkin opened this issue Jun 26, 2017 · 2 comments
Labels
bug Panic, non-idempotency, invalid code, etc. os-windows p-medium

Comments

@EPashkin
Copy link

EPashkin commented Jun 26, 2017

This crate with build script, that use file from src

>cargo new fmt_bug
>cd fmt_bug
>cat build.rs
#[path = "src/consts.rs"]
mod consts;

fn main() {
    println!("VERSION:{}", consts::VERSION);
}

>cat src/consts.rs
pub const VERSION: &'static str = "1dd0028";

produce this error on Windows + MSys2:

D:\eap\rust\0_test\fmt_bug>cargo fmt
error: couldn't read "\\\\?\\D:\\eap\\rust\\0_test\\fmt_bug\\src/consts.rs": Syntax error in file name, folder name, or volume label.
(os error 123)
 --> \\?\D:\eap\rust\0_test\fmt_bug\build.rs:2:5
  |
2 | mod consts;
  |     ^^^^^^

thread 'main' panicked at 'Box<Any>', src\libsyntax\parse\mod.rs:207
stack backtrace:
   0: mingw_set_invalid_parameter_handler
   1: mingw_set_invalid_parameter_handler
   2: mingw_set_invalid_parameter_handler
   3: mingw_set_invalid_parameter_handler
   4: mingw_set_invalid_parameter_handler
   5: mingw_set_invalid_parameter_handler
   6: mingw_set_invalid_parameter_handler
   7: mingw_set_invalid_parameter_handler
   8: mingw_set_invalid_parameter_handler
   9: mingw_set_invalid_parameter_handler
  10: mingw_set_invalid_parameter_handler
  11: mingw_set_invalid_parameter_handler
  12: rustfmt_nightly::parse_input
  13: rustfmt_nightly::run
  14: rustfmt::execute
  15: rustfmt::main
  16: mingw_set_invalid_parameter_handler
  17: mingw_set_invalid_parameter_handler
  18: _tmainCRTStartup
  19: mainCRTStartup
  20: mingw_set_invalid_parameter_handler

Versions:

>cargo -Vv
cargo 0.21.0-nightly (e53e2f8d5 2017-06-17)
release: 0.21.0
commit-hash: e53e2f8d5b7f7751dd478fff68c1dbe7247cb096
commit-date: 2017-06-17

>rustc -Vv
rustc 1.20.0-nightly (445077963 2017-06-20)
binary: rustc
commit-hash: 445077963c55297ef1e196a3525723090fe80b22
commit-date: 2017-06-20
host: x86_64-pc-windows-gnu
release: 1.20.0-nightly
LLVM version: 4.0

>rustfmt -Vv
0.1.5-nightly ( )

EDIT: translated error message from Russian.

@nrc nrc added bug Panic, non-idempotency, invalid code, etc. p-medium labels Jun 27, 2017
@nrc nrc added the os-windows label Sep 18, 2017
@nrc nrc added this to the impl period milestone Sep 18, 2017
@nrc nrc removed this from the impl period milestone Jan 11, 2018
@EPashkin
Copy link
Author

@nrc Bug in rust repo, can be fixed in https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/parser.rs#L6018:

    pub fn submod_path_from_attr(attrs: &[Attribute], dir_path: &Path) -> Option<PathBuf> {
        if let Some(s) = attr::first_attr_value_str_by_name(attrs, "path") {
            let s = s.as_str();
            #[cfg(windows)]
            let s = s.replace("/", "\\");
	    Some(dir_path.join(s))
	} else {
            None
	}
    }

but actual problem lies somewhere in std::os::windows::fs, Ex. std::path::Path::canonicalize not works only in 4th case with error Err(Os { code: 123, kind: Other, message: "The filename, directory name, or volume label syntax is incorrect." }):

        assert_eq!(Path::new("c:\\windows\\temp").canonicalize().unwrap().as_os_str(), "\\\\?\\C:\\Windows\\Temp");
        assert_eq!(Path::new("c:\\windows/temp").canonicalize().unwrap().as_os_str(), "\\\\?\\C:\\Windows\\Temp");
        assert_eq!(Path::new("\\\\?\\c:\\windows\\temp").canonicalize().unwrap().as_os_str(), "\\\\?\\C:\\Windows\\Temp");
        assert!(Path::new("\\\\?\\c:\\windows/temp").canonicalize().is_err());

bors added a commit to rust-lang/rust that referenced this issue Jun 19, 2018
…ows, r=nikomatsakis

Fix processing mod with multi-level path on Windows

Fix error in [rustfmt](rust-lang/rustfmt#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"
@EPashkin
Copy link
Author

EPashkin commented Jul 7, 2018

In rustfmt 0.8.2-nightly (5e59925 2018-07-02) issue fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. os-windows p-medium
Projects
None yet
Development

No branches or pull requests

2 participants