Skip to content

Commit 474f7a9

Browse files
committed
Auto merge of #40620 - laumann:slash-in-diagnostics-path, r=BurntSushi
Replace hardcoded forward slash with path::MAIN_SEPARATOR Fixes #40149
2 parents 5c94997 + b376386 commit 474f7a9

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

src/libstd/sys_common/backtrace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use io;
1919
use libc;
2020
use str;
2121
use sync::atomic::{self, Ordering};
22-
use path::Path;
22+
use path::{self, Path};
2323
use sys::mutex::Mutex;
2424
use ptr;
2525

@@ -262,7 +262,7 @@ fn output_fileline(w: &mut Write, file: &[u8], line: libc::c_int,
262262
if let Ok(cwd) = env::current_dir() {
263263
if let Ok(stripped) = file_path.strip_prefix(&cwd) {
264264
if let Some(s) = stripped.to_str() {
265-
write!(w, " at ./{}:{}", s, line)?;
265+
write!(w, " at .{}{}:{}", path::MAIN_SEPARATOR, s, line)?;
266266
already_printed = true;
267267
}
268268
}

src/libsyntax/parse/parser.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use util::ThinVec;
5959

6060
use std::collections::HashSet;
6161
use std::{cmp, mem, slice};
62-
use std::path::{Path, PathBuf};
62+
use std::path::{self, Path, PathBuf};
6363

6464
bitflags! {
6565
flags Restrictions: u8 {
@@ -5146,7 +5146,7 @@ impl<'a> Parser<'a> {
51465146
pub fn default_submod_path(id: ast::Ident, dir_path: &Path, codemap: &CodeMap) -> ModulePath {
51475147
let mod_name = id.to_string();
51485148
let default_path_str = format!("{}.rs", mod_name);
5149-
let secondary_path_str = format!("{}/mod.rs", mod_name);
5149+
let secondary_path_str = format!("{}{}mod.rs", mod_name, path::MAIN_SEPARATOR);
51505150
let default_path = dir_path.join(&default_path_str);
51515151
let secondary_path = dir_path.join(&secondary_path_str);
51525152
let default_exists = codemap.file_exists(&default_path);
@@ -5224,8 +5224,9 @@ impl<'a> Parser<'a> {
52245224
};
52255225
err.span_note(id_sp,
52265226
&format!("maybe move this module `{0}` to its own directory \
5227-
via `{0}/mod.rs`",
5228-
this_module));
5227+
via `{0}{1}mod.rs`",
5228+
this_module,
5229+
path::MAIN_SEPARATOR));
52295230
if paths.path_exists {
52305231
err.span_note(id_sp,
52315232
&format!("... or maybe `use` the module `{}` instead \

src/test/parse-fail/mod_file_not_exist.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-windows
12+
1113
// compile-flags: -Z parse-only
1214

1315
mod not_a_real_file; //~ ERROR file not found for module `not_a_real_file`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-gnu
12+
// ignore-android
13+
// ignore-bitrig
14+
// ignore-macos
15+
// ignore-dragonfly
16+
// ignore-freebsd
17+
// ignore-haiku
18+
// ignore-ios
19+
// ignore-linux
20+
// ignore-netbsd
21+
// ignore-openbsd
22+
// ignore-solaris
23+
// ignore-emscripten
24+
25+
// compile-flags: -Z parse-only
26+
27+
mod not_a_real_file; //~ ERROR file not found for module `not_a_real_file`
28+
//~^ HELP name the file either not_a_real_file.rs or not_a_real_file\mod.rs inside the directory
29+
30+
fn main() {
31+
assert_eq!(mod_file_aux::bar(), 10);
32+
}

0 commit comments

Comments
 (0)