@@ -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 } ;
@@ -481,7 +481,7 @@ impl Session {
481
481
}
482
482
483
483
#[ inline]
484
- pub fn source_map ( & self ) -> & source_map :: SourceMap {
484
+ pub fn source_map ( & self ) -> & SourceMap {
485
485
self . parse_sess . source_map ( )
486
486
}
487
487
pub fn verbose ( & self ) -> bool {
@@ -984,26 +984,10 @@ impl Session {
984
984
}
985
985
}
986
986
987
- pub fn build_session (
988
- sopts : config:: Options ,
989
- local_crate_source_file : Option < PathBuf > ,
990
- registry : rustc_errors:: registry:: Registry ,
991
- ) -> Session {
992
- build_session_with_source_map (
993
- sopts,
994
- local_crate_source_file,
995
- registry,
996
- DiagnosticOutput :: Default ,
997
- Default :: default ( ) ,
998
- None ,
999
- )
1000
- . 0
1001
- }
1002
-
1003
987
fn default_emitter (
1004
988
sopts : & config:: Options ,
1005
989
registry : rustc_errors:: registry:: Registry ,
1006
- source_map : & Lrc < source_map :: SourceMap > ,
990
+ source_map : Lrc < SourceMap > ,
1007
991
emitter_dest : Option < Box < dyn Write + Send > > ,
1008
992
) -> Box < dyn Emitter + sync:: Send > {
1009
993
let macro_backtrace = sopts. debugging_opts . macro_backtrace ;
@@ -1012,25 +996,22 @@ fn default_emitter(
1012
996
let ( short, color_config) = kind. unzip ( ) ;
1013
997
1014
998
if let HumanReadableErrorType :: AnnotateSnippet ( _) = kind {
1015
- let emitter = AnnotateSnippetEmitterWriter :: new (
1016
- Some ( source_map. clone ( ) ) ,
1017
- short,
1018
- macro_backtrace,
1019
- ) ;
999
+ let emitter =
1000
+ AnnotateSnippetEmitterWriter :: new ( Some ( source_map) , short, macro_backtrace) ;
1020
1001
Box :: new ( emitter. ui_testing ( sopts. debugging_opts . ui_testing ) )
1021
1002
} else {
1022
1003
let emitter = match dst {
1023
1004
None => EmitterWriter :: stderr (
1024
1005
color_config,
1025
- Some ( source_map. clone ( ) ) ,
1006
+ Some ( source_map) ,
1026
1007
short,
1027
1008
sopts. debugging_opts . teach ,
1028
1009
sopts. debugging_opts . terminal_width ,
1029
1010
macro_backtrace,
1030
1011
) ,
1031
1012
Some ( dst) => EmitterWriter :: new (
1032
1013
dst,
1033
- Some ( source_map. clone ( ) ) ,
1014
+ Some ( source_map) ,
1034
1015
short,
1035
1016
false , // no teach messages when writing to a buffer
1036
1017
false , // no colors when writing to a buffer
@@ -1042,20 +1023,14 @@ fn default_emitter(
1042
1023
}
1043
1024
}
1044
1025
( config:: ErrorOutputType :: Json { pretty, json_rendered } , None ) => Box :: new (
1045
- JsonEmitter :: stderr (
1046
- Some ( registry) ,
1047
- source_map. clone ( ) ,
1048
- pretty,
1049
- json_rendered,
1050
- macro_backtrace,
1051
- )
1052
- . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1026
+ JsonEmitter :: stderr ( Some ( registry) , source_map, pretty, json_rendered, macro_backtrace)
1027
+ . ui_testing ( sopts. debugging_opts . ui_testing ) ,
1053
1028
) ,
1054
1029
( config:: ErrorOutputType :: Json { pretty, json_rendered } , Some ( dst) ) => Box :: new (
1055
1030
JsonEmitter :: new (
1056
1031
dst,
1057
1032
Some ( registry) ,
1058
- source_map. clone ( ) ,
1033
+ source_map,
1059
1034
pretty,
1060
1035
json_rendered,
1061
1036
macro_backtrace,
@@ -1070,14 +1045,14 @@ pub enum DiagnosticOutput {
1070
1045
Raw ( Box < dyn Write + Send > ) ,
1071
1046
}
1072
1047
1073
- pub fn build_session_with_source_map (
1048
+ pub fn build_session (
1074
1049
sopts : config:: Options ,
1075
1050
local_crate_source_file : Option < PathBuf > ,
1076
1051
registry : rustc_errors:: registry:: Registry ,
1077
1052
diagnostics_output : DiagnosticOutput ,
1078
1053
driver_lint_caps : FxHashMap < lint:: LintId , lint:: Level > ,
1079
1054
file_loader : Option < Box < dyn FileLoader + Send + Sync + ' static > > ,
1080
- ) -> ( Session , Lrc < SourceMap > ) {
1055
+ ) -> Session {
1081
1056
// FIXME: This is not general enough to make the warning lint completely override
1082
1057
// normal diagnostic warnings, since the warning lint can also be denied and changed
1083
1058
// later via the source code.
@@ -1115,7 +1090,7 @@ pub fn build_session_with_source_map(
1115
1090
sopts. file_path_mapping ( ) ,
1116
1091
hash_kind,
1117
1092
) ) ;
1118
- let emitter = default_emitter ( & sopts, registry, & source_map, write_dest) ;
1093
+ let emitter = default_emitter ( & sopts, registry, source_map. clone ( ) , write_dest) ;
1119
1094
1120
1095
let span_diagnostic = rustc_errors:: Handler :: with_emitter_and_flags (
1121
1096
emitter,
@@ -1143,7 +1118,7 @@ pub fn build_session_with_source_map(
1143
1118
None
1144
1119
} ;
1145
1120
1146
- let parse_sess = ParseSess :: with_span_handler ( span_diagnostic, source_map. clone ( ) ) ;
1121
+ let parse_sess = ParseSess :: with_span_handler ( span_diagnostic, source_map) ;
1147
1122
let sysroot = match & sopts. maybe_sysroot {
1148
1123
Some ( sysroot) => sysroot. clone ( ) ,
1149
1124
None => filesearch:: get_or_default_sysroot ( ) ,
@@ -1266,7 +1241,7 @@ pub fn build_session_with_source_map(
1266
1241
1267
1242
validate_commandline_args_with_session_available ( & sess) ;
1268
1243
1269
- ( sess, source_map )
1244
+ sess
1270
1245
}
1271
1246
1272
1247
// If it is useful to have a Session available already for validating a
0 commit comments