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

Disallow including and thereby deep-cloning the same module several times #71

Open
fmease opened this issue Feb 15, 2021 · 0 comments
Open
Labels
T-enhancement Type: Enhancement

Comments

@fmease
Copy link
Owner

fmease commented Feb 15, 2021

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.

@fmease fmease added A-diagnostics Area: Diagnostics T-enhancement Type: Enhancement and removed A-diagnostics Area: Diagnostics labels Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-enhancement Type: Enhancement
Projects
None yet
Development

No branches or pull requests

1 participant