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

Stdin build silently ignores non-inline mod items #65601

Closed
mystor opened this issue Oct 19, 2019 · 2 comments · Fixed by #114093
Closed

Stdin build silently ignores non-inline mod items #65601

mystor opened this issue Oct 19, 2019 · 2 comments · Fixed by #114093
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mystor
Copy link
Contributor

mystor commented Oct 19, 2019

Missing external modules don't report a build error when a crate is built from stdin.

Expected: When parsing an external submodule from stdin, a compiler error (or warning) is emitted noting that external submodules are not supported for stdio crates.

Actual: No diagnostics are emitted and an empty submodule is implicitly inserted.

Generally if a mod statement references a file which does not exist, an E0583 compile error will be emitted. However, when building a crate from stdin, no relative filesystem is present, yet no compile errors are emitted, even with explicit #[path="x"] attributes. Instead they are implicitly substituted with empty inline modules.

# Surprising stdin cases
$ echo 'mod x;' | rustc --crate-type=rlib -  # Builds
$ echo '#[path="/y"] mod x;' | rustc --crate-type=rlib -  # Builds

# Working file case
$ echo 'mod x;' > y.rs
$ rustc --crate-type=rlib y.rs
error[E0583]: file not found for module `x`
 --> y.rs:1:5
[...]

I'm not super familiar with rustc, so this might not be handy, but I'm guessing this is caused by the Parser::recurse_into_file_modules flag being unset when parsing from a string rather than a file (rustc_interface::passes::parse -> syntax::parse::parse_crate_from_source_str -> syntax::parse::new_parser_from_source_str), leading to a dummy module being inserted rather than trying to access the filesystem or emit an error during the parse.

@Alexendoo Alexendoo added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 20, 2019
@Enselic
Copy link
Member

Enselic commented Jul 25, 2023

This was fixed in nightly-2020-03-20, probably by #69838

I don't think this is worth adding a regression test for this TBH, so I think we should simply close this issue. It remains fixed in current stable (1.71).

$ echo 'mod x;' | rustc +nightly-2020-03-19 --crate-type=rlib -
$ echo 'mod x;' | rustc +nightly-2020-03-20 --crate-type=rlib -
error[E0583]: file not found for module `x`
 --> <anon>:1:1
  |
1 | mod x;
  | ^^^^^^
  |
  = help: to create the module `x`, create file "x.rs"

error: aborting due to previous error

For more information about this error, try `rustc --explain E0583`.
$ echo 'mod x;' | rustc +stable --crate-type=rlib -
error[E0583]: file not found for module `x`
 --> <anon>:1:1
  |
1 | mod x;
  | ^^^^^^
  |
  = help: to create the module `x`, create file "x.rs" or "x/mod.rs"

error: aborting due to previous error

For more information about this error, try `rustc --explain E0583`.

@Enselic
Copy link
Member

Enselic commented Jul 26, 2023

On a second thought the right way to close this issue is probably by writing a regression test after all. Otherwise the bug can re-appear. I was being too lazy.

Edit: Fix: #114093

@rustbot label E-needs-test

@rustbot rustbot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jul 26, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 31, 2023
…Simulacrum

Add regression test for `echo 'mod unknown;' | rustc -`

Closes rust-lang#65601

The bug is fixed since long ago, probably by rust-lang#69838 (see rust-lang#65601 (comment) for more details).
Add a regression test so we can close the issue.
@bors bors closed this as completed in 61c55e3 Aug 7, 2023
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Aug 8, 2023
Add regression test for `echo 'mod unknown;' | rustc -`

Closes #65601

The bug is fixed since long ago, probably by #69838 (see rust-lang/rust#65601 (comment) for more details).
Add a regression test so we can close the issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants