External module declarations are basically textual includes (C-like) where the additions are packed into a new module.
A problem arises when a user writes two or more external module declarations referencing the same file tree which is possible
with the attribute @location (corresponding to Rust's #[path]): The subdeclarations are added twice (or more) to the crate resulting in declarations which are named identical and have an identical definition except that they are considered separate declarations (no name collisions happen because they are namespaced). This is not unsound but it is counter-intuitive to newcomers who might classify external module declarations as some kind of import mechanism which only analyzes the referenced module once. This does indeed occur: People new to Rust often get confounded by this.
As I was writing this issue, I came to realize that we probably should not simply warn if a file path is used several times in @locations inside the whole crate but we should disallow it. There is no good reason for doing this. Let's not fall prey to the
infamous warning culture (critiqued by Jon Blow).
Example:
module left =
@(location "path/to/thing")
module whatever
module right =
@(location "path/to/thing")
module whatsoever
Above should trigger an error looking something like this:
error[EXXX]: file path referenced several times across external module declarations
--> ${DIRECTORY}/main.lushui:L:C
|
L | @(location "path/to/thing")
| ^^^^^^^^^^^^^^^ used multiple times
|
--> ${DIRECTORY}/main.lushui:M:K
|
M | @(location "path/to/thing")
| ^^^^^^^^^^^^^^^ used multiple times
|
note: something explaining the difference between the concept of imports and ext. mod. decls.
error: aborting due to previous error
Alternatively, once we implement crates #14, remove the @location attribute.
External module declarations are basically textual includes (C-like) where the additions are packed into a new module. A problem arises when a user writes two or more external module declarations referencing the same file tree which is possible with the attribute
@location
(corresponding to Rust's#[path]
): The subdeclarations are added twice (or more) to the crate resulting in declarations which are named identical and have an identical definition except that they are considered separate declarations (no name collisions happen because they are namespaced). This is not unsound but it is counter-intuitive to newcomers who might classify external module declarations as some kind of import mechanism which only analyzes the referenced module once. This does indeed occur: People new to Rust often get confounded by this.As I was writing this issue, I came to realize that we probably should not simply warn if a file path is used several times in
@location
s inside the whole crate but we should disallow it. There is no good reason for doing this. Let's not fall prey to the infamous warning culture (critiqued by Jon Blow).Example:
Above should trigger an error looking something like this:
Alternatively, once we implement crates #14, remove the
@location
attribute.