Skip to content

Commit 4e96aba

Browse files
authored
Rollup merge of rust-lang#112933 - TaKO8Ki:avoid-&format-in-error-message-code, r=oli-obk
Avoid `&format` in error message code follow-up of rust-lang#111633
2 parents 3feee9f + c896062 commit 4e96aba

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

compiler/rustc_borrowck/src/borrowck_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
278278
move_from_span: Span,
279279
move_from_desc: &str,
280280
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
281-
struct_span_err!(self, move_from_span, E0507, "cannot move out of {}", move_from_desc,)
281+
struct_span_err!(self, move_from_span, E0507, "cannot move out of {}", move_from_desc)
282282
}
283283

284284
/// Signal an error due to an attempt to move out of the interior

compiler/rustc_macros/src/diagnostics/error.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn path_to_string(path: &syn::Path) -> String {
5454

5555
/// Returns an error diagnostic on span `span` with msg `msg`.
5656
#[must_use]
57-
pub(crate) fn span_err(span: impl MultiSpan, msg: &str) -> Diagnostic {
57+
pub(crate) fn span_err<T: Into<String>>(span: impl MultiSpan, msg: T) -> Diagnostic {
5858
Diagnostic::spanned(span, Level::Error, msg)
5959
}
6060

@@ -77,11 +77,9 @@ pub(crate) fn invalid_attr(attr: &Attribute) -> Diagnostic {
7777
let span = attr.span().unwrap();
7878
let path = path_to_string(attr.path());
7979
match attr.meta {
80-
Meta::Path(_) => span_err(span, &format!("`#[{path}]` is not a valid attribute")),
81-
Meta::NameValue(_) => {
82-
span_err(span, &format!("`#[{path} = ...]` is not a valid attribute"))
83-
}
84-
Meta::List(_) => span_err(span, &format!("`#[{path}(...)]` is not a valid attribute")),
80+
Meta::Path(_) => span_err(span, format!("`#[{path}]` is not a valid attribute")),
81+
Meta::NameValue(_) => span_err(span, format!("`#[{path} = ...]` is not a valid attribute")),
82+
Meta::List(_) => span_err(span, format!("`#[{path}(...)]` is not a valid attribute")),
8583
}
8684
}
8785

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
200200

201201
throw_span_err!(
202202
attr.span().unwrap(),
203-
&format!(
203+
format!(
204204
"diagnostic slug must be first argument of a `#[{name}(...)]` attribute"
205205
)
206206
);

compiler/rustc_macros/src/diagnostics/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub(crate) trait HasFieldMap {
347347
None => {
348348
span_err(
349349
span.unwrap(),
350-
&format!("`{field}` doesn't refer to a field on this type"),
350+
format!("`{field}` doesn't refer to a field on this type"),
351351
)
352352
.emit();
353353
quote! {

0 commit comments

Comments
 (0)