Skip to content

Support specifying #[cfg(panic = ...)] #11794

Closed
@andylizi

Description

@andylizi

#[cfg(panic = "...")] was recently stablized in nightly. At the moment, rust-analyzer always uses panic = "unwind", making it difficult to write code for "abort", similar to #7225.

My first thought was to set [profile.dev] panic = "abort" in Cargo.toml, but that didn't work. As it turns out, RA gets the built-in cfgs from running cargo -Z unstable-options rustc --print cfg, which specifically ignores profile settings (rust-lang/cargo#9357):

  • Profiles are ignored. This has historically caused confusion for people (for things like debug_assertions). However, all of cargo ignores profiles for the intended use case (--print=cfg). It's not clear what this should do.

But if we pass --print to rustc directly with cargo rustc --lib -- --print cfg, it will use the settings from profile.dev then. This kind of problem had never came up before, since panic is the first and only cfg that can be affected by cargo profiles (aside from debug_assertions which RA hardcodes anyway).

https://github.com/rust-analyzer/rust-analyzer/blob/b594f9c441cf12319d10c14ba6a511d5c9db1b87/crates/project_model/src/rustc_cfg.rs#L40-L44

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions