Skip to content

rustc --test should not check linking when using --emit=metadata or -Z no-trans #39948

Open
@Wilfred

Description

@Wilfred

Suppose I have a library configured with panic = "abort":

$ cargo init --lib foo
$ cd foo
$ nano Cargo.toml
$ more Cargo.toml
[package]
name = "foo"
version = "0.1.0"
authors = ["Wilfred Hughes <me@wilfred.me.uk>"]

[dependencies]

[profile.dev]
panic = "abort"

I'm unable to build with with --test:

$ cargo rustc -- --test
   Compiling foo v0.1.0 (file:///home/wilfred/tmp/foo)
error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`

error: aborting due to previous error

error: Could not compile `foo`.

To learn more, run the command again with --verbose.

As discussed in rust-lang/cargo#3166 (comment) this is because the test harness needs unwinding on panic.

However, I get the same error with -Z no-trans:

$ cargo rustc -- -Z no-trans --test 
   Compiling foo v0.1.0 (file:///home/wilfred/tmp/foo)
error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`

error: aborting due to previous error

error: Could not compile `foo`.

To learn more, run the command again with --verbose.

This causes problems in editor integration like flycheck/flycheck-rust#47 . We want to pass --test as otherwise we don't get syntax checking on test files. However, we get the above error for projects with abort-on-panic.

Could we teach --test to ignore the runtime when we pass -Z no-trans?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryC-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions