'How do I print all attributes?
I want to print the compile-time attributes to the console, ("conditional predicates"). Is there built-in function or macro that does this?
I'm imagining code like:
#[allow(non_snake_case)]
fn main() {
eprintln!(cfg_as_str!());
}
that might print
allow.non_snake_case=true
allow.dead_code=false
...
cfg.debug_attributes=true
cfg.test=false
cfg.bench=false
...
target_arch="x86_64"
...
I want to better understand the state of the rust compiler at different lines of code. However, it's tedious to do so by trial-and-error.
Of course, I could write this on my own. But I'd guess someone else already has.
Solution 1:[1]
I don't think you'll get the lint attributes but for the cfg options you could add a build.rs with:
use std::env;
fn main() {
for (key, value) in env::vars() {
if key.starts_with("CARGO") {
eprintln!("{}: {}", key, value);
}
}
}
Then building with cargo build -vv will output cfgs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
