Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File not found for module error #39765

Merged
merged 3 commits into from
Feb 21, 2017

Conversation

GuillaumeGomez
Copy link
Member

Fixes #39542.

r? @jonathandturner

Maybe you want to take a look @pnkfelix?

Erroneous code example:

```compile_fail,E0583
mod file_that_doesnt_exist; // error: ile not found for module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "ile not found for module"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups, thanks!

@@ -224,4 +291,5 @@ register_diagnostics! {
E0555, // malformed feature attribute, expected #![feature(...)]
E0556, // malformed feature, expected just one word
E0557, // feature has been removed
E0584, // file for module `..` found at both .. and ..
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the other newly added errors be registered as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know how to trigger this one and not enough time to investigate. Someone will do it later on if I don't myself.

Copy link
Contributor

@durka durka Feb 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error occurs for mod foo; when both foo.rs and foo/mod.rs exist. There's a test: cfail/mod_file_disambig.

fn foo() {}
```
"##,

Copy link
Contributor

@durka durka Feb 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature flags will be needed in these examples, also the cfail tests for inclusive ranges.

@GuillaumeGomez
Copy link
Member Author

@durka: I added the corresponding tests already. Take a look at the new files in compile-fail directory.

@durka
Copy link
Contributor

durka commented Feb 13, 2017

Yeah but you are missing #![feature(inclusive_range_syntax)].

@GuillaumeGomez
Copy link
Member Author

It's not needed as far as I can tell... ? At least when I test, I have no missing feature issue.

@durka
Copy link
Contributor

durka commented Feb 13, 2017 via email

@sophiajt
Copy link
Contributor

I'm cool with this change, but you probably want to ping someone on the compiler team to double-check the logic. I haven't done much with the module system, yet.

@GuillaumeGomez
Copy link
Member Author

cc @rust-lang/compiler

@@ -201,6 +201,73 @@ where appropriate is ongoing. Try using an unquoted name instead:
pub fn something() {}
```
"##,

E0583: r##"
A file wasn't found for a module import.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to call mod foo; a "module import"?
I've heard it called an "out-of-line module", but never heard "module import" except to refer to a use import of a module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you reword it then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call it a "module item" or an "out-of-line module".

fn main() {}
```

Please be sure that a file corresponding to the module really exist. So if you
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: really exists. So


Please be sure that a file corresponding to the module really exist. So if you
want to import a `file_that_doesnt_exist` module, you need to have a
`file_that_doesnt_exist.rs` file at the same level.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or file_that_doesnt_exist/mod.rs

"##,

E0585: r##"
A documentation comment which doesn't comment anything was found.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/which/that/, s/comment/document/

}
```

Documentation comments need to be used on items like functions, types,
Copy link
Contributor

@jseyfried jseyfried Feb 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/used on/followed by/, s/like/including/

mod_name: mod_name.clone(),
default_path: default_path_str,
secondary_path: secondary_path_str,
dir_path: format!("{}", dir_path.display()) }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a newline before the }),

dir_path: format!("{}", dir_path.display()) }),
(true, true) => Err(Errors::DuplicatePaths { mod_name: mod_name.clone(),
default_path: default_path_str,
secondary_path: secondary_path_str }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: block indenting is more idiomatic here.

match paths.result {
Ok(succ) => Ok(succ),
Err(err) => Err(self.span_fatal_err(id_sp, err)),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we could use map_err here instead of match.

fn main() {
let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
let x = &tmp[1...]; //~ ERROR E0586
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no trailing new newline

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

dir_path: String },
DuplicatePaths { mod_name: String, default_path: String, secondary_path: String },
UselessDocComment,
InclusiveRangeWithNoEnd,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this variant? I think it would be simpler to just emit the error directly in the relevant parsing function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to centralize the errors. Making them easier to spot and modify.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think UselessDocComment and InclusiveRangeWithNoEnd would be more appropriate as methods on the Parser, since they don't have anything to do with with the first two variants (except that they are errors during parsing).

Then, the enum could be named ModulePathError -- clearer and more precise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point isn't to group same kind of errors but to centralize them.

@GuillaumeGomez
Copy link
Member Author

@jseyfried: Is it ok for you now? ;)

```

Please be sure that a file corresponding to the module exists. If you
want to import a `file_that_doesnt_exist` module, you need to have a
Copy link
Contributor

@jseyfried jseyfried Feb 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not "import"ing here -- I would say "define", "declare", or "use" instead.

Also I would say "a module named file_that_doesnt_exist" instead of "a file_that_doesnt_exist module".


Please be sure that a file corresponding to the module exists. If you
want to import a `file_that_doesnt_exist` module, you need to have a
`file_that_doesnt_exist/mod.rs` file at the same level.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user can have file_that_doesnt_exist.rs or file_that_doesnt_exist/mod.rs -- we need to mention both options here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I would say "in the same directory" instead of "at the same level".

}
```

Documentation comments need to be followed items including functions, types,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to be followed by items**,** including
(add "by" and ",")

```

Documentation comments need to be followed items including functions, types,
modules, etc... Examples:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one "." here.

"doc comments must come before what they document, maybe a \
comment was intended with `//`?");
Errors::UselessDocComment.span_err(s.prev_span, s.diagnostic())
.emit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're not getting rid of span_fatal_err, shouldn't we use it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely!

@GuillaumeGomez
Copy link
Member Author

Updated.

Copy link
Contributor

@jseyfried jseyfried left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me modulo comments


Please be sure that a file corresponding to the module exists. If you
want to use a module named `file_that_doesnt_exist`, you need to have a
`file_that_doesnt_exist.rs` or a `file_that_doesnt_exist/mod.rs` file in the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you need to have a file_that_doesnt_exist.rs or file_that_doesnt_exist/mod.rs file in the same directory.

or: you need to have a file named file_that_doesnt_exist.rs or file_that_doesnt_exist/mod.rs in the same directory.

@@ -233,6 +233,63 @@ pub struct ModulePathError {
pub help_msg: String,
}

pub enum Errors {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit: Error would be a more idiomatic name

@GuillaumeGomez
Copy link
Member Author

Ok, I fixed the two last nits. If you find anything else, don't hesitate to r-!

@bors: r=jseyfried

@bors
Copy link
Contributor

bors commented Feb 20, 2017

📌 Commit a9f22d7 has been approved by jseyfried

InclusiveRangeWithNoEnd,
}

impl Errors {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors -> Error (won't pass travis)

Error::FileNotFoundForModule { ref mod_name,
ref default_path,
ref secondary_path,
ref dir_path } => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indent (one extra space)

@@ -955,6 +1009,9 @@ impl<'a> Parser<'a> {
pub fn span_fatal(&self, sp: Span, m: &str) -> DiagnosticBuilder<'a> {
self.sess.span_diagnostic.struct_span_fatal(sp, m)
}
pub fn span_fatal_err(&self, sp: Span, err: Errors) -> DiagnosticBuilder<'a> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here (Errors -> Error), etc.

ref default_path,
ref secondary_path,
ref dir_path } => {
let mut err = struct_span_er!(handler, sp, E0583,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

@jseyfried
Copy link
Contributor

@bors r-
I usually wait for Travis to pass before directing bors.

@GuillaumeGomez
Copy link
Member Author

@jseyfried: Outch, my string replacement failed badly... Updated.

@GuillaumeGomez
Copy link
Member Author

Tests seem ok this time so let's r+ it. Thanks @jseyfried!

@bors: r=jseyfried

@bors
Copy link
Contributor

bors commented Feb 21, 2017

📌 Commit b6818be has been approved by jseyfried

@bors
Copy link
Contributor

bors commented Feb 21, 2017

⌛ Testing commit b6818be with merge ab89a78...

@bors
Copy link
Contributor

bors commented Feb 21, 2017

💔 Test failed - status-appveyor

@alexcrichton
Copy link
Member

alexcrichton commented Feb 21, 2017 via email

@bors
Copy link
Contributor

bors commented Feb 21, 2017

⌛ Testing commit b6818be with merge 0f34b53...

bors added a commit that referenced this pull request Feb 21, 2017
…, r=jseyfried

File not found for module error

Fixes #39542.

r? @jonathandturner

Maybe you want to take a look @pnkfelix?
@bors
Copy link
Contributor

bors commented Feb 21, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: jseyfried
Pushing 0f34b53 to master...

@bors bors merged commit b6818be into rust-lang:master Feb 21, 2017
@GuillaumeGomez GuillaumeGomez deleted the file-not-found-for-module-error branch February 22, 2017 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants