Diagnostic
cleanups
- `emitted_at` isn't used outside the crate. - `code` and `messages` are public fields, so there's no point have trivial getters/setters for them. - `suggestions` is public, so the comment about "functionality on `Diagnostic`" isn't needed.
This commit is contained in:
parent
585367f15f
commit
a9a2e1565a
@ -102,7 +102,7 @@ pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
|
|||||||
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {
|
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {
|
||||||
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
||||||
let diag: DiagnosticBuilder<'_, G> = self.0.into_diagnostic(dcx, level);
|
let diag: DiagnosticBuilder<'_, G> = self.0.into_diagnostic(dcx, level);
|
||||||
let (message, _) = diag.messages().first().expect("`LlvmError` with no message");
|
let (message, _) = diag.messages.first().expect("`LlvmError` with no message");
|
||||||
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args());
|
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args());
|
||||||
|
|
||||||
DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
|
DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
|
||||||
|
@ -116,7 +116,7 @@ pub struct Diagnostic {
|
|||||||
|
|
||||||
/// With `-Ztrack_diagnostics` enabled,
|
/// With `-Ztrack_diagnostics` enabled,
|
||||||
/// we print where in rustc this error was emitted.
|
/// we print where in rustc this error was emitted.
|
||||||
pub emitted_at: DiagnosticLocation,
|
pub(crate) emitted_at: DiagnosticLocation,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Encodable, Decodable)]
|
#[derive(Clone, Debug, Encodable, Decodable)]
|
||||||
@ -206,9 +206,6 @@ impl StringPart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: most of these methods are setters that return `&mut Self`. The small
|
|
||||||
// number of simple getter functions all have `get_` prefixes to distinguish
|
|
||||||
// them from the setters.
|
|
||||||
impl Diagnostic {
|
impl Diagnostic {
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn new<M: Into<DiagnosticMessage>>(level: Level, message: M) -> Self {
|
pub fn new<M: Into<DiagnosticMessage>>(level: Level, message: M) -> Self {
|
||||||
@ -889,15 +886,6 @@ impl Diagnostic {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_code(&mut self) -> &mut Self {
|
|
||||||
self.code = None;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_code(&self) -> Option<ErrCode> {
|
|
||||||
self.code
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self {
|
pub fn primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self {
|
||||||
self.messages[0] = (msg.into(), Style::NoStyle);
|
self.messages[0] = (msg.into(), Style::NoStyle);
|
||||||
self
|
self
|
||||||
@ -923,10 +911,6 @@ impl Diagnostic {
|
|||||||
self.args = args;
|
self.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn messages(&self) -> &[(DiagnosticMessage, Style)] {
|
|
||||||
&self.messages
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by
|
/// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by
|
||||||
/// combining it with the primary message of the diagnostic (if translatable, otherwise it just
|
/// combining it with the primary message of the diagnostic (if translatable, otherwise it just
|
||||||
/// passes the user's string along).
|
/// passes the user's string along).
|
||||||
|
@ -1422,7 +1422,7 @@ impl DiagCtxtInner {
|
|||||||
&mut out,
|
&mut out,
|
||||||
"delayed span bug: {}\n{}\n",
|
"delayed span bug: {}\n{}\n",
|
||||||
bug.inner
|
bug.inner
|
||||||
.messages()
|
.messages
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(msg, _)| msg.as_str())
|
.filter_map(|(msg, _)| msg.as_str())
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
|
@ -590,7 +590,6 @@ fn infer_placeholder_type<'a>(
|
|||||||
|
|
||||||
// The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
|
// The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
|
||||||
// We are typeck and have the real type, so remove that and suggest the actual type.
|
// We are typeck and have the real type, so remove that and suggest the actual type.
|
||||||
// FIXME(eddyb) this looks like it should be functionality on `Diagnostic`.
|
|
||||||
if let Ok(suggestions) = &mut err.suggestions {
|
if let Ok(suggestions) = &mut err.suggestions {
|
||||||
suggestions.clear();
|
suggestions.clear();
|
||||||
}
|
}
|
||||||
|
@ -576,7 +576,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
if (lhs, rhs).references_error() {
|
if (lhs, rhs).references_error() {
|
||||||
err.downgrade_to_delayed_bug();
|
err.downgrade_to_delayed_bug();
|
||||||
}
|
}
|
||||||
if self.tcx.sess.teach(err.get_code().unwrap()) {
|
if self.tcx.sess.teach(err.code.unwrap()) {
|
||||||
err.note(
|
err.note(
|
||||||
"In a match expression, only numbers and characters can be matched \
|
"In a match expression, only numbers and characters can be matched \
|
||||||
against a range. This is because the compiler checks that the range \
|
against a range. This is because the compiler checks that the range \
|
||||||
@ -847,7 +847,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
type_str
|
type_str
|
||||||
);
|
);
|
||||||
err.span_label(span, format!("type `{type_str}` cannot be dereferenced"));
|
err.span_label(span, format!("type `{type_str}` cannot be dereferenced"));
|
||||||
if self.tcx.sess.teach(err.get_code().unwrap()) {
|
if self.tcx.sess.teach(err.code.unwrap()) {
|
||||||
err.note(CANNOT_IMPLICITLY_DEREF_POINTER_TRAIT_OBJ);
|
err.note(CANNOT_IMPLICITLY_DEREF_POINTER_TRAIT_OBJ);
|
||||||
}
|
}
|
||||||
return Err(err.emit());
|
return Err(err.emit());
|
||||||
@ -1669,7 +1669,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if tcx.sess.teach(err.get_code().unwrap()) {
|
if tcx.sess.teach(err.code.unwrap()) {
|
||||||
err.note(
|
err.note(
|
||||||
"This error indicates that a struct pattern attempted to \
|
"This error indicates that a struct pattern attempted to \
|
||||||
extract a nonexistent field from a struct. Struct fields \
|
extract a nonexistent field from a struct. Struct fields \
|
||||||
|
@ -195,7 +195,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
diag.help("type parameters must be constrained to match other types");
|
diag.help("type parameters must be constrained to match other types");
|
||||||
if tcx.sess.teach(diag.get_code().unwrap()) {
|
if tcx.sess.teach(diag.code.unwrap()) {
|
||||||
diag.help(
|
diag.help(
|
||||||
"given a type parameter `T` and a method `foo`:
|
"given a type parameter `T` and a method `foo`:
|
||||||
```
|
```
|
||||||
@ -678,7 +678,7 @@ impl<T> Trait<T> for X {
|
|||||||
https://doc.rust-lang.org/book/ch19-03-advanced-traits.html",
|
https://doc.rust-lang.org/book/ch19-03-advanced-traits.html",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if tcx.sess.teach(diag.get_code().unwrap()) {
|
if tcx.sess.teach(diag.code.unwrap()) {
|
||||||
diag.help(
|
diag.help(
|
||||||
"given an associated type `T` and a method `foo`:
|
"given an associated type `T` and a method `foo`:
|
||||||
```
|
```
|
||||||
|
@ -2717,7 +2717,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
let (trait_name, trait_verb) =
|
let (trait_name, trait_verb) =
|
||||||
if name == sym::Send { ("`Send`", "sent") } else { ("`Sync`", "shared") };
|
if name == sym::Send { ("`Send`", "sent") } else { ("`Sync`", "shared") };
|
||||||
|
|
||||||
err.clear_code();
|
err.code = None;
|
||||||
err.primary_message(format!(
|
err.primary_message(format!(
|
||||||
"{future_or_coroutine} cannot be {trait_verb} between threads safely"
|
"{future_or_coroutine} cannot be {trait_verb} between threads safely"
|
||||||
));
|
));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user