-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Lint on inline modules module
if there also exists a file at path ./module.rs
or ./module/mod.rs
#139685
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
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
module
if there also exists a file at path ./module.rs
or ./module/mod.rs
@Manishearth , @fmease - Given the scope of harm this issue could result in, wouldn't it be preferrable that this kind of code be treated as a compiler error, instead of just a warning? |
No. This does not appear to be nearly as serious and you make it out to be, and generally stuff that can legitimately happen as transitional states should be warned on, not errored on. Furthermore, an error would be a breaking change, rasing the burden of justification for this significantly. Note that the compiler does not add lints often either. |
Uh oh!
There was an error while loading. Please reload this page.
Note
The updated description was written by @fmease.
Given the following code in a file called
root.rs
:and a file structure of the form:
or
it could be beneficial if rustc could feature a lint that informs the user that the files
module.rs
andmodule/mod.rs
respectively are not considered since they are essentially shadowed by the inline module.In real code bases, this situation might arise when the user has updated a file module declaration
mod module;
tomod module { /*…*/ }
while forgetting to copy over the contents of the former module file or forgetting to delete it.Since the proposed lint would be relatively expensive to run due to the extra filesystem-related syscalls per inline module, it should maybe be allow-by-default only?
The lint should take into account
#[path]
(indeed, it's intentionally allowed on inline modules, cc #13156).Original outdated issue description
In Chapter 7 of rustbook, Section 7.2 ->
Modules Cheat Sheet
->Declaring modules:
, the preference of the compiler for module declarations is clearly defined. However, when I tried experimenting with all the three ways, namely:1 of 3) Inline, within curly brackets that replace the semicolon following mod garden
2 of 3) In the file src/garden.rs
3 of 3) In the file src/garden/mod.rs
I observed inconsistency in the compiler's behaviour when using multiple ways.
To check how these three ways might conflict with each other, I first tried
1 of 3)
and2 of 3)
above. The behaviour of the compiler was to silently (as in, no error or warning) prefer1 of 3)
over2 of 3)
, effectively ignoring2 of 3)
. So, the compilation was successful.However, when I tried
2 of 3)
and3 of 3)
, the compiler threw error[E0761], complaining about the module being found in multiple places.Code (
1 of 3)
and2 of 3)
)Code (
2 of 3)
and3 of 3)
)Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: