Skip to content

Offer to close TODO: parse rustflags #333

Description

@MusicalNinjaDad

in

pub(crate) fn toml(extra_rustflags: &[&'static str]) -> toml::Value {

you have
if let Some(flags) = env::var_os("RUSTFLAGS") {
// TODO: could parse this properly and allowlist or blocklist certain
// flags. This is good enough to at least support cargo-llvm-cov.
if flags.to_string_lossy().contains("-C instrument-coverage") {

I now have a (very specific) use case where additional rustflags are required.

Suggestion & PR offer

I would be happy to offer to draft a PR (manually, not via AI) to offer something like the following API (reading from the env would clearly lead to flaky tests):

#[test]
fn specific_rustflags() {
    let t = trybuild::TestCases::with_rustflags(vec!["-Zallow-features=", "--cfg", "some_cfg"]);
    t.compile_fail("tests/some_cfg/*.rs");
}

Background

My case is the following - I'm sure there will be others who need rustflags for similar or very different reasons:

  • I have a created wrapper around proc_macro::Diagnostic for proc_macro2.
  • I provide a consistent API for all usage, regardless of which channel the final compilation occurs on.
  • I also use additional experimental features (from the try_trait_v2 family) where available.
  • The API is consistent, regardless of which channel is used for the final compilation. I have fall-back to (acceptable, non-breaking & clearly documented) reduced functionality where certain features are not available.
  • I would like to consistently test (not just manually) the outcomes in the following situation:
    • current stable & beta: no diagnostics & no try_trait_v2 ✅ (I can run CI on various toolchains & cfg-gate the path passed to trybuild)
    • current nightly: diagnostics & try_trait_v2 ✅ (I can run CI on various toolchains & cfg-gate the path passed to trybuild)
    • possible future 1: diagnostics but no try_trait_v2 ❌ (can only test manually, I have no way to construct this situation in trybuild)
    • possible future 2: try_trait_v2 but no diagnostics ❌ (can only test manually, I have no way to construct this situation in trybuild)

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions