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.
This commit is contained in:
parent
067d7c3d00
commit
2999d8dc72
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// FIXME: spec the JSON output properly.
|
// FIXME: spec the JSON output properly.
|
||||||
|
|
||||||
use rustc_span::source_map::{FilePathMapping, SourceMap};
|
use rustc_span::source_map::SourceMap;
|
||||||
use termcolor::{ColorSpec, WriteColor};
|
use termcolor::{ColorSpec, WriteColor};
|
||||||
|
|
||||||
use crate::emitter::{
|
use crate::emitter::{
|
||||||
@ -56,60 +56,6 @@ pub struct JsonEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl JsonEmitter {
|
impl JsonEmitter {
|
||||||
pub fn stderr(
|
|
||||||
registry: Option<Registry>,
|
|
||||||
source_map: Lrc<SourceMap>,
|
|
||||||
fluent_bundle: Option<Lrc<FluentBundle>>,
|
|
||||||
fallback_bundle: LazyFallbackBundle,
|
|
||||||
pretty: bool,
|
|
||||||
json_rendered: HumanReadableErrorType,
|
|
||||||
diagnostic_width: Option<usize>,
|
|
||||||
macro_backtrace: bool,
|
|
||||||
track_diagnostics: bool,
|
|
||||||
terminal_url: TerminalUrl,
|
|
||||||
) -> JsonEmitter {
|
|
||||||
JsonEmitter {
|
|
||||||
dst: IntoDynSyncSend(Box::new(io::BufWriter::new(io::stderr()))),
|
|
||||||
registry,
|
|
||||||
sm: source_map,
|
|
||||||
fluent_bundle,
|
|
||||||
fallback_bundle,
|
|
||||||
pretty,
|
|
||||||
ui_testing: false,
|
|
||||||
ignored_directories_in_source_blocks: Vec::new(),
|
|
||||||
json_rendered,
|
|
||||||
diagnostic_width,
|
|
||||||
macro_backtrace,
|
|
||||||
track_diagnostics,
|
|
||||||
terminal_url,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn basic(
|
|
||||||
pretty: bool,
|
|
||||||
json_rendered: HumanReadableErrorType,
|
|
||||||
fluent_bundle: Option<Lrc<FluentBundle>>,
|
|
||||||
fallback_bundle: LazyFallbackBundle,
|
|
||||||
diagnostic_width: Option<usize>,
|
|
||||||
macro_backtrace: bool,
|
|
||||||
track_diagnostics: bool,
|
|
||||||
terminal_url: TerminalUrl,
|
|
||||||
) -> JsonEmitter {
|
|
||||||
let file_path_mapping = FilePathMapping::empty();
|
|
||||||
JsonEmitter::stderr(
|
|
||||||
None,
|
|
||||||
Lrc::new(SourceMap::new(file_path_mapping)),
|
|
||||||
fluent_bundle,
|
|
||||||
fallback_bundle,
|
|
||||||
pretty,
|
|
||||||
json_rendered,
|
|
||||||
diagnostic_width,
|
|
||||||
macro_backtrace,
|
|
||||||
track_diagnostics,
|
|
||||||
terminal_url,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
dst: Box<dyn Write + Send>,
|
dst: Box<dyn Write + Send>,
|
||||||
registry: Option<Registry>,
|
registry: Option<Registry>,
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
use rustc_macros::HashStable_Generic;
|
use rustc_macros::HashStable_Generic;
|
||||||
pub use rustc_span::def_id::StableCrateId;
|
pub use rustc_span::def_id::StableCrateId;
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::source_map::{FileLoader, RealFileLoader, SourceMap};
|
use rustc_span::source_map::{FileLoader, FilePathMapping, RealFileLoader, SourceMap};
|
||||||
use rustc_span::{SourceFileHashAlgorithm, Span, Symbol};
|
use rustc_span::{SourceFileHashAlgorithm, Span, Symbol};
|
||||||
use rustc_target::asm::InlineAsmArch;
|
use rustc_target::asm::InlineAsmArch;
|
||||||
use rustc_target::spec::{CodeModel, PanicStrategy, RelocModel, RelroLevel};
|
use rustc_target::spec::{CodeModel, PanicStrategy, RelocModel, RelroLevel};
|
||||||
@ -39,6 +39,7 @@
|
|||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::io;
|
||||||
use std::ops::{Div, Mul};
|
use std::ops::{Div, Mul};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@ -998,7 +999,8 @@ fn default_emitter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(
|
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(
|
||||||
JsonEmitter::stderr(
|
JsonEmitter::new(
|
||||||
|
Box::new(io::BufWriter::new(io::stderr())),
|
||||||
Some(registry),
|
Some(registry),
|
||||||
source_map,
|
source_map,
|
||||||
bundle,
|
bundle,
|
||||||
@ -1478,11 +1480,14 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
|
|||||||
.short_message(short),
|
.short_message(short),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic(
|
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::new(
|
||||||
pretty,
|
Box::new(io::BufWriter::new(io::stderr())),
|
||||||
json_rendered,
|
None,
|
||||||
|
Lrc::new(SourceMap::new(FilePathMapping::empty())),
|
||||||
None,
|
None,
|
||||||
fallback_bundle,
|
fallback_bundle,
|
||||||
|
pretty,
|
||||||
|
json_rendered,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
use rustc_span::{source_map, Span};
|
use rustc_span::{source_map, Span};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::io;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
@ -155,7 +156,8 @@ pub(crate) fn new_dcx(
|
|||||||
Lrc::new(source_map::SourceMap::new(source_map::FilePathMapping::empty()))
|
Lrc::new(source_map::SourceMap::new(source_map::FilePathMapping::empty()))
|
||||||
});
|
});
|
||||||
Box::new(
|
Box::new(
|
||||||
JsonEmitter::stderr(
|
JsonEmitter::new(
|
||||||
|
Box::new(io::BufWriter::new(io::stderr())),
|
||||||
None,
|
None,
|
||||||
source_map,
|
source_map,
|
||||||
None,
|
None,
|
||||||
|
Loading…
Reference in New Issue
Block a user