Skip to content

parser: modulesubpath defined with path macro needs to replace pathseperator to the default pathseperator #48400

@yenwel

Description

@yenwel

When trying out rustfmt on windows I got an error on my code that compiles. I have defined cross platform modules as such:

#[cfg(target_os = "linux")]
#[path = "proxyimpl/linux.rs"]
pub mod proxyimpl;
#[cfg(not(target_os = "linux"))]
#[path = "proxyimpl/nonlinux.rs"]
pub mod proxyimpl;

When running rustfmt on windows I get the following error

rustfmt .\main.rs
error: couldn't read "\\\\?\\C:\\Users\\<snip>\\Source\\irondragon\\src\\gpioaccess\\proxyimpl/linux.rs": The filename, directory name, or volume label syntax is incorrect. (os error 123)
  --> \\?\C:\Users\<snip>\Source\irondragon\src\gpioaccess\mod.rs:68:9
   |
68 | pub mod proxyimpl;
   |         ^^^^^^^^^

thread 'main' panicked at 'Box<Any>', src\libsyntax\parse\mod.rs:215:29
stack backtrace:
   0: <std::sync::condvar::WaitTimeoutResult as core::fmt::Debug>::fmt
   1: <std::time::SystemTimeError as core::fmt::Display>::fmt
   2: std::panicking::Location::column
   3: std::panicking::Location::column
   4: std::panicking::rust_panic_with_hook
   5: <syntax::ext::tt::macro_rules::TokenSet as core::fmt::Debug>::fmt
   6: syntax::parse::new_parser_from_tts
   7: syntax::parse::parser::Parser::default_submod_path
   8: syntax::parse::parser::Parser::parse_item
   9: syntax::parse::parser::Parser::parse_visibility
  10: syntax::parse::parser::Parser::default_submod_path
  11: syntax::parse::parser::Parser::parse_item
  12: syntax::parse::parser::Parser::parse_visibility
  13: syntax::parse::parser::Parser::parse_crate_mod
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: <unknown>
  19: std::panicking::update_panic_count
  20: _rust_maybe_catch_panic
  21: std::rt::lang_start_internal
  22: <unknown>
  23: <unknown>
  24: BaseThreadInitThunk

Changing it to

#[cfg(target_os = "linux")]
#[path = "proxyimpl\\linux.rs"]
pub mod proxyimpl;
#[cfg(not(target_os = "linux"))]
#[path = "proxyimpl\\nonlinux.rs"]
pub mod proxyimpl;

I can run rustfmt on windows, but my travisci build (linux) fails.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions