diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2023-05-18 10:52:35 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-18 10:52:35 +0530 |
| commit | 08efb9d652c840715d15954592426e2befe13b36 (patch) | |
| tree | aa97bae80b39c4e36910dd711e499002f5ab59cd /src/librustdoc | |
| parent | cdfaf69498e339b02a90193cc842eed462c8e589 (diff) | |
| parent | 01e33a3600789b0e96511c4ac95fc114b507c79e (diff) | |
| download | rust-08efb9d652c840715d15954592426e2befe13b36.tar.gz rust-08efb9d652c840715d15954592426e2befe13b36.zip | |
Rollup merge of #111633 - nnethercote:avoid-ref-format, r=WaffleLapkin
Avoid `&format("...")` calls in error message code.
Some error message cleanups. Best reviewed one commit at a time.
r? `@davidtwco`
Diffstat (limited to 'src/librustdoc')
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 8 | ||||
| -rw-r--r-- | src/librustdoc/passes/collect_intra_doc_links.rs | 25 |
3 files changed, 19 insertions, 18 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 4b0aee9c3ad..c9957e8e39c 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -773,7 +773,7 @@ impl<'tcx> ExtraInfo<'tcx> { ExtraInfo { def_id, sp, tcx } } - fn error_invalid_codeblock_attr(&self, msg: &str, help: &str) { + fn error_invalid_codeblock_attr(&self, msg: String, help: &str) { if let Some(def_id) = self.def_id.as_local() { self.tcx.struct_span_lint_hir( crate::lint::INVALID_CODEBLOCK_ATTRIBUTES, @@ -948,7 +948,7 @@ impl LangString { } { if let Some(extra) = extra { extra.error_invalid_codeblock_attr( - &format!("unknown attribute `{}`. Did you mean `{}`?", x, flag), + format!("unknown attribute `{}`. Did you mean `{}`?", x, flag), help, ); } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 5460bce21a5..0a56916edcd 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -192,11 +192,11 @@ fn init_logging() { Ok("auto") | Err(VarError::NotPresent) => io::stdout().is_terminal(), Ok(value) => early_error( ErrorOutputType::default(), - &format!("invalid log color value '{}': expected one of always, never, or auto", value), + format!("invalid log color value '{}': expected one of always, never, or auto", value), ), Err(VarError::NotUnicode(value)) => early_error( ErrorOutputType::default(), - &format!( + format!( "invalid log color value '{}': expected one of always, never, or auto", value.to_string_lossy() ), @@ -228,7 +228,7 @@ fn get_args() -> Option<Vec<String>> { .map_err(|arg| { early_warn( ErrorOutputType::default(), - &format!("Argument {} is not valid Unicode: {:?}", i, arg), + format!("Argument {} is not valid Unicode: {:?}", i, arg), ); }) .ok() @@ -721,7 +721,7 @@ fn main_args(at_args: &[String]) -> MainResult { let matches = match options.parse(&args[1..]) { Ok(m) => m, Err(err) => { - early_error(ErrorOutputType::default(), &err.to_string()); + early_error(ErrorOutputType::default(), err.to_string()); } }; diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index a885ff0ca5e..9381b3e0567 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -8,7 +8,7 @@ use rustc_data_structures::{ fx::{FxHashMap, FxHashSet}, intern::Interned, }; -use rustc_errors::{Applicability, Diagnostic}; +use rustc_errors::{Applicability, Diagnostic, DiagnosticMessage}; use rustc_hir::def::Namespace::*; use rustc_hir::def::{DefKind, Namespace, PerNS}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; @@ -24,6 +24,7 @@ use rustc_span::BytePos; use smallvec::{smallvec, SmallVec}; use std::borrow::Cow; +use std::fmt::Display; use std::mem; use std::ops::Range; @@ -841,7 +842,7 @@ impl PreprocessingError { match self { PreprocessingError::MultipleAnchors => report_multiple_anchors(cx, diag_info), PreprocessingError::Disambiguator(range, msg) => { - disambiguator_error(cx, diag_info, range.clone(), msg) + disambiguator_error(cx, diag_info, range.clone(), msg.as_str()) } PreprocessingError::MalformedGenerics(err, path_str) => { report_malformed_generics(cx, diag_info, *err, path_str) @@ -1185,7 +1186,7 @@ impl LinkCollector<'_, '_> { } suggest_disambiguator(resolved, diag, path_str, &ori_link.link, sp); }; - report_diagnostic(self.cx.tcx, BROKEN_INTRA_DOC_LINKS, &msg, diag_info, callback); + report_diagnostic(self.cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, diag_info, callback); } fn report_rawptr_assoc_feature_gate(&self, dox: &str, ori_link: &Range<usize>, item: &Item) { @@ -1581,7 +1582,7 @@ impl Suggestion { fn report_diagnostic( tcx: TyCtxt<'_>, lint: &'static Lint, - msg: &str, + msg: impl Into<DiagnosticMessage> + Display, DiagnosticInfo { item, ori_link: _, dox, link_range }: &DiagnosticInfo<'_>, decorate: impl FnOnce(&mut Diagnostic, Option<rustc_span::Span>), ) { @@ -1649,7 +1650,7 @@ fn resolution_failure( report_diagnostic( tcx, BROKEN_INTRA_DOC_LINKS, - &format!("unresolved link to `{}`", path_str), + format!("unresolved link to `{}`", path_str), &diag_info, |diag, sp| { let item = |res: Res| format!("the {} `{}`", res.descr(), res.name(tcx),); @@ -1865,20 +1866,20 @@ fn resolution_failure( fn report_multiple_anchors(cx: &DocContext<'_>, diag_info: DiagnosticInfo<'_>) { let msg = format!("`{}` contains multiple anchors", diag_info.ori_link); - anchor_failure(cx, diag_info, &msg, 1) + anchor_failure(cx, diag_info, msg, 1) } fn report_anchor_conflict(cx: &DocContext<'_>, diag_info: DiagnosticInfo<'_>, def_id: DefId) { let (link, kind) = (diag_info.ori_link, Res::from_def_id(cx.tcx, def_id).descr()); let msg = format!("`{link}` contains an anchor, but links to {kind}s are already anchored"); - anchor_failure(cx, diag_info, &msg, 0) + anchor_failure(cx, diag_info, msg, 0) } /// Report an anchor failure. fn anchor_failure( cx: &DocContext<'_>, diag_info: DiagnosticInfo<'_>, - msg: &str, + msg: String, anchor_idx: usize, ) { report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |diag, sp| { @@ -1898,7 +1899,7 @@ fn disambiguator_error( cx: &DocContext<'_>, mut diag_info: DiagnosticInfo<'_>, disambiguator_range: Range<usize>, - msg: &str, + msg: impl Into<DiagnosticMessage> + Display, ) { diag_info.link_range = disambiguator_range; report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |diag, _sp| { @@ -1919,7 +1920,7 @@ fn report_malformed_generics( report_diagnostic( cx.tcx, BROKEN_INTRA_DOC_LINKS, - &format!("unresolved link to `{}`", path_str), + format!("unresolved link to `{}`", path_str), &diag_info, |diag, sp| { let note = match err { @@ -1994,7 +1995,7 @@ fn ambiguity_error( } } - report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, &msg, diag_info, |diag, sp| { + report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, diag_info, |diag, sp| { if let Some(sp) = sp { diag.span_label(sp, "ambiguous link"); } else { @@ -2046,7 +2047,7 @@ fn privacy_error(cx: &DocContext<'_>, diag_info: &DiagnosticInfo<'_>, path_str: let msg = format!("public documentation for `{}` links to private item `{}`", item_name, path_str); - report_diagnostic(cx.tcx, PRIVATE_INTRA_DOC_LINKS, &msg, diag_info, |diag, sp| { + report_diagnostic(cx.tcx, PRIVATE_INTRA_DOC_LINKS, msg, diag_info, |diag, sp| { if let Some(sp) = sp { diag.span_label(sp, "this item is private"); } |
