Auto merge of #113281 - dayo05:master, r=davidtwco
Implement diagnostic translation for rustc-errors This is my first PR to rustc yeah~ I'm going to implement diagnostic translation on rustc-errors crate. This PR is WIP, the reason of opening this as draft, I want to show my code to prevent the issue caused by misunderstanding and also I have few questions. Some error messages are processed by `pluralize!` macro which determines to use plural word or not. From now, I make two kinds of keys and combine with enum but I'm not sure is this best method to do it. Is there any prefered method to do this? => This resolved on conversation on PR. I'll remain to perform force-push until my first implementation looks good to me
This commit is contained in:
commit
f239bb6bea
3 changed files with 111 additions and 14 deletions
|
@ -22,6 +22,8 @@ extern crate rustc_macros;
|
|||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
extern crate self as rustc_errors;
|
||||
|
||||
pub use emitter::ColorConfig;
|
||||
|
||||
use rustc_lint_defs::LintExpectationId;
|
||||
|
@ -377,13 +379,16 @@ pub struct ExplicitBug;
|
|||
/// rather than a failed assertion, etc.
|
||||
pub struct DelayedBugPanic;
|
||||
|
||||
use crate::diagnostic_impls::{DelayedAtWithNewline, DelayedAtWithoutNewline};
|
||||
pub use diagnostic::{
|
||||
AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
|
||||
DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
|
||||
};
|
||||
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, Noted};
|
||||
pub use diagnostic_impls::{
|
||||
DiagnosticArgFromDisplay, DiagnosticSymbolList, LabelKind, SingleLabelManySpans,
|
||||
DiagnosticArgFromDisplay, DiagnosticSymbolList, ExpectedLifetimeParameter,
|
||||
IndicateAnonymousLifetime, InvalidFlushedDelayedDiagnosticLevel, LabelKind,
|
||||
SingleLabelManySpans,
|
||||
};
|
||||
use std::backtrace::{Backtrace, BacktraceStatus};
|
||||
|
||||
|
@ -1673,11 +1678,10 @@ impl HandlerInner {
|
|||
if bug.level != Level::DelayedBug {
|
||||
// NOTE(eddyb) not panicking here because we're already producing
|
||||
// an ICE, and the more information the merrier.
|
||||
bug.note(format!(
|
||||
"`flushed_delayed` got diagnostic with level {:?}, \
|
||||
instead of the expected `DelayedBug`",
|
||||
bug.level,
|
||||
));
|
||||
bug.subdiagnostic(InvalidFlushedDelayedDiagnosticLevel {
|
||||
span: bug.span.primary_span().unwrap(),
|
||||
level: bug.level,
|
||||
});
|
||||
}
|
||||
bug.level = Level::Bug;
|
||||
|
||||
|
@ -1744,12 +1748,22 @@ impl DelayedDiagnostic {
|
|||
fn decorate(mut self) -> Diagnostic {
|
||||
match self.note.status() {
|
||||
BacktraceStatus::Captured => {
|
||||
self.inner.note(format!("delayed at {}\n{}", self.inner.emitted_at, self.note));
|
||||
let inner = &self.inner;
|
||||
self.inner.subdiagnostic(DelayedAtWithNewline {
|
||||
span: inner.span.primary_span().unwrap(),
|
||||
emitted_at: inner.emitted_at.clone(),
|
||||
note: self.note,
|
||||
});
|
||||
}
|
||||
// Avoid the needless newline when no backtrace has been captured,
|
||||
// the display impl should just be a single line.
|
||||
_ => {
|
||||
self.inner.note(format!("delayed at {} - {}", self.inner.emitted_at, self.note));
|
||||
let inner = &self.inner;
|
||||
self.inner.subdiagnostic(DelayedAtWithoutNewline {
|
||||
span: inner.span.primary_span().unwrap(),
|
||||
emitted_at: inner.emitted_at.clone(),
|
||||
note: self.note,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1841,7 +1855,7 @@ pub fn add_elided_lifetime_in_path_suggestion(
|
|||
incl_angl_brckt: bool,
|
||||
insertion_span: Span,
|
||||
) {
|
||||
diag.span_label(path_span, format!("expected lifetime parameter{}", pluralize!(n)));
|
||||
diag.subdiagnostic(ExpectedLifetimeParameter { span: path_span, count: n });
|
||||
if !source_map.is_span_accessible(insertion_span) {
|
||||
// Do not try to suggest anything if generated by a proc-macro.
|
||||
return;
|
||||
|
@ -1849,12 +1863,12 @@ pub fn add_elided_lifetime_in_path_suggestion(
|
|||
let anon_lts = vec!["'_"; n].join(", ");
|
||||
let suggestion =
|
||||
if incl_angl_brckt { format!("<{}>", anon_lts) } else { format!("{}, ", anon_lts) };
|
||||
diag.span_suggestion_verbose(
|
||||
insertion_span.shrink_to_hi(),
|
||||
format!("indicate the anonymous lifetime{}", pluralize!(n)),
|
||||
|
||||
diag.subdiagnostic(IndicateAnonymousLifetime {
|
||||
span: insertion_span.shrink_to_hi(),
|
||||
count: n,
|
||||
suggestion,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue