Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit a9a2e15

Browse files
committed
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.
1 parent 585367f commit a9a2e15

File tree

7 files changed

+9
-26
lines changed

7 files changed

+9
-26
lines changed

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
102102
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {
103103
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
104104
let diag: DiagnosticBuilder<'_, G> = self.0.into_diagnostic(dcx, level);
105-
let (message, _) = diag.messages().first().expect("`LlvmError` with no message");
105+
let (message, _) = diag.messages.first().expect("`LlvmError` with no message");
106106
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args());
107107

108108
DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub struct Diagnostic {
116116

117117
/// With `-Ztrack_diagnostics` enabled,
118118
/// we print where in rustc this error was emitted.
119-
pub emitted_at: DiagnosticLocation,
119+
pub(crate) emitted_at: DiagnosticLocation,
120120
}
121121

122122
#[derive(Clone, Debug, Encodable, Decodable)]
@@ -206,9 +206,6 @@ impl StringPart {
206206
}
207207
}
208208

209-
// Note: most of these methods are setters that return `&mut Self`. The small
210-
// number of simple getter functions all have `get_` prefixes to distinguish
211-
// them from the setters.
212209
impl Diagnostic {
213210
#[track_caller]
214211
pub fn new<M: Into<DiagnosticMessage>>(level: Level, message: M) -> Self {
@@ -889,15 +886,6 @@ impl Diagnostic {
889886
self
890887
}
891888

892-
pub fn clear_code(&mut self) -> &mut Self {
893-
self.code = None;
894-
self
895-
}
896-
897-
pub fn get_code(&self) -> Option<ErrCode> {
898-
self.code
899-
}
900-
901889
pub fn primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self {
902890
self.messages[0] = (msg.into(), Style::NoStyle);
903891
self
@@ -923,10 +911,6 @@ impl Diagnostic {
923911
self.args = args;
924912
}
925913

926-
pub fn messages(&self) -> &[(DiagnosticMessage, Style)] {
927-
&self.messages
928-
}
929-
930914
/// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by
931915
/// combining it with the primary message of the diagnostic (if translatable, otherwise it just
932916
/// passes the user's string along).

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ impl DiagCtxtInner {
14221422
&mut out,
14231423
"delayed span bug: {}\n{}\n",
14241424
bug.inner
1425-
.messages()
1425+
.messages
14261426
.iter()
14271427
.filter_map(|(msg, _)| msg.as_str())
14281428
.collect::<String>(),

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ fn infer_placeholder_type<'a>(
590590

591591
// The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
592592
// We are typeck and have the real type, so remove that and suggest the actual type.
593-
// FIXME(eddyb) this looks like it should be functionality on `Diagnostic`.
594593
if let Ok(suggestions) = &mut err.suggestions {
595594
suggestions.clear();
596595
}

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
576576
if (lhs, rhs).references_error() {
577577
err.downgrade_to_delayed_bug();
578578
}
579-
if self.tcx.sess.teach(err.get_code().unwrap()) {
579+
if self.tcx.sess.teach(err.code.unwrap()) {
580580
err.note(
581581
"In a match expression, only numbers and characters can be matched \
582582
against a range. This is because the compiler checks that the range \
@@ -847,7 +847,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
847847
type_str
848848
);
849849
err.span_label(span, format!("type `{type_str}` cannot be dereferenced"));
850-
if self.tcx.sess.teach(err.get_code().unwrap()) {
850+
if self.tcx.sess.teach(err.code.unwrap()) {
851851
err.note(CANNOT_IMPLICITLY_DEREF_POINTER_TRAIT_OBJ);
852852
}
853853
return Err(err.emit());
@@ -1669,7 +1669,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16691669
}
16701670
}
16711671
}
1672-
if tcx.sess.teach(err.get_code().unwrap()) {
1672+
if tcx.sess.teach(err.code.unwrap()) {
16731673
err.note(
16741674
"This error indicates that a struct pattern attempted to \
16751675
extract a nonexistent field from a struct. Struct fields \

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
195195
}
196196
}
197197
diag.help("type parameters must be constrained to match other types");
198-
if tcx.sess.teach(diag.get_code().unwrap()) {
198+
if tcx.sess.teach(diag.code.unwrap()) {
199199
diag.help(
200200
"given a type parameter `T` and a method `foo`:
201201
```
@@ -678,7 +678,7 @@ impl<T> Trait<T> for X {
678678
https://doc.rust-lang.org/book/ch19-03-advanced-traits.html",
679679
);
680680
}
681-
if tcx.sess.teach(diag.get_code().unwrap()) {
681+
if tcx.sess.teach(diag.code.unwrap()) {
682682
diag.help(
683683
"given an associated type `T` and a method `foo`:
684684
```

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2717,7 +2717,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
27172717
let (trait_name, trait_verb) =
27182718
if name == sym::Send { ("`Send`", "sent") } else { ("`Sync`", "shared") };
27192719

2720-
err.clear_code();
2720+
err.code = None;
27212721
err.primary_message(format!(
27222722
"{future_or_coroutine} cannot be {trait_verb} between threads safely"
27232723
));

0 commit comments

Comments
 (0)