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

Commit 87d2aa5

Browse files
Improve error emitting code
1 parent bbaa930 commit 87d2aa5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
//! ```
2727
2828
use rustc_data_structures::fx::FxHashMap;
29+
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
2930
use rustc_hir::def_id::DefId;
3031
use rustc_middle::ty::TyCtxt;
3132
pub(crate) use rustc_resolve::rustdoc::main_body_opts;
@@ -808,7 +809,7 @@ impl<'tcx> ExtraInfo<'tcx> {
808809
ExtraInfo { def_id, sp, tcx }
809810
}
810811

811-
fn error_invalid_codeblock_attr(&self, msg: &str) {
812+
fn error_invalid_codeblock_attr(&self, msg: impl Into<DiagnosticMessage>) {
812813
if let Some(def_id) = self.def_id.as_local() {
813814
self.tcx.struct_span_lint_hir(
814815
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
@@ -820,7 +821,11 @@ impl<'tcx> ExtraInfo<'tcx> {
820821
}
821822
}
822823

823-
fn error_invalid_codeblock_attr_with_help(&self, msg: &str, help: &str) {
824+
fn error_invalid_codeblock_attr_with_help(
825+
&self,
826+
msg: impl Into<DiagnosticMessage>,
827+
help: impl Into<SubdiagnosticMessage>,
828+
) {
824829
if let Some(def_id) = self.def_id.as_local() {
825830
self.tcx.struct_span_lint_hir(
826831
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
@@ -1246,7 +1251,7 @@ impl LangString {
12461251
} {
12471252
if let Some(extra) = extra {
12481253
extra.error_invalid_codeblock_attr_with_help(
1249-
&format!("unknown attribute `{}`. Did you mean `{}`?", x, flag),
1254+
format!("unknown attribute `{x}`. Did you mean `{flag}`?"),
12501255
help,
12511256
);
12521257
}
@@ -1263,9 +1268,8 @@ impl LangString {
12631268
if key == "class" {
12641269
data.added_classes.push(value.to_owned());
12651270
} else if let Some(extra) = extra {
1266-
extra.error_invalid_codeblock_attr(&format!(
1267-
"unsupported attribute `{key}`"
1268-
));
1271+
extra
1272+
.error_invalid_codeblock_attr(format!("unsupported attribute `{key}`"));
12691273
}
12701274
}
12711275
LangStringToken::ClassAttribute(class) => {

0 commit comments

Comments
 (0)