@@ -21,7 +21,7 @@ use rustc_errors::json::JsonEmitter;
21
21
use rustc_errors:: registry:: Registry ;
22
22
use rustc_errors:: { Applicability , DiagnosticBuilder , DiagnosticId , ErrorReported } ;
23
23
use rustc_span:: edition:: Edition ;
24
- use rustc_span:: source_map:: { self , FileLoader , MultiSpan , RealFileLoader , SourceMap , Span } ;
24
+ use rustc_span:: source_map:: { FileLoader , MultiSpan , RealFileLoader , SourceMap , Span } ;
25
25
use rustc_span:: { SourceFileHashAlgorithm , Symbol } ;
26
26
use rustc_target:: asm:: InlineAsmArch ;
27
27
use rustc_target:: spec:: { CodeModel , PanicStrategy , RelocModel , RelroLevel } ;
@@ -523,7 +523,7 @@ impl Session {
523
523
}
524
524
525
525
#[ inline]
526
- pub fn source_map ( & self ) -> & source_map :: SourceMap {
526
+ pub fn source_map ( & self ) -> & SourceMap {
527
527
self . parse_sess . source_map ( )
528
528
}
529
529
pub fn verbose ( & self ) -> bool {
@@ -1026,26 +1026,10 @@ impl Session {
1026
1026
}
1027
1027
}
1028
1028
1029
- pub fn build_session (
1030
- sopts : config:: Options ,
1031
- local_crate_source_file : Option < PathBuf > ,
1032
- registry : rustc_errors:: registry:: Registry ,
1033
- ) -> Session {
1034
- build_session_with_source_map (
1035
- sopts,
1036
- local_crate_source_file,
1037
- registry,
1038
- DiagnosticOutput :: Default ,
1039
- Default :: default ( ) ,
1040
- None ,
1041
- )
1042
- . 0
1043
- }
1044
-
1045
1029
fn default_emitter (
1046
1030
sopts : & config:: Options ,
1047
1031
registry : rustc_errors:: registry:: Registry ,
1048
- source_map : & Lrc < source_map :: SourceMap > ,
1032
+ source_map : Lrc < SourceMap > ,
1049
1033
emitter_dest : Option < Box < dyn Write + Send > > ,
1050
1034
) -> Box < dyn Emitter + sync:: Send > {
1051
1035
let macro_backtrace = sopts. debugging_opts . macro_backtrace ;
@@ -1054,25 +1038,22 @@ fn default_emitter(
1054
1038
let ( short, color_config) = kind. unzip ( ) ;
1055
1039
1056
1040
if let HumanReadableErrorType :: AnnotateSnippet ( _) = kind {
1057
- let emitter = AnnotateSnippetEmitterWriter :: new (
1058
- Some ( source_map. clone ( ) ) ,
1059
- short,
1060
- macro_backtrace,
1061
- ) ;
1041
+ let emitter =
1042
+ AnnotateSnippetEmitterWriter :: new ( Some ( source_map) , short, macro_backtrace) ;
1062
1043
Box :: new ( emitter. ui_testing ( sopts. debugging_opts . ui_testing ) )
1063
1044
} else {
1064
1045
let emitter = match dst {
1065
1046
None => EmitterWriter :: stderr (
1066
1047
color_config,
1067
- Some ( source_map. clone ( ) ) ,
1048
+ Some ( source_map) ,
1068
1049
short,
1069
1050
sopts. debugging_opts . teach ,
1070
1051
sopts. debugging_opts . terminal_width ,
1071
1052
macro_backtrace,
1072
1053
) ,
1073
1054
Some ( dst) => EmitterWriter :: new (
1074
1055
dst,
1075
- Some ( source_map. clone ( ) ) ,
1056
+ Some ( source_map) ,
1076
1057
short,
1077
1058
false , // no teach messages when writing to a buffer
1078
1059
false , // no colors when writing to a buffer
@@ -1084,20 +1065,14 @@ fn default_emitter(
1084
1065
}
1085
1066
}
1086
1067
( config:: ErrorOutputType :: Json { pretty, json_rendered } , None ) => Box :: new (
1087
- JsonEmitter :: stderr (
1088
- Some ( registry) ,
1089
- source_map. clone ( ) ,
1090
- pretty,
1091
- json_rendered,
1092
- macro_backtrace,
1093
- )
1094
- . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1068
+ JsonEmitter :: stderr ( Some ( registry) , source_map, pretty, json_rendered, macro_backtrace)
1069
+ . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1095
1070
) ,
1096
1071
( config:: ErrorOutputType :: Json { pretty, json_rendered } , Some ( dst) ) => Box :: new (
1097
1072
JsonEmitter :: new (
1098
1073
dst,
1099
1074
Some ( registry) ,
1100
- source_map. clone ( ) ,
1075
+ source_map,
1101
1076
pretty,
1102
1077
json_rendered,
1103
1078
macro_backtrace,
@@ -1112,14 +1087,14 @@ pub enum DiagnosticOutput {
1112
1087
Raw ( Box < dyn Write + Send > ) ,
1113
1088
}
1114
1089
1115
- pub fn build_session_with_source_map (
1090
+ pub fn build_session (
1116
1091
sopts : config:: Options ,
1117
1092
local_crate_source_file : Option < PathBuf > ,
1118
1093
registry : rustc_errors:: registry:: Registry ,
1119
1094
diagnostics_output : DiagnosticOutput ,
1120
1095
driver_lint_caps : FxHashMap < lint:: LintId , lint:: Level > ,
1121
1096
file_loader : Option < Box < dyn FileLoader + Send + Sync + ' static > > ,
1122
- ) -> ( Session , Lrc < SourceMap > ) {
1097
+ ) -> Session {
1123
1098
// FIXME: This is not general enough to make the warning lint completely override
1124
1099
// normal diagnostic warnings, since the warning lint can also be denied and changed
1125
1100
// later via the source code.
@@ -1157,7 +1132,7 @@ pub fn build_session_with_source_map(
1157
1132
sopts. file_path_mapping ( ) ,
1158
1133
hash_kind,
1159
1134
) ) ;
1160
- let emitter = default_emitter ( & sopts, registry, & source_map, write_dest) ;
1135
+ let emitter = default_emitter ( & sopts, registry, source_map. clone ( ) , write_dest) ;
1161
1136
1162
1137
let span_diagnostic = rustc_errors:: Handler :: with_emitter_and_flags (
1163
1138
emitter,
@@ -1185,7 +1160,7 @@ pub fn build_session_with_source_map(
1185
1160
None
1186
1161
} ;
1187
1162
1188
- let parse_sess = ParseSess :: with_span_handler ( span_diagnostic, source_map. clone ( ) ) ;
1163
+ let parse_sess = ParseSess :: with_span_handler ( span_diagnostic, source_map) ;
1189
1164
let sysroot = match & sopts. maybe_sysroot {
1190
1165
Some ( sysroot) => sysroot. clone ( ) ,
1191
1166
None => filesearch:: get_or_default_sysroot ( ) ,
@@ -1308,7 +1283,7 @@ pub fn build_session_with_source_map(
1308
1283
1309
1284
validate_commandline_args_with_session_available ( & sess) ;
1310
1285
1311
- ( sess, source_map )
1286
+ sess
1312
1287
}
1313
1288
1314
1289
// If it is useful to have a Session available already for validating a
0 commit comments