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:
Philipp Hansch 2019-10-15 08:12:55 +02:00
parent e369d87b01
commit 6c75e81561
No known key found for this signature in database
GPG Key ID: 82AA61CAA11397E6
4 changed files with 40 additions and 40 deletions

View File

@ -1667,13 +1667,13 @@ impl 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 {
msg: db.message(),
code: db.code.clone(),
lvl: db.level,
msg: diag.message(),
code: diag.code.clone(),
lvl: diag.level,
})));
for child in &db.children {
for child in &diag.children {
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
msg: child.message(),
code: None,

View File

@ -31,19 +31,19 @@ pub struct AnnotateSnippetEmitterWriter {
impl Emitter for AnnotateSnippetEmitterWriter {
/// The entry point for the diagnostics generation
fn emit_diagnostic(&mut self, db: &Diagnostic) {
let mut children = db.children.clone();
let (mut primary_span, suggestions) = self.primary_span_formatted(&db);
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
let mut children = diag.children.clone();
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
self.fix_multispans_in_std_macros(&self.source_map,
&mut primary_span,
&mut children,
&db.level,
&diag.level,
self.external_macro_backtrace);
self.emit_messages_default(&db.level,
db.message(),
&db.code,
self.emit_messages_default(&diag.level,
diag.message(),
&diag.code,
&primary_span,
&children,
&suggestions);

View File

@ -180,7 +180,7 @@ const ANONYMIZED_LINE_NUM: &str = "LL";
/// Emitter trait for emitting errors.
pub trait Emitter {
/// 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.
/// 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.
fn primary_span_formatted<'a>(
&mut self,
db: &'a Diagnostic,
diag: &'a Diagnostic,
) -> (MultiSpan, &'a [CodeSuggestion]) {
let mut primary_span = db.span.clone();
if let Some((sugg, rest)) = db.suggestions.split_first() {
let mut primary_span = diag.span.clone();
if let Some((sugg, rest)) = diag.suggestions.split_first() {
if rest.is_empty() &&
// ^ if there is only one suggestion
// 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
// make one (or the first one) inline, but that would give
// undue importance to a semi-random suggestion
(primary_span, &db.suggestions)
(primary_span, &diag.suggestions)
}
} else {
(primary_span, &db.suggestions)
(primary_span, &diag.suggestions)
}
}
@ -401,19 +401,19 @@ impl Emitter for EmitterWriter {
self.sm.as_ref()
}
fn emit_diagnostic(&mut self, db: &Diagnostic) {
let mut children = db.children.clone();
let (mut primary_span, suggestions) = self.primary_span_formatted(&db);
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
let mut children = diag.children.clone();
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
self.fix_multispans_in_std_macros(&self.sm,
&mut primary_span,
&mut children,
&db.level,
&diag.level,
self.external_macro_backtrace);
self.emit_messages_default(&db.level,
&db.styled_message(),
&db.code,
self.emit_messages_default(&diag.level,
&diag.styled_message(),
&diag.code,
&primary_span,
&children,
&suggestions);

View File

@ -89,8 +89,8 @@ impl JsonEmitter {
}
impl Emitter for JsonEmitter {
fn emit_diagnostic(&mut self, db: &errors::Diagnostic) {
let data = Diagnostic::from_errors_diagnostic(db, self);
fn emit_diagnostic(&mut self, diag: &errors::Diagnostic) {
let data = Diagnostic::from_errors_diagnostic(diag, self);
let result = if self.pretty {
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
} else {
@ -209,10 +209,10 @@ struct ArtifactNotification<'a> {
}
impl Diagnostic {
fn from_errors_diagnostic(db: &errors::Diagnostic,
fn from_errors_diagnostic(diag: &errors::Diagnostic,
je: &JsonEmitter)
-> Diagnostic {
let sugg = db.suggestions.iter().map(|sugg| {
let sugg = diag.suggestions.iter().map(|sugg| {
Diagnostic {
message: sugg.msg.clone(),
code: None,
@ -241,30 +241,30 @@ impl Diagnostic {
let output = buf.clone();
je.json_rendered.new_emitter(
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 = String::from_utf8(output).unwrap();
Diagnostic {
message: db.message(),
code: DiagnosticCode::map_opt_string(db.code.clone(), je),
level: db.level.to_str(),
spans: DiagnosticSpan::from_multispan(&db.span, je),
children: db.children.iter().map(|c| {
message: diag.message(),
code: DiagnosticCode::map_opt_string(diag.code.clone(), je),
level: diag.level.to_str(),
spans: DiagnosticSpan::from_multispan(&diag.span, je),
children: diag.children.iter().map(|c| {
Diagnostic::from_sub_diagnostic(c, je)
}).chain(sugg).collect(),
rendered: Some(output),
}
}
fn from_sub_diagnostic(db: &SubDiagnostic, je: &JsonEmitter) -> Diagnostic {
fn from_sub_diagnostic(diag: &SubDiagnostic, je: &JsonEmitter) -> Diagnostic {
Diagnostic {
message: db.message(),
message: diag.message(),
code: None,
level: db.level.to_str(),
spans: db.render_span.as_ref()
level: diag.level.to_str(),
spans: diag.render_span.as_ref()
.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![],
rendered: None,
}