Skip to content

Commit 1685264

Browse files
authored
Rollup merge of rust-lang#69520 - kornelski:e69492, r=cramertj
Make error message clearer about creating new module This is a partial improvement for rust-lang#69492
2 parents 2443eb4 + 8de1ec9 commit 1685264

10 files changed

+18
-33
lines changed

src/librustc_parse/parser/diagnostics.rs

+7-19
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: &str = "use `::<...>` instead of `<...>` to specify type arguments";
2324

@@ -40,29 +41,15 @@ pub(super) fn dummy_arg(ident: Ident) -> Param {
4041
}
4142

4243
pub enum Error {
43-
FileNotFoundForModule {
44-
mod_name: String,
45-
default_path: String,
46-
secondary_path: String,
47-
dir_path: String,
48-
},
49-
DuplicatePaths {
50-
mod_name: String,
51-
default_path: String,
52-
secondary_path: String,
53-
},
44+
FileNotFoundForModule { mod_name: String, default_path: PathBuf },
45+
DuplicatePaths { mod_name: String, default_path: String, secondary_path: String },
5446
UselessDocComment,
5547
}
5648

5749
impl Error {
5850
fn span_err(self, sp: impl Into<MultiSpan>, handler: &Handler) -> DiagnosticBuilder<'_> {
5951
match self {
60-
Error::FileNotFoundForModule {
61-
ref mod_name,
62-
ref default_path,
63-
ref secondary_path,
64-
ref dir_path,
65-
} => {
52+
Error::FileNotFoundForModule { ref mod_name, ref default_path } => {
6653
let mut err = struct_span_err!(
6754
handler,
6855
sp,
@@ -71,8 +58,9 @@ impl Error {
7158
mod_name,
7259
);
7360
err.help(&format!(
74-
"name the file either {} or {} inside the directory \"{}\"",
75-
default_path, secondary_path, dir_path,
61+
"to create the module `{}`, create file \"{}\"",
62+
mod_name,
63+
default_path.display(),
7664
));
7765
err
7866
}

src/librustc_parse/parser/module.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,9 @@ impl<'a> Parser<'a> {
234234
path: secondary_path,
235235
directory_ownership: DirectoryOwnership::Owned { relative: None },
236236
}),
237-
(false, false) => Err(Error::FileNotFoundForModule {
238-
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(),
242-
}),
237+
(false, false) => {
238+
Err(Error::FileNotFoundForModule { mod_name: mod_name.clone(), default_path })
239+
}
243240
(true, true) => Err(Error::DuplicatePaths {
244241
mod_name: mod_name.clone(),
245242
default_path: default_path_str,

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.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// only-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_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)