@@ -21,7 +21,7 @@ use rustc_errors::json::JsonEmitter;
2121use rustc_errors:: registry:: Registry ;
2222use rustc_errors:: { Applicability , DiagnosticBuilder , DiagnosticId , ErrorReported } ;
2323use 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 } ;
2525use rustc_span:: { SourceFileHashAlgorithm , Symbol } ;
2626use rustc_target:: asm:: InlineAsmArch ;
2727use rustc_target:: spec:: { CodeModel , PanicStrategy , RelocModel , RelroLevel } ;
@@ -481,7 +481,7 @@ impl Session {
481481 }
482482
483483 #[ inline]
484- pub fn source_map ( & self ) -> & source_map :: SourceMap {
484+ pub fn source_map ( & self ) -> & SourceMap {
485485 self . parse_sess . source_map ( )
486486 }
487487 pub fn verbose ( & self ) -> bool {
@@ -984,26 +984,10 @@ impl Session {
984984 }
985985}
986986
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-
1003987fn default_emitter (
1004988 sopts : & config:: Options ,
1005989 registry : rustc_errors:: registry:: Registry ,
1006- source_map : & Lrc < source_map :: SourceMap > ,
990+ source_map : Lrc < SourceMap > ,
1007991 emitter_dest : Option < Box < dyn Write + Send > > ,
1008992) -> Box < dyn Emitter + sync:: Send > {
1009993 let macro_backtrace = sopts. debugging_opts . macro_backtrace ;
@@ -1012,25 +996,22 @@ fn default_emitter(
1012996 let ( short, color_config) = kind. unzip ( ) ;
1013997
1014998 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) ;
10201001 Box :: new ( emitter. ui_testing ( sopts. debugging_opts . ui_testing ) )
10211002 } else {
10221003 let emitter = match dst {
10231004 None => EmitterWriter :: stderr (
10241005 color_config,
1025- Some ( source_map. clone ( ) ) ,
1006+ Some ( source_map) ,
10261007 short,
10271008 sopts. debugging_opts . teach ,
10281009 sopts. debugging_opts . terminal_width ,
10291010 macro_backtrace,
10301011 ) ,
10311012 Some ( dst) => EmitterWriter :: new (
10321013 dst,
1033- Some ( source_map. clone ( ) ) ,
1014+ Some ( source_map) ,
10341015 short,
10351016 false , // no teach messages when writing to a buffer
10361017 false , // no colors when writing to a buffer
@@ -1042,20 +1023,14 @@ fn default_emitter(
10421023 }
10431024 }
10441025 ( 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 ) ,
10531028 ) ,
10541029 ( config:: ErrorOutputType :: Json { pretty, json_rendered } , Some ( dst) ) => Box :: new (
10551030 JsonEmitter :: new (
10561031 dst,
10571032 Some ( registry) ,
1058- source_map. clone ( ) ,
1033+ source_map,
10591034 pretty,
10601035 json_rendered,
10611036 macro_backtrace,
@@ -1070,14 +1045,14 @@ pub enum DiagnosticOutput {
10701045 Raw ( Box < dyn Write + Send > ) ,
10711046}
10721047
1073- pub fn build_session_with_source_map (
1048+ pub fn build_session (
10741049 sopts : config:: Options ,
10751050 local_crate_source_file : Option < PathBuf > ,
10761051 registry : rustc_errors:: registry:: Registry ,
10771052 diagnostics_output : DiagnosticOutput ,
10781053 driver_lint_caps : FxHashMap < lint:: LintId , lint:: Level > ,
10791054 file_loader : Option < Box < dyn FileLoader + Send + Sync + ' static > > ,
1080- ) -> ( Session , Lrc < SourceMap > ) {
1055+ ) -> Session {
10811056 // FIXME: This is not general enough to make the warning lint completely override
10821057 // normal diagnostic warnings, since the warning lint can also be denied and changed
10831058 // later via the source code.
@@ -1115,7 +1090,7 @@ pub fn build_session_with_source_map(
11151090 sopts. file_path_mapping ( ) ,
11161091 hash_kind,
11171092 ) ) ;
1118- let emitter = default_emitter ( & sopts, registry, & source_map, write_dest) ;
1093+ let emitter = default_emitter ( & sopts, registry, source_map. clone ( ) , write_dest) ;
11191094
11201095 let span_diagnostic = rustc_errors:: Handler :: with_emitter_and_flags (
11211096 emitter,
@@ -1143,7 +1118,7 @@ pub fn build_session_with_source_map(
11431118 None
11441119 } ;
11451120
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) ;
11471122 let sysroot = match & sopts. maybe_sysroot {
11481123 Some ( sysroot) => sysroot. clone ( ) ,
11491124 None => filesearch:: get_or_default_sysroot ( ) ,
@@ -1266,7 +1241,7 @@ pub fn build_session_with_source_map(
12661241
12671242 validate_commandline_args_with_session_available ( & sess) ;
12681243
1269- ( sess, source_map )
1244+ sess
12701245}
12711246
12721247// If it is useful to have a Session available already for validating a
0 commit comments