@@ -899,14 +899,14 @@ impl Session {
899
899
900
900
/// Returns the number of query threads that should be used for this
901
901
/// 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 ( ) )
904
904
}
905
905
906
906
/// Returns the number of query threads that should be used for this
907
907
/// compilation
908
908
pub fn threads ( & self ) -> usize {
909
- Self :: threads_from_opts ( & self . opts )
909
+ Self :: threads_from_count ( self . opts . debugging_opts . threads )
910
910
}
911
911
912
912
/// Returns the number of codegen units that should be used for this
@@ -1023,16 +1023,67 @@ pub fn build_session(
1023
1023
local_crate_source_file,
1024
1024
registry,
1025
1025
Lrc :: new ( source_map:: SourceMap :: new ( file_path_mapping) ) ,
1026
- None ,
1026
+ DiagnosticOutput :: Default ,
1027
+ Default :: default ( ) ,
1027
1028
)
1028
1029
}
1029
1030
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
+
1030
1080
pub fn build_session_with_source_map (
1031
1081
sopts : config:: Options ,
1032
1082
local_crate_source_file : Option < PathBuf > ,
1033
1083
registry : errors:: registry:: Registry ,
1034
1084
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 > ,
1036
1087
) -> Session {
1037
1088
// FIXME: This is not general enough to make the warning lint completely override
1038
1089
// normal diagnostic warnings, since the warning lint can also be denied and changed
@@ -1054,42 +1105,13 @@ pub fn build_session_with_source_map(
1054
1105
1055
1106
let external_macro_backtrace = sopts. debugging_opts . external_macro_backtrace ;
1056
1107
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
+ } ;
1093
1115
1094
1116
let diagnostic_handler = errors:: Handler :: with_emitter_and_flags (
1095
1117
emitter,
@@ -1103,14 +1125,15 @@ pub fn build_session_with_source_map(
1103
1125
} ,
1104
1126
) ;
1105
1127
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 )
1107
1129
}
1108
1130
1109
1131
pub fn build_session_ (
1110
1132
sopts : config:: Options ,
1111
1133
local_crate_source_file : Option < PathBuf > ,
1112
1134
span_diagnostic : errors:: Handler ,
1113
1135
source_map : Lrc < source_map:: SourceMap > ,
1136
+ driver_lint_caps : FxHashMap < lint:: LintId , lint:: Level > ,
1114
1137
) -> Session {
1115
1138
let host_triple = TargetTriple :: from_triple ( config:: host_triple ( ) ) ;
1116
1139
let host = Target :: search ( & host_triple) . unwrap_or_else ( |e|
@@ -1235,7 +1258,7 @@ pub fn build_session_(
1235
1258
} ,
1236
1259
has_global_allocator : Once :: new ( ) ,
1237
1260
has_panic_handler : Once :: new ( ) ,
1238
- driver_lint_caps : Default :: default ( ) ,
1261
+ driver_lint_caps,
1239
1262
} ;
1240
1263
1241
1264
validate_commandline_args_with_session_available ( & sess) ;
0 commit comments