mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
Refactor: Rename db
locals to diag
https://github.com/rust-lang/rust/pull/64272 replaced `DiagnosticBuilder` with `Diagnostic` in some places. This commit just renames the DB variable from `db` to `diag` where it wasn't renamed.
This commit is contained in:
parent
e369d87b01
commit
6c75e81561
@ -1667,13 +1667,13 @@ impl SharedEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for SharedEmitter {
|
impl Emitter for SharedEmitter {
|
||||||
fn emit_diagnostic(&mut self, db: &rustc_errors::Diagnostic) {
|
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
|
||||||
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
||||||
msg: db.message(),
|
msg: diag.message(),
|
||||||
code: db.code.clone(),
|
code: diag.code.clone(),
|
||||||
lvl: db.level,
|
lvl: diag.level,
|
||||||
})));
|
})));
|
||||||
for child in &db.children {
|
for child in &diag.children {
|
||||||
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
||||||
msg: child.message(),
|
msg: child.message(),
|
||||||
code: None,
|
code: None,
|
||||||
|
@ -31,19 +31,19 @@ pub struct AnnotateSnippetEmitterWriter {
|
|||||||
|
|
||||||
impl Emitter for AnnotateSnippetEmitterWriter {
|
impl Emitter for AnnotateSnippetEmitterWriter {
|
||||||
/// The entry point for the diagnostics generation
|
/// The entry point for the diagnostics generation
|
||||||
fn emit_diagnostic(&mut self, db: &Diagnostic) {
|
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
|
||||||
let mut children = db.children.clone();
|
let mut children = diag.children.clone();
|
||||||
let (mut primary_span, suggestions) = self.primary_span_formatted(&db);
|
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
|
||||||
|
|
||||||
self.fix_multispans_in_std_macros(&self.source_map,
|
self.fix_multispans_in_std_macros(&self.source_map,
|
||||||
&mut primary_span,
|
&mut primary_span,
|
||||||
&mut children,
|
&mut children,
|
||||||
&db.level,
|
&diag.level,
|
||||||
self.external_macro_backtrace);
|
self.external_macro_backtrace);
|
||||||
|
|
||||||
self.emit_messages_default(&db.level,
|
self.emit_messages_default(&diag.level,
|
||||||
db.message(),
|
diag.message(),
|
||||||
&db.code,
|
&diag.code,
|
||||||
&primary_span,
|
&primary_span,
|
||||||
&children,
|
&children,
|
||||||
&suggestions);
|
&suggestions);
|
||||||
|
@ -180,7 +180,7 @@ const ANONYMIZED_LINE_NUM: &str = "LL";
|
|||||||
/// Emitter trait for emitting errors.
|
/// Emitter trait for emitting errors.
|
||||||
pub trait Emitter {
|
pub trait Emitter {
|
||||||
/// Emit a structured diagnostic.
|
/// Emit a structured diagnostic.
|
||||||
fn emit_diagnostic(&mut self, db: &Diagnostic);
|
fn emit_diagnostic(&mut self, diag: &Diagnostic);
|
||||||
|
|
||||||
/// Emit a notification that an artifact has been output.
|
/// Emit a notification that an artifact has been output.
|
||||||
/// This is currently only supported for the JSON format,
|
/// This is currently only supported for the JSON format,
|
||||||
@ -206,10 +206,10 @@ pub trait Emitter {
|
|||||||
/// we return the original `primary_span` and the original suggestions.
|
/// we return the original `primary_span` and the original suggestions.
|
||||||
fn primary_span_formatted<'a>(
|
fn primary_span_formatted<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
db: &'a Diagnostic,
|
diag: &'a Diagnostic,
|
||||||
) -> (MultiSpan, &'a [CodeSuggestion]) {
|
) -> (MultiSpan, &'a [CodeSuggestion]) {
|
||||||
let mut primary_span = db.span.clone();
|
let mut primary_span = diag.span.clone();
|
||||||
if let Some((sugg, rest)) = db.suggestions.split_first() {
|
if let Some((sugg, rest)) = diag.suggestions.split_first() {
|
||||||
if rest.is_empty() &&
|
if rest.is_empty() &&
|
||||||
// ^ if there is only one suggestion
|
// ^ if there is only one suggestion
|
||||||
// don't display multi-suggestions as labels
|
// don't display multi-suggestions as labels
|
||||||
@ -260,10 +260,10 @@ pub trait Emitter {
|
|||||||
// to be consistent. We could try to figure out if we can
|
// to be consistent. We could try to figure out if we can
|
||||||
// make one (or the first one) inline, but that would give
|
// make one (or the first one) inline, but that would give
|
||||||
// undue importance to a semi-random suggestion
|
// undue importance to a semi-random suggestion
|
||||||
(primary_span, &db.suggestions)
|
(primary_span, &diag.suggestions)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(primary_span, &db.suggestions)
|
(primary_span, &diag.suggestions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,19 +401,19 @@ impl Emitter for EmitterWriter {
|
|||||||
self.sm.as_ref()
|
self.sm.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_diagnostic(&mut self, db: &Diagnostic) {
|
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
|
||||||
let mut children = db.children.clone();
|
let mut children = diag.children.clone();
|
||||||
let (mut primary_span, suggestions) = self.primary_span_formatted(&db);
|
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
|
||||||
|
|
||||||
self.fix_multispans_in_std_macros(&self.sm,
|
self.fix_multispans_in_std_macros(&self.sm,
|
||||||
&mut primary_span,
|
&mut primary_span,
|
||||||
&mut children,
|
&mut children,
|
||||||
&db.level,
|
&diag.level,
|
||||||
self.external_macro_backtrace);
|
self.external_macro_backtrace);
|
||||||
|
|
||||||
self.emit_messages_default(&db.level,
|
self.emit_messages_default(&diag.level,
|
||||||
&db.styled_message(),
|
&diag.styled_message(),
|
||||||
&db.code,
|
&diag.code,
|
||||||
&primary_span,
|
&primary_span,
|
||||||
&children,
|
&children,
|
||||||
&suggestions);
|
&suggestions);
|
||||||
|
@ -89,8 +89,8 @@ impl JsonEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for JsonEmitter {
|
impl Emitter for JsonEmitter {
|
||||||
fn emit_diagnostic(&mut self, db: &errors::Diagnostic) {
|
fn emit_diagnostic(&mut self, diag: &errors::Diagnostic) {
|
||||||
let data = Diagnostic::from_errors_diagnostic(db, self);
|
let data = Diagnostic::from_errors_diagnostic(diag, self);
|
||||||
let result = if self.pretty {
|
let result = if self.pretty {
|
||||||
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
|
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
|
||||||
} else {
|
} else {
|
||||||
@ -209,10 +209,10 @@ struct ArtifactNotification<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic {
|
impl Diagnostic {
|
||||||
fn from_errors_diagnostic(db: &errors::Diagnostic,
|
fn from_errors_diagnostic(diag: &errors::Diagnostic,
|
||||||
je: &JsonEmitter)
|
je: &JsonEmitter)
|
||||||
-> Diagnostic {
|
-> Diagnostic {
|
||||||
let sugg = db.suggestions.iter().map(|sugg| {
|
let sugg = diag.suggestions.iter().map(|sugg| {
|
||||||
Diagnostic {
|
Diagnostic {
|
||||||
message: sugg.msg.clone(),
|
message: sugg.msg.clone(),
|
||||||
code: None,
|
code: None,
|
||||||
@ -241,30 +241,30 @@ impl Diagnostic {
|
|||||||
let output = buf.clone();
|
let output = buf.clone();
|
||||||
je.json_rendered.new_emitter(
|
je.json_rendered.new_emitter(
|
||||||
Box::new(buf), Some(je.sm.clone()), false, None, je.external_macro_backtrace
|
Box::new(buf), Some(je.sm.clone()), false, None, je.external_macro_backtrace
|
||||||
).ui_testing(je.ui_testing).emit_diagnostic(db);
|
).ui_testing(je.ui_testing).emit_diagnostic(diag);
|
||||||
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
|
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
|
||||||
let output = String::from_utf8(output).unwrap();
|
let output = String::from_utf8(output).unwrap();
|
||||||
|
|
||||||
Diagnostic {
|
Diagnostic {
|
||||||
message: db.message(),
|
message: diag.message(),
|
||||||
code: DiagnosticCode::map_opt_string(db.code.clone(), je),
|
code: DiagnosticCode::map_opt_string(diag.code.clone(), je),
|
||||||
level: db.level.to_str(),
|
level: diag.level.to_str(),
|
||||||
spans: DiagnosticSpan::from_multispan(&db.span, je),
|
spans: DiagnosticSpan::from_multispan(&diag.span, je),
|
||||||
children: db.children.iter().map(|c| {
|
children: diag.children.iter().map(|c| {
|
||||||
Diagnostic::from_sub_diagnostic(c, je)
|
Diagnostic::from_sub_diagnostic(c, je)
|
||||||
}).chain(sugg).collect(),
|
}).chain(sugg).collect(),
|
||||||
rendered: Some(output),
|
rendered: Some(output),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_sub_diagnostic(db: &SubDiagnostic, je: &JsonEmitter) -> Diagnostic {
|
fn from_sub_diagnostic(diag: &SubDiagnostic, je: &JsonEmitter) -> Diagnostic {
|
||||||
Diagnostic {
|
Diagnostic {
|
||||||
message: db.message(),
|
message: diag.message(),
|
||||||
code: None,
|
code: None,
|
||||||
level: db.level.to_str(),
|
level: diag.level.to_str(),
|
||||||
spans: db.render_span.as_ref()
|
spans: diag.render_span.as_ref()
|
||||||
.map(|sp| DiagnosticSpan::from_multispan(sp, je))
|
.map(|sp| DiagnosticSpan::from_multispan(sp, je))
|
||||||
.unwrap_or_else(|| DiagnosticSpan::from_multispan(&db.span, je)),
|
.unwrap_or_else(|| DiagnosticSpan::from_multispan(&diag.span, je)),
|
||||||
children: vec![],
|
children: vec![],
|
||||||
rendered: None,
|
rendered: None,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user