Skip to content

Commit

Permalink
Rollup merge of #112933 - TaKO8Ki:avoid-&format-in-error-message-code…
Browse files Browse the repository at this point in the history
…, r=oli-obk

Avoid `&format` in error message code

follow-up of #111633
  • Loading branch information
matthiaskrgr authored Jun 23, 2023
2 parents 3feee9f + c896062 commit 4e96aba
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
move_from_span: Span,
move_from_desc: &str,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
struct_span_err!(self, move_from_span, E0507, "cannot move out of {}", move_from_desc,)
struct_span_err!(self, move_from_span, E0507, "cannot move out of {}", move_from_desc)
}

/// Signal an error due to an attempt to move out of the interior
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_macros/src/diagnostics/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn path_to_string(path: &syn::Path) -> String {

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

Expand All @@ -77,11 +77,9 @@ pub(crate) fn invalid_attr(attr: &Attribute) -> Diagnostic {
let span = attr.span().unwrap();
let path = path_to_string(attr.path());
match attr.meta {
Meta::Path(_) => span_err(span, &format!("`#[{path}]` is not a valid attribute")),
Meta::NameValue(_) => {
span_err(span, &format!("`#[{path} = ...]` is not a valid attribute"))
}
Meta::List(_) => span_err(span, &format!("`#[{path}(...)]` is not a valid attribute")),
Meta::Path(_) => span_err(span, format!("`#[{path}]` is not a valid attribute")),
Meta::NameValue(_) => span_err(span, format!("`#[{path} = ...]` is not a valid attribute")),
Meta::List(_) => span_err(span, format!("`#[{path}(...)]` is not a valid attribute")),
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {

throw_span_err!(
attr.span().unwrap(),
&format!(
format!(
"diagnostic slug must be first argument of a `#[{name}(...)]` attribute"
)
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/diagnostics/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ pub(crate) trait HasFieldMap {
None => {
span_err(
span.unwrap(),
&format!("`{field}` doesn't refer to a field on this type"),
format!("`{field}` doesn't refer to a field on this type"),
)
.emit();
quote! {
Expand Down

0 comments on commit 4e96aba

Please sign in to comment.