Skip to content

Stdin build silently ignores non-inline mod items #65601

Closed
@mystor

Description

@mystor

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions