Rollup merge of #130236 - yaahc:unstable-feature-usage, r=estebank
unstable feature usage metrics example output ``` test-lib on master [?] is 📦 v0.1.0 via 🦀 v1.80.1 ❯ cat src/lib.rs ───────┬─────────────────────────────────────────────────────── │ File: src/lib.rs ───────┼─────────────────────────────────────────────────────── 1 │ #![feature(unix_set_mark)] 2 │ pub fn add(left: u64, right: u64) -> u64 { 3 │ left + right 4 │ } 5 │ 6 │ #[cfg(test)] 7 │ mod tests { 8 │ use super::*; 9 │ 10 │ #[test] 11 │ fn it_works() { 12 │ let result = add(2, 2); 13 │ assert_eq!(result, 4); 14 │ } 15 │ } ───────┴─────────────────────────────────────────────────────── test-lib on master [?] is 📦 v0.1.0 via 🦀 v1.80.1 ❯ cargo +stage1 rustc -- -Zmetrics-dir=$PWD/metrics Compiling test-lib v0.1.0 (/home/yaahc/tmp/test-lib) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s test-lib on master [?] is 📦 v0.1.0 via 🦀 v1.80.1 ❯ cat metrics/unstable_feature_usage.json ───────┬───────────────────────────────────────────────────────────────────── │ File: metrics/unstable_feature_usage.json ───────┼───────────────────────────────────────────────────────────────────── 1 │ {"lib_features":[{"symbol":"unix_set_mark"}],"lang_features":[]} ``` related to https://github.com/rust-lang/rust/issues/129485
This commit is contained in:
commit
fe5403f517
10 changed files with 185 additions and 3 deletions
|
@ -7,4 +7,6 @@ edition = "2021"
|
|||
# tidy-alphabetical-start
|
||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
serde = { version = "1.0.125", features = [ "derive" ] }
|
||||
serde_json = "1.0.59"
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! List of the unstable feature gates.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Symbol, sym};
|
||||
|
@ -651,6 +653,54 @@ declare_features! (
|
|||
// -------------------------------------------------------------------------
|
||||
);
|
||||
|
||||
impl Features {
|
||||
pub fn dump_feature_usage_metrics(
|
||||
&self,
|
||||
metrics_path: PathBuf,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
#[derive(serde::Serialize)]
|
||||
struct LibFeature {
|
||||
symbol: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct LangFeature {
|
||||
symbol: String,
|
||||
since: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct FeatureUsage {
|
||||
lib_features: Vec<LibFeature>,
|
||||
lang_features: Vec<LangFeature>,
|
||||
}
|
||||
|
||||
let metrics_file = std::fs::File::create(metrics_path)?;
|
||||
let metrics_file = std::io::BufWriter::new(metrics_file);
|
||||
|
||||
let lib_features = self
|
||||
.enabled_lib_features
|
||||
.iter()
|
||||
.map(|EnabledLibFeature { gate_name, .. }| LibFeature { symbol: gate_name.to_string() })
|
||||
.collect();
|
||||
|
||||
let lang_features = self
|
||||
.enabled_lang_features
|
||||
.iter()
|
||||
.map(|EnabledLangFeature { gate_name, stable_since, .. }| LangFeature {
|
||||
symbol: gate_name.to_string(),
|
||||
since: stable_since.map(|since| since.to_string()),
|
||||
})
|
||||
.collect();
|
||||
|
||||
let feature_usage = FeatureUsage { lib_features, lang_features };
|
||||
|
||||
serde_json::to_writer(metrics_file, &feature_usage)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Some features are not allowed to be used together at the same time, if
|
||||
/// the two are present, produce an error.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue