Skip to content

Commit 515446c

Browse files
committed
Make error message clearer about creating new module
#69492
1 parent ee50590 commit 515446c

File tree

9 files changed

+12
-17
lines changed

9 files changed

+12
-17
lines changed

src/librustc_parse/parser/diagnostics.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_span::{MultiSpan, Span, SpanSnippetError, DUMMY_SP};
1818

1919
use log::{debug, trace};
2020
use std::mem;
21+
use std::path::PathBuf;
2122

2223
const TURBOFISH: &'static str = "use `::<...>` instead of `<...>` to specify type arguments";
2324

@@ -42,9 +43,7 @@ pub(super) fn dummy_arg(ident: Ident) -> Param {
4243
pub enum Error {
4344
FileNotFoundForModule {
4445
mod_name: String,
45-
default_path: String,
46-
secondary_path: String,
47-
dir_path: String,
46+
default_path: PathBuf,
4847
},
4948
DuplicatePaths {
5049
mod_name: String,
@@ -60,8 +59,6 @@ impl Error {
6059
Error::FileNotFoundForModule {
6160
ref mod_name,
6261
ref default_path,
63-
ref secondary_path,
64-
ref dir_path,
6562
} => {
6663
let mut err = struct_span_err!(
6764
handler,
@@ -71,8 +68,8 @@ impl Error {
7168
mod_name,
7269
);
7370
err.help(&format!(
74-
"name the file either {} or {} inside the directory \"{}\"",
75-
default_path, secondary_path, dir_path,
71+
"to create the module `{}`, create file \"{}\"",
72+
mod_name, default_path.display(),
7673
));
7774
err
7875
}

src/librustc_parse/parser/module.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ impl<'a> Parser<'a> {
236236
}),
237237
(false, false) => Err(Error::FileNotFoundForModule {
238238
mod_name: mod_name.clone(),
239-
default_path: default_path_str,
240-
secondary_path: secondary_path_str,
241-
dir_path: dir_path.display().to_string(),
239+
default_path,
242240
}),
243241
(true, true) => Err(Error::DuplicatePaths {
244242
mod_name: mod_name.clone(),

src/test/ui/error-codes/E0583.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0583]: file not found for module `module_that_doesnt_exist`
44
LL | mod module_that_doesnt_exist;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= help: name the file either module_that_doesnt_exist.rs or module_that_doesnt_exist/mod.rs inside the directory "$DIR"
7+
= help: to create the module `module_that_doesnt_exist`, create file "$DIR/module_that_doesnt_exist.rs"
88

99
error: aborting due to previous error
1010

src/test/ui/invalid-module-declaration/invalid-module-declaration.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0583]: file not found for module `baz`
44
LL | pub mod baz;
55
| ^^^
66
|
7-
= help: name the file either bar/baz.rs or bar/baz/mod.rs inside the directory "$DIR/auxiliary/foo"
7+
= help: to create the module `baz`, create file "$DIR/auxiliary/foo/bar/baz.rs"
88

99
error: aborting due to previous error
1010

src/test/ui/missing_non_modrs_mod/missing_non_modrs_mod.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0583]: file not found for module `missing`
44
LL | mod missing;
55
| ^^^^^^^
66
|
7-
= help: name the file either foo/missing.rs or foo/missing/mod.rs inside the directory "$DIR"
7+
= help: to create the module `missing`, create file "$DIR/foo/missing.rs"
88

99
error: aborting due to previous error
1010

src/test/ui/missing_non_modrs_mod/missing_non_modrs_mod_inline.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0583]: file not found for module `missing`
44
LL | mod missing;
55
| ^^^^^^^
66
|
7-
= help: name the file either missing.rs or missing/mod.rs inside the directory "$DIR/foo_inline/inline"
7+
= help: to create the module `missing`, create file "$DIR/foo_inline/inline/missing.rs"
88

99
error: aborting due to previous error
1010

src/test/ui/parser/mod_file_not_exist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ignore-windows
22

33
mod not_a_real_file; //~ ERROR file not found for module `not_a_real_file`
4-
//~^ HELP name the file either not_a_real_file.rs or not_a_real_file/mod.rs inside the directory
4+
//~^ HELP to create the module `not_a_real_file`, create file "
55

66
fn main() {
77
assert_eq!(mod_file_aux::bar(), 10);

src/test/ui/parser/mod_file_not_exist.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0583]: file not found for module `not_a_real_file`
44
LL | mod not_a_real_file;
55
| ^^^^^^^^^^^^^^^
66
|
7-
= help: name the file either not_a_real_file.rs or not_a_real_file/mod.rs inside the directory "$DIR"
7+
= help: to create the module `not_a_real_file`, create file "$DIR/not_a_real_file.rs"
88

99
error: aborting due to previous error
1010

src/test/ui/parser/mod_file_not_exist_windows.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0583]: file not found for module `not_a_real_file`
44
LL | mod not_a_real_file;
55
| ^^^^^^^^^^^^^^^
66
|
7-
= help: name the file either not_a_real_file.rs or not_a_real_file/mod.rs inside the directory "$DIR"
7+
= help: to create the module `not_a_real_file`, create file "$DIR/not_a_real_file.rs"
88

99
error: aborting due to previous error
1010

0 commit comments

Comments
 (0)