mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
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<'_> {
|
||||
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
||||
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());
|
||||
|
||||
DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
|
||||
|
@ -116,7 +116,7 @@ pub struct Diagnostic {
|
||||
|
||||
/// With `-Ztrack_diagnostics` enabled,
|
||||
/// we print where in rustc this error was emitted.
|
||||
pub emitted_at: DiagnosticLocation,
|
||||
pub(crate) emitted_at: DiagnosticLocation,
|
||||
}
|
||||
|
||||
#[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 {
|
||||
#[track_caller]
|
||||
pub fn new<M: Into<DiagnosticMessage>>(level: Level, message: M) -> Self {
|
||||
@ -889,15 +886,6 @@ impl Diagnostic {
|
||||
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 {
|
||||
self.messages[0] = (msg.into(), Style::NoStyle);
|
||||
self
|
||||
@ -923,10 +911,6 @@ impl Diagnostic {
|
||||
self.args = args;
|
||||
}
|
||||
|
||||
pub fn messages(&self) -> &[(DiagnosticMessage, Style)] {
|
||||
&self.messages
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// passes the user's string along).
|
||||
|
@ -1422,7 +1422,7 @@ impl DiagCtxtInner {
|
||||
&mut out,
|
||||
"delayed span bug: {}\n{}\n",
|
||||
bug.inner
|
||||
.messages()
|
||||
.messages
|
||||
.iter()
|
||||
.filter_map(|(msg, _)| msg.as_str())
|
||||
.collect::<String>(),
|
||||
|
@ -590,7 +590,6 @@ fn infer_placeholder_type<'a>(
|
||||
|
||||
// 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.
|
||||
// FIXME(eddyb) this looks like it should be functionality on `Diagnostic`.
|
||||
if let Ok(suggestions) = &mut err.suggestions {
|
||||
suggestions.clear();
|
||||
}
|
||||
|
@ -576,7 +576,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
if (lhs, rhs).references_error() {
|
||||
err.downgrade_to_delayed_bug();
|
||||
}
|
||||
if self.tcx.sess.teach(err.get_code().unwrap()) {
|
||||
if self.tcx.sess.teach(err.code.unwrap()) {
|
||||
err.note(
|
||||
"In a match expression, only numbers and characters can be matched \
|
||||
against a range. This is because the compiler checks that the range \
|
||||
@ -847,7 +847,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
type_str
|
||||
);
|
||||
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);
|
||||
}
|
||||
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(
|
||||
"This error indicates that a struct pattern attempted to \
|
||||
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");
|
||||
if tcx.sess.teach(diag.get_code().unwrap()) {
|
||||
if tcx.sess.teach(diag.code.unwrap()) {
|
||||
diag.help(
|
||||
"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",
|
||||
);
|
||||
}
|
||||
if tcx.sess.teach(diag.get_code().unwrap()) {
|
||||
if tcx.sess.teach(diag.code.unwrap()) {
|
||||
diag.help(
|
||||
"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) =
|
||||
if name == sym::Send { ("`Send`", "sent") } else { ("`Sync`", "shared") };
|
||||
|
||||
err.clear_code();
|
||||
err.code = None;
|
||||
err.primary_message(format!(
|
||||
"{future_or_coroutine} cannot be {trait_verb} between threads safely"
|
||||
));
|
||||
|
Loading…
Reference in New Issue
Block a user