@@ -73,9 +73,11 @@ extern crate tikv_jemalloc_sys as jemalloc_sys;
73
73
74
74
use std:: env:: { self , VarError } ;
75
75
use std:: io:: { self , IsTerminal } ;
76
+ use std:: path:: Path ;
76
77
use std:: process;
77
78
78
79
use rustc_errors:: DiagCtxtHandle ;
80
+ use rustc_hir:: def_id:: LOCAL_CRATE ;
79
81
use rustc_interface:: interface;
80
82
use rustc_middle:: ty:: TyCtxt ;
81
83
use rustc_session:: config:: { ErrorOutputType , RustcOptGroup , make_crate_type_option} ;
@@ -909,6 +911,10 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
909
911
return ;
910
912
}
911
913
914
+ if let Some ( metrics_dir) = & sess. opts . unstable_opts . metrics_dir {
915
+ dump_feature_usage_metrics ( tcx, metrics_dir) ;
916
+ }
917
+
912
918
info ! ( "going to format" ) ;
913
919
match output_format {
914
920
config:: OutputFormat :: Html => sess. time ( "render_html" , || {
@@ -923,3 +929,16 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
923
929
} )
924
930
} )
925
931
}
932
+
933
+ fn dump_feature_usage_metrics ( tcxt : TyCtxt < ' _ > , metrics_dir : & Path ) {
934
+ let hash = tcxt. crate_hash ( LOCAL_CRATE ) ;
935
+ let crate_name = tcxt. crate_name ( LOCAL_CRATE ) ;
936
+ let metrics_file_name = format ! ( "unstable_feature_usage_metrics-{crate_name}-{hash}.json" ) ;
937
+ let metrics_path = metrics_dir. join ( metrics_file_name) ;
938
+ if let Err ( _) = tcxt. features ( ) . dump_feature_usage_metrics ( metrics_path) {
939
+ // FIXME(yaahc): once metrics can be enabled by default we will want "failure to emit
940
+ // default metrics" to only produce a warning when metrics are enabled by default and emit
941
+ // an error only when the user manually enables metrics
942
+ tcxt. dcx ( ) . err ( "placeholder" ) ;
943
+ }
944
+ }
0 commit comments