rust-lang/rust · error · Exception

A Rust source path is required with the `test` argument

Error message

A Rust source path is required with the `test` argument

What it means

Raised by TestEnvironment.debug() when the user passes --test but not --rust-src. The --test path is used to construct a source-map and a zxdb attach script that references a Rust source tree; without --rust-src those paths cannot be built. It is a usage error caught early at fuchsia-test-runner.py:1050-1053.

Source

Thrown at src/ci/docker/scripts/fuchsia-test-runner.py:1051

                f"--symbol-path={self.rust_dir}/lib/rustlib/{self.target}/lib",
            ]

        # Add rust source if it's available
        rust_src_map = None
        if args.rust_src is not None:
            # This matches the remapped prefix used by compiletest. There's no
            # clear way that we can determine this, so it's hard coded.
            rust_src_map = f"/rustc/FAKE_PREFIX={args.rust_src}"

        # Add fuchsia source if it's available
        fuchsia_src_map = None
        if args.fuchsia_src is not None:
            fuchsia_src_map = f"./../..={args.fuchsia_src}"

        # Load debug symbols for the test binary and automatically attach
        if args.test is not None:
            if args.rust_src is None:
                raise Exception(
                    "A Rust source path is required with the `test` argument"
                )

            test_name = os.path.splitext(os.path.basename(args.test))[0]

            build_dir = os.path.join(
                args.rust_src,
                "fuchsia-build",
                self.host_arch_triple(),
            )
            test_dir = os.path.join(
                build_dir,
                "test",
                os.path.dirname(args.test),
                test_name,
            )

            # The fake-test-src-base directory maps to the suite directory

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Add --rust-src pointing at your Rust source checkout: `fuchsia-test-runner.py debug --rust-src /path/to/rust --test ui/box/new.rs`.
  2. If you do not need source-level debugging, drop --test and pass raw zxdb args instead.
  3. Set up an alias/shell wrapper that always supplies --rust-src alongside --test.

Example fix

// before
$ fuchsia-test-runner.py debug --test ui/box/new.rs
# Exception: A Rust source path is required with the `test` argument

// after
$ fuchsia-test-runner.py debug --rust-src ~/src/rust --test ui/box/new.rs
Defensive patterns

Strategy: validation

Validate before calling

if getattr(args, "test", None) is not None and not getattr(args, "rust_src", None):
    raise SystemExit("--rust-src is required when --test is passed to `debug`.")
# safe to call debug()
env.debug(args)

Type guard

def debug_args_are_valid(args) -> bool:
    return not (args.test is not None and args.rust_src is None)

Try / catch

try:
    test_env.debug(args)
except Exception as e:
    if "Rust source path is required" in str(e):
        sys.exit("Re-run with --rust-src <path> when using --test.")
    raise

Prevention

When it happens

Trigger: Invoking `fuchsia-test-runner.py debug --test ui/box/new.rs` (or any --test value) without also passing `--rust-src <path>`. The check is `if args.test is not None and args.rust_src is None`.

Common situations: Forgetting the --rust-src flag; assuming the runner can infer the Rust source location from the environment; copy-pasting a debug command from docs that omitted the flag.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/2e094454d67d0111. Report an issue: GitHub.