From 87d2aa5fd34ab96f755fe69aed64083e8a246e09 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 4 May 2023 11:17:56 +0200 Subject: [PATCH] Improve error emitting code --- src/librustdoc/html/markdown.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 482e7b7f260..61dc4357c41 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -26,6 +26,7 @@ //! ``` use rustc_data_structures::fx::FxHashMap; +use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; use rustc_hir::def_id::DefId; use rustc_middle::ty::TyCtxt; pub(crate) use rustc_resolve::rustdoc::main_body_opts; @@ -808,7 +809,7 @@ pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: DefId, sp: Span) -> ExtraInfo<'tcx> ExtraInfo { def_id, sp, tcx } } - fn error_invalid_codeblock_attr(&self, msg: &str) { + fn error_invalid_codeblock_attr(&self, msg: impl Into) { if let Some(def_id) = self.def_id.as_local() { self.tcx.struct_span_lint_hir( crate::lint::INVALID_CODEBLOCK_ATTRIBUTES, @@ -820,7 +821,11 @@ fn error_invalid_codeblock_attr(&self, msg: &str) { } } - fn error_invalid_codeblock_attr_with_help(&self, msg: &str, help: &str) { + fn error_invalid_codeblock_attr_with_help( + &self, + msg: impl Into, + help: impl Into, + ) { if let Some(def_id) = self.def_id.as_local() { self.tcx.struct_span_lint_hir( crate::lint::INVALID_CODEBLOCK_ATTRIBUTES, @@ -1246,7 +1251,7 @@ fn parse( } { if let Some(extra) = extra { extra.error_invalid_codeblock_attr_with_help( - &format!("unknown attribute `{}`. Did you mean `{}`?", x, flag), + format!("unknown attribute `{x}`. Did you mean `{flag}`?"), help, ); } @@ -1263,9 +1268,8 @@ fn parse( if key == "class" { data.added_classes.push(value.to_owned()); } else if let Some(extra) = extra { - extra.error_invalid_codeblock_attr(&format!( - "unsupported attribute `{key}`" - )); + extra + .error_invalid_codeblock_attr(format!("unsupported attribute `{key}`")); } } LangStringToken::ClassAttribute(class) => {