@@ -50,6 +50,7 @@ use rustc_interface::{Linker, Queries, interface, passes};
50
50
use rustc_lint:: unerased_lint_store;
51
51
use rustc_metadata:: creader:: MetadataLoader ;
52
52
use rustc_metadata:: locator;
53
+ use rustc_middle:: ty:: TyCtxt ;
53
54
use rustc_parse:: { new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal} ;
54
55
use rustc_session:: config:: {
55
56
CG_OPTIONS , ErrorOutputType , Input , OutFileName , OutputType , UnstableOptions , Z_OPTIONS ,
@@ -102,7 +103,7 @@ mod signal_handler {
102
103
103
104
use crate :: session_diagnostics:: {
104
105
RLinkEmptyVersionNumber , RLinkEncodingVersionMismatch , RLinkRustcVersionMismatch ,
105
- RLinkWrongFileType , RlinkCorruptFile , RlinkNotAFile , RlinkUnableToRead ,
106
+ RLinkWrongFileType , RlinkCorruptFile , RlinkNotAFile , RlinkUnableToRead , UnstableFeatureUsage ,
106
107
} ;
107
108
108
109
rustc_fluent_macro:: fluent_messages! { "../messages.ftl" }
@@ -430,6 +431,10 @@ fn run_compiler(
430
431
// Make sure name resolution and macro expansion is run.
431
432
queries. global_ctxt( ) ?. enter( |tcx| tcx. resolver_for_lowering( ) ) ;
432
433
434
+ if let Some ( metrics_dir) = & sess. opts. unstable_opts. metrics_dir {
435
+ queries. global_ctxt( ) ?. enter( |tcxt| dump_feature_usage_metrics( tcxt, metrics_dir) ) ;
436
+ }
437
+
433
438
if callbacks. after_expansion( compiler, queries) == Compilation :: Stop {
434
439
return early_exit( ) ;
435
440
}
@@ -474,6 +479,23 @@ fn run_compiler(
474
479
} )
475
480
}
476
481
482
+ fn dump_feature_usage_metrics( tcxt: TyCtxt <' _>, metrics_dir: & PathBuf ) {
483
+ let output_filenames = tcxt. output_filenames( ( ) ) ;
484
+ let mut metrics_file_name = std:: ffi:: OsString :: from( "unstable_feature_usage_metrics-" ) ;
485
+ let mut metrics_path = output_filenames. with_directory_and_extension( metrics_dir, "json" ) ;
486
+ let metrics_file_stem =
487
+ metrics_path. file_name( ) . expect( "there should be a valid default output filename" ) ;
488
+ metrics_file_name. push( metrics_file_stem) ;
489
+ metrics_path. pop( ) ;
490
+ metrics_path. push( metrics_file_name) ;
491
+ if let Err ( error) = tcxt. features( ) . dump_feature_usage_metrics( metrics_path) {
492
+ // FIXME(yaahc): once metrics can be enabled by default we will want "failure to emit
493
+ // default metrics" to only produce a warning when metrics are enabled by default and emit
494
+ // an error only when the user manually enables metrics
495
+ tcxt. dcx( ) . emit_err( UnstableFeatureUsage { error } ) ;
496
+ }
497
+ }
498
+
477
499
// Extract output directory and file from matches.
478
500
fn make_output( matches: & getopts:: Matches ) -> ( Option <PathBuf >, Option <OutFileName >) {
479
501
let odir = matches. opt_str( "out-dir" ) . map( |o| PathBuf :: from( & o) ) ;
0 commit comments