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

Invalid "ignoring emit path because multiple .s files were produced" message #122509

Closed
pacak opened this issue Mar 14, 2024 · 0 comments · Fixed by #122842
Closed

Invalid "ignoring emit path because multiple .s files were produced" message #122509

pacak opened this issue Mar 14, 2024 · 0 comments · Fixed by #122842
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pacak
Copy link
Contributor

pacak commented Mar 14, 2024

Code

#[inline(never)]
pub fn alpha() -> usize {
    println!("alpha");
    12
}

#[inline(never)]
pub fn beta() -> usize {
    println!("beta");
    12
}

Current output

$ rustc lib.rs --crate-type lib --emit asm -C codegen-units=2
warning: ignoring emit path because multiple .s files were produced

warning: 1 warning emitted

Desired output

blank

Rationale and extra context

Error originates from somewhere around here and implies that I passed --emit foo=some_name, while in fact I only passed --emit foo

if crate_output.outputs.contains_key(&output_type) {
// 2) Multiple codegen units, with `--emit foo=some_name`. We have
// no good solution for this case, so warn the user.
sess.dcx().emit_warn(errors::IgnoringEmitPath { extension });
} else if crate_output.single_output_file.is_some() {

Other cases

No response

Rust Version

rustc 1.78.0-nightly (1a648b397 2024-02-11)
binary: rustc
commit-hash: 1a648b397dedc98ada3dd3360f6d661ec2436c56
commit-date: 2024-02-11
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6

Anything else?

No response

@pacak pacak added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 14, 2024
@jieyouxu jieyouxu added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 15, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 25, 2024
…ister

Don't emit an error about failing to produce a file with a specific name if user never gave an explicit name

Fixes rust-lang#122509

You can ask `rustc` to produce some intermediate results with `--emit foo`, this operation comes in two flavors: `--emit asm` and `--emit asm=foo.s`. First one produces one or more `.s` files without any name guarantees, second one renames it into `foo.s`. Second version only works when compiler produces a single file - for asm files this means using a single compilation unit for example.

In case compilation produced more than a single file `rustc` runs following check to emit some warnings:

```rust
            if crate_output.outputs.contains_key(&output_type) {
                // 2) Multiple codegen units, with `--emit foo=some_name`. We have
                //    no good solution for this case, so warn the user.
                sess.dcx().emit_warn(errors::IgnoringEmitPath { extension });
            } else if crate_output.single_output_file.is_some() {
                // 3) Multiple codegen units, with `-o some_name`. We have
                //    no good solution for this case, so warn the user.
                sess.dcx().emit_warn(errors::IgnoringOutput { extension });
            } else {
                // 4) Multiple codegen units, but no explicit name. We
                //    just leave the `foo.0.x` files in place.
                // (We don't have to do any work in this case.)
            }
```

Comment in the final `else` branch implies that if user didn't ask for a specific name - there's no need to emit warnings. However because of the internal representation of `crate_output.outputs` - this doesn't work as expected: if user asked to produce an asm file without giving it an implicit name it will contain `Some(None)`.

To fix the problem new code actually checks if user gave an explicit name. I think this was an original intentional behavior, at least comments imply that.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 25, 2024
Rollup merge of rust-lang#122842 - pacak:explicit_name, r=michaelwoerister

Don't emit an error about failing to produce a file with a specific name if user never gave an explicit name

Fixes rust-lang#122509

You can ask `rustc` to produce some intermediate results with `--emit foo`, this operation comes in two flavors: `--emit asm` and `--emit asm=foo.s`. First one produces one or more `.s` files without any name guarantees, second one renames it into `foo.s`. Second version only works when compiler produces a single file - for asm files this means using a single compilation unit for example.

In case compilation produced more than a single file `rustc` runs following check to emit some warnings:

```rust
            if crate_output.outputs.contains_key(&output_type) {
                // 2) Multiple codegen units, with `--emit foo=some_name`. We have
                //    no good solution for this case, so warn the user.
                sess.dcx().emit_warn(errors::IgnoringEmitPath { extension });
            } else if crate_output.single_output_file.is_some() {
                // 3) Multiple codegen units, with `-o some_name`. We have
                //    no good solution for this case, so warn the user.
                sess.dcx().emit_warn(errors::IgnoringOutput { extension });
            } else {
                // 4) Multiple codegen units, but no explicit name. We
                //    just leave the `foo.0.x` files in place.
                // (We don't have to do any work in this case.)
            }
```

Comment in the final `else` branch implies that if user didn't ask for a specific name - there's no need to emit warnings. However because of the internal representation of `crate_output.outputs` - this doesn't work as expected: if user asked to produce an asm file without giving it an implicit name it will contain `Some(None)`.

To fix the problem new code actually checks if user gave an explicit name. I think this was an original intentional behavior, at least comments imply that.
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 25, 2024
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants