Skip to content

Commit

Permalink
Make error message clearer about creating new module
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Mar 1, 2020
1 parent ee50590 commit 515446c
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 17 deletions.
11 changes: 4 additions & 7 deletions src/librustc_parse/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use rustc_span::{MultiSpan, Span, SpanSnippetError, DUMMY_SP};

use log::{debug, trace};
use std::mem;
use std::path::PathBuf;

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

Expand All @@ -42,9 +43,7 @@ pub(super) fn dummy_arg(ident: Ident) -> Param {
pub enum Error {
FileNotFoundForModule {
mod_name: String,
default_path: String,
secondary_path: String,
dir_path: String,
default_path: PathBuf,
},
DuplicatePaths {
mod_name: String,
Expand All @@ -60,8 +59,6 @@ impl Error {
Error::FileNotFoundForModule {
ref mod_name,
ref default_path,
ref secondary_path,
ref dir_path,
} => {
let mut err = struct_span_err!(
handler,
Expand All @@ -71,8 +68,8 @@ impl Error {
mod_name,
);
err.help(&format!(
"name the file either {} or {} inside the directory \"{}\"",
default_path, secondary_path, dir_path,
"to create the module `{}`, create file \"{}\"",
mod_name, default_path.display(),
));
err
}
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_parse/parser/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,7 @@ impl<'a> Parser<'a> {
}),
(false, false) => Err(Error::FileNotFoundForModule {
mod_name: mod_name.clone(),
default_path: default_path_str,
secondary_path: secondary_path_str,
dir_path: dir_path.display().to_string(),
default_path,
}),
(true, true) => Err(Error::DuplicatePaths {
mod_name: mod_name.clone(),
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0583.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0583]: file not found for module `module_that_doesnt_exist`
LL | mod module_that_doesnt_exist;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: name the file either module_that_doesnt_exist.rs or module_that_doesnt_exist/mod.rs inside the directory "$DIR"
= help: to create the module `module_that_doesnt_exist`, create file "$DIR/module_that_doesnt_exist.rs"

error: aborting due to previous error

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

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0583]: file not found for module `missing`
LL | mod missing;
| ^^^^^^^
|
= help: name the file either foo/missing.rs or foo/missing/mod.rs inside the directory "$DIR"
= help: to create the module `missing`, create file "$DIR/foo/missing.rs"

error: aborting due to previous error

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

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/mod_file_not_exist.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ignore-windows

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

fn main() {
assert_eq!(mod_file_aux::bar(), 10);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/mod_file_not_exist.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0583]: file not found for module `not_a_real_file`
LL | mod not_a_real_file;
| ^^^^^^^^^^^^^^^
|
= help: name the file either not_a_real_file.rs or not_a_real_file/mod.rs inside the directory "$DIR"
= help: to create the module `not_a_real_file`, create file "$DIR/not_a_real_file.rs"

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/mod_file_not_exist_windows.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0583]: file not found for module `not_a_real_file`
LL | mod not_a_real_file;
| ^^^^^^^^^^^^^^^
|
= help: name the file either not_a_real_file.rs or not_a_real_file/mod.rs inside the directory "$DIR"
= help: to create the module `not_a_real_file`, create file "$DIR/not_a_real_file.rs"

error: aborting due to previous error

Expand Down

0 comments on commit 515446c

Please sign in to comment.