Skip to content

Commit 2999d8d

Browse files
committed
Inline and remove JsonEmitter::{basic,stderr}.
They are so similar to `JsonEmitter::new` it's not worth having separate functions, it makes the code harder to read.
1 parent 067d7c3 commit 2999d8d

File tree

3 files changed

+14
-61
lines changed

3 files changed

+14
-61
lines changed

compiler/rustc_errors/src/json.rs

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
// FIXME: spec the JSON output properly.
1111

12-
use rustc_span::source_map::{FilePathMapping, SourceMap};
12+
use rustc_span::source_map::SourceMap;
1313
use termcolor::{ColorSpec, WriteColor};
1414

1515
use crate::emitter::{
@@ -56,60 +56,6 @@ pub struct JsonEmitter {
5656
}
5757

5858
impl JsonEmitter {
59-
pub fn stderr(
60-
registry: Option<Registry>,
61-
source_map: Lrc<SourceMap>,
62-
fluent_bundle: Option<Lrc<FluentBundle>>,
63-
fallback_bundle: LazyFallbackBundle,
64-
pretty: bool,
65-
json_rendered: HumanReadableErrorType,
66-
diagnostic_width: Option<usize>,
67-
macro_backtrace: bool,
68-
track_diagnostics: bool,
69-
terminal_url: TerminalUrl,
70-
) -> JsonEmitter {
71-
JsonEmitter {
72-
dst: IntoDynSyncSend(Box::new(io::BufWriter::new(io::stderr()))),
73-
registry,
74-
sm: source_map,
75-
fluent_bundle,
76-
fallback_bundle,
77-
pretty,
78-
ui_testing: false,
79-
ignored_directories_in_source_blocks: Vec::new(),
80-
json_rendered,
81-
diagnostic_width,
82-
macro_backtrace,
83-
track_diagnostics,
84-
terminal_url,
85-
}
86-
}
87-
88-
pub fn basic(
89-
pretty: bool,
90-
json_rendered: HumanReadableErrorType,
91-
fluent_bundle: Option<Lrc<FluentBundle>>,
92-
fallback_bundle: LazyFallbackBundle,
93-
diagnostic_width: Option<usize>,
94-
macro_backtrace: bool,
95-
track_diagnostics: bool,
96-
terminal_url: TerminalUrl,
97-
) -> JsonEmitter {
98-
let file_path_mapping = FilePathMapping::empty();
99-
JsonEmitter::stderr(
100-
None,
101-
Lrc::new(SourceMap::new(file_path_mapping)),
102-
fluent_bundle,
103-
fallback_bundle,
104-
pretty,
105-
json_rendered,
106-
diagnostic_width,
107-
macro_backtrace,
108-
track_diagnostics,
109-
terminal_url,
110-
)
111-
}
112-
11359
pub fn new(
11460
dst: Box<dyn Write + Send>,
11561
registry: Option<Registry>,

compiler/rustc_session/src/session.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_errors::{
2828
use rustc_macros::HashStable_Generic;
2929
pub use rustc_span::def_id::StableCrateId;
3030
use rustc_span::edition::Edition;
31-
use rustc_span::source_map::{FileLoader, RealFileLoader, SourceMap};
31+
use rustc_span::source_map::{FileLoader, FilePathMapping, RealFileLoader, SourceMap};
3232
use rustc_span::{SourceFileHashAlgorithm, Span, Symbol};
3333
use rustc_target::asm::InlineAsmArch;
3434
use rustc_target::spec::{CodeModel, PanicStrategy, RelocModel, RelroLevel};
@@ -39,6 +39,7 @@ use rustc_target::spec::{
3939
use std::any::Any;
4040
use std::env;
4141
use std::fmt;
42+
use std::io;
4243
use std::ops::{Div, Mul};
4344
use std::path::{Path, PathBuf};
4445
use std::str::FromStr;
@@ -998,7 +999,8 @@ fn default_emitter(
998999
}
9991000
}
10001001
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(
1001-
JsonEmitter::stderr(
1002+
JsonEmitter::new(
1003+
Box::new(io::BufWriter::new(io::stderr())),
10021004
Some(registry),
10031005
source_map,
10041006
bundle,
@@ -1478,11 +1480,14 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
14781480
.short_message(short),
14791481
)
14801482
}
1481-
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic(
1482-
pretty,
1483-
json_rendered,
1483+
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::new(
1484+
Box::new(io::BufWriter::new(io::stderr())),
1485+
None,
1486+
Lrc::new(SourceMap::new(FilePathMapping::empty())),
14841487
None,
14851488
fallback_bundle,
1489+
pretty,
1490+
json_rendered,
14861491
None,
14871492
false,
14881493
false,

src/librustdoc/core.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_span::symbol::sym;
2020
use rustc_span::{source_map, Span};
2121

2222
use std::cell::RefCell;
23+
use std::io;
2324
use std::mem;
2425
use std::rc::Rc;
2526
use std::sync::LazyLock;
@@ -155,7 +156,8 @@ pub(crate) fn new_dcx(
155156
Lrc::new(source_map::SourceMap::new(source_map::FilePathMapping::empty()))
156157
});
157158
Box::new(
158-
JsonEmitter::stderr(
159+
JsonEmitter::new(
160+
Box::new(io::BufWriter::new(io::stderr())),
159161
None,
160162
source_map,
161163
None,

0 commit comments

Comments
 (0)