@@ -899,14 +899,14 @@ impl Session {
899899
900900 /// Returns the number of query threads that should be used for this
901901 /// compilation
902- pub fn threads_from_opts ( opts : & config :: Options ) -> usize {
903- opts . debugging_opts . threads . unwrap_or ( :: num_cpus:: get ( ) )
902+ pub fn threads_from_count ( query_threads : Option < usize > ) -> usize {
903+ query_threads . unwrap_or ( :: num_cpus:: get ( ) )
904904 }
905905
906906 /// Returns the number of query threads that should be used for this
907907 /// compilation
908908 pub fn threads ( & self ) -> usize {
909- Self :: threads_from_opts ( & self . opts )
909+ Self :: threads_from_count ( self . opts . debugging_opts . threads )
910910 }
911911
912912 /// Returns the number of codegen units that should be used for this
@@ -1023,16 +1023,67 @@ pub fn build_session(
10231023 local_crate_source_file,
10241024 registry,
10251025 Lrc :: new ( source_map:: SourceMap :: new ( file_path_mapping) ) ,
1026- None ,
1026+ DiagnosticOutput :: Default ,
1027+ Default :: default ( ) ,
10271028 )
10281029}
10291030
1031+ fn default_emitter (
1032+ sopts : & config:: Options ,
1033+ registry : errors:: registry:: Registry ,
1034+ source_map : & Lrc < source_map:: SourceMap > ,
1035+ emitter_dest : Option < Box < dyn Write + Send > > ,
1036+ ) -> Box < dyn Emitter + sync:: Send > {
1037+ match ( sopts. error_format , emitter_dest) {
1038+ ( config:: ErrorOutputType :: HumanReadable ( color_config) , None ) => Box :: new (
1039+ EmitterWriter :: stderr (
1040+ color_config,
1041+ Some ( source_map. clone ( ) ) ,
1042+ false ,
1043+ sopts. debugging_opts . teach ,
1044+ ) . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1045+ ) ,
1046+ ( config:: ErrorOutputType :: HumanReadable ( _) , Some ( dst) ) => Box :: new (
1047+ EmitterWriter :: new ( dst, Some ( source_map. clone ( ) ) , false , false )
1048+ . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1049+ ) ,
1050+ ( config:: ErrorOutputType :: Json ( pretty) , None ) => Box :: new (
1051+ JsonEmitter :: stderr (
1052+ Some ( registry) ,
1053+ source_map. clone ( ) ,
1054+ pretty,
1055+ ) . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1056+ ) ,
1057+ ( config:: ErrorOutputType :: Json ( pretty) , Some ( dst) ) => Box :: new (
1058+ JsonEmitter :: new (
1059+ dst,
1060+ Some ( registry) ,
1061+ source_map. clone ( ) ,
1062+ pretty,
1063+ ) . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1064+ ) ,
1065+ ( config:: ErrorOutputType :: Short ( color_config) , None ) => Box :: new (
1066+ EmitterWriter :: stderr ( color_config, Some ( source_map. clone ( ) ) , true , false ) ,
1067+ ) ,
1068+ ( config:: ErrorOutputType :: Short ( _) , Some ( dst) ) => {
1069+ Box :: new ( EmitterWriter :: new ( dst, Some ( source_map. clone ( ) ) , true , false ) )
1070+ }
1071+ }
1072+ }
1073+
1074+ pub enum DiagnosticOutput {
1075+ Default ,
1076+ Raw ( Box < dyn Write + Send > ) ,
1077+ Emitter ( Box < dyn Emitter + Send + sync:: Send > )
1078+ }
1079+
10301080pub fn build_session_with_source_map (
10311081 sopts : config:: Options ,
10321082 local_crate_source_file : Option < PathBuf > ,
10331083 registry : errors:: registry:: Registry ,
10341084 source_map : Lrc < source_map:: SourceMap > ,
1035- emitter_dest : Option < Box < dyn Write + Send > > ,
1085+ diagnostics_output : DiagnosticOutput ,
1086+ lint_caps : FxHashMap < lint:: LintId , lint:: Level > ,
10361087) -> Session {
10371088 // FIXME: This is not general enough to make the warning lint completely override
10381089 // normal diagnostic warnings, since the warning lint can also be denied and changed
@@ -1054,42 +1105,13 @@ pub fn build_session_with_source_map(
10541105
10551106 let external_macro_backtrace = sopts. debugging_opts . external_macro_backtrace ;
10561107
1057- let emitter: Box < dyn Emitter + sync:: Send > =
1058- match ( sopts. error_format , emitter_dest) {
1059- ( config:: ErrorOutputType :: HumanReadable ( color_config) , None ) => Box :: new (
1060- EmitterWriter :: stderr (
1061- color_config,
1062- Some ( source_map. clone ( ) ) ,
1063- false ,
1064- sopts. debugging_opts . teach ,
1065- ) . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1066- ) ,
1067- ( config:: ErrorOutputType :: HumanReadable ( _) , Some ( dst) ) => Box :: new (
1068- EmitterWriter :: new ( dst, Some ( source_map. clone ( ) ) , false , false )
1069- . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1070- ) ,
1071- ( config:: ErrorOutputType :: Json ( pretty) , None ) => Box :: new (
1072- JsonEmitter :: stderr (
1073- Some ( registry) ,
1074- source_map. clone ( ) ,
1075- pretty,
1076- ) . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1077- ) ,
1078- ( config:: ErrorOutputType :: Json ( pretty) , Some ( dst) ) => Box :: new (
1079- JsonEmitter :: new (
1080- dst,
1081- Some ( registry) ,
1082- source_map. clone ( ) ,
1083- pretty,
1084- ) . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1085- ) ,
1086- ( config:: ErrorOutputType :: Short ( color_config) , None ) => Box :: new (
1087- EmitterWriter :: stderr ( color_config, Some ( source_map. clone ( ) ) , true , false ) ,
1088- ) ,
1089- ( config:: ErrorOutputType :: Short ( _) , Some ( dst) ) => {
1090- Box :: new ( EmitterWriter :: new ( dst, Some ( source_map. clone ( ) ) , true , false ) )
1091- }
1092- } ;
1108+ let emitter = match diagnostics_output {
1109+ DiagnosticOutput :: Default => default_emitter ( & sopts, registry, & source_map, None ) ,
1110+ DiagnosticOutput :: Raw ( write) => {
1111+ default_emitter ( & sopts, registry, & source_map, Some ( write) )
1112+ }
1113+ DiagnosticOutput :: Emitter ( emitter) => emitter,
1114+ } ;
10931115
10941116 let diagnostic_handler = errors:: Handler :: with_emitter_and_flags (
10951117 emitter,
@@ -1103,14 +1125,15 @@ pub fn build_session_with_source_map(
11031125 } ,
11041126 ) ;
11051127
1106- build_session_ ( sopts, local_crate_source_file, diagnostic_handler, source_map)
1128+ build_session_ ( sopts, local_crate_source_file, diagnostic_handler, source_map, lint_caps )
11071129}
11081130
11091131pub fn build_session_ (
11101132 sopts : config:: Options ,
11111133 local_crate_source_file : Option < PathBuf > ,
11121134 span_diagnostic : errors:: Handler ,
11131135 source_map : Lrc < source_map:: SourceMap > ,
1136+ driver_lint_caps : FxHashMap < lint:: LintId , lint:: Level > ,
11141137) -> Session {
11151138 let host_triple = TargetTriple :: from_triple ( config:: host_triple ( ) ) ;
11161139 let host = Target :: search ( & host_triple) . unwrap_or_else ( |e|
@@ -1235,7 +1258,7 @@ pub fn build_session_(
12351258 } ,
12361259 has_global_allocator : Once :: new ( ) ,
12371260 has_panic_handler : Once :: new ( ) ,
1238- driver_lint_caps : Default :: default ( ) ,
1261+ driver_lint_caps,
12391262 } ;
12401263
12411264 validate_commandline_args_with_session_available ( & sess) ;
0 commit comments