Skip to content

Rustc can't handle non-UTF-8 input paths, but only when RUST_BACKTRACE is not set #164585

Open

Description

@theemathas

I ran the following python script, which runs rustc with a non-UTF-8 input file name:

import subprocess

p = subprocess.run(["rustc", bytes([255])], check=False)
print(p)

I got the following output (the empty line is not a copy-paste error):


thread 'main' (468943) panicked at /rustc/b6eeb93c992027a03e1fd120b6652546396b142c/library/std/src/env.rs:935:51:
called `Result::unwrap()` on an `Err` value: "\xFF"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
CompletedProcess(args=['rustc', b'\xff'], returncode=101)

If I instead set RUST_BACKTRACE=1 before running the script, I get the following output (again, the empty line is not a copy-paste error. And for this one, in my terminal, the error message is bolded and has color):

error: argument 1 is not valid Unicode: "\xFF"

CompletedProcess(args=['rustc', b'\xff'], returncode=1)

Seems like whatever is trying to output the error message doesn't like it when RUST_BACKTRACE isn't set. (Also note that the returncode in the two outputs are different.)

Meta

rustc --version --verbose:

rustc 1.101.0-nightly (b6eeb93c9 2026-10-18)
binary: rustc
commit-hash: b6eeb93c992027a03e1fd120b6652546396b142c
commit-date: 2026-10-18
host: aarch64-apple-darwin
release: 1.101.0-nightly
LLVM version: 23.1.4

Activity

  1. added
    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
    A-driverArea: rustc_driver that ties everything together into the `rustc` compiler
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Oct 19, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 19, 2026
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 19, 2026
  4. theemathas commented on Oct 19, 2026

    @theemathas
    ContributorAuthor

    What on earth is this code doing? (Note the std::env::args() call.)

    pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(DiagCtxtHandle<'_>)) {
    // If the user has not explicitly overridden "RUST_BACKTRACE", then produce
    // full backtraces. When a compiler ICE happens, we want to gather
    // as much information as possible to present in the issue opened
    // by the user. Compiler developers and other rustc users can
    // opt in to less-verbose backtraces by manually setting "RUST_BACKTRACE"
    // (e.g. `RUST_BACKTRACE=1`)
    if env::var_os("RUST_BACKTRACE").is_none() {
    // HACK: this check is extremely dumb, but we don't really need it to be smarter since this should only happen in the test suite anyway.
    let ui_testing = std::env::args().any(|arg| arg == "-Zui-testing");
    if env!("CFG_RELEASE_CHANNEL") == "dev" && !ui_testing {
    panic::set_backtrace_style(panic::BacktraceStyle::Short);
    } else {
    panic::set_backtrace_style(panic::BacktraceStyle::Full);
    }
    }

  5. ChrisDenton commented on Oct 19, 2026

    @ChrisDenton
    Member

    The nature of the hack aside, the only issue is that it uses args when it should be using args_os.

  6. maxdexh commented on Oct 19, 2026

    @maxdexh
    Member

    It also doesn't support passing -Z ui-testing (or -Zui-testing=yes, or anything else that option flags should support)

  7. assigned and unassigned on Oct 19, 2026
  8. ChrisDenton commented on Oct 19, 2026

    @ChrisDenton
    Member

    It also doesn't support passing -Z ui-testing (or -Zui-testing=yes, or anything else that option flags should support)

    I'm assuming that's semi-intentional since it's an internal only flag and shouldn't be used by anyone (except the UI testing framework).

  9. maxdexh commented on Oct 19, 2026

    @maxdexh
    Member

    It shows up when you rustc -Zhelp, and it doesn't say it's internal. Is that the next problem?

    -Z                                    ui-testing=val -- emit compiler diagnostics in a form suitable for UI testing (default: no)
    

    (also notice that the =val form it shows up as literally doesn't work (and it shows up with spaces))

  10. ChrisDenton commented on Oct 19, 2026

    @ChrisDenton
    Member

    I mean the given code is specifically for the backtrace behaviour though, not ui-testing in general. The =val form should work in general since that's handled by our normal argument parsing.

  11. maxdexh commented on Oct 19, 2026

    @maxdexh
    Member

    Yeah, but that still sounds like buggy behavior, why would the backtrace format depend on how you passed the arg? ^^

  12. ChrisDenton commented on Oct 19, 2026

    @ChrisDenton
    Member

    It also depends on CFG_RELEASE_CHANNEL which is unlikely to be set by anyone who isn't building rustc from source.

    But I think your position is that the hack added in #110989 shouldn't be a hack, despite the comment claiming it's "good enough"?

  13. maxdexh commented on Oct 19, 2026

    @maxdexh
    Member

    no my claim is that this code is super weird ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UnicodeArea: UnicodeA-driverArea: rustc_driver that ties everything together into the `rustc` compilerC-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.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