summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_builtin_macros/src/format.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /compiler/rustc_builtin_macros/src/format.rs
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_builtin_macros/src/format.rs')
-rw-r--r--compiler/rustc_builtin_macros/src/format.rs37
1 files changed, 23 insertions, 14 deletions
diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs
index ede95dbf8..8397b5e42 100644
--- a/compiler/rustc_builtin_macros/src/format.rs
+++ b/compiler/rustc_builtin_macros/src/format.rs
@@ -260,20 +260,29 @@ fn make_format_args(
if let Some((label, span)) = err.secondary_label && is_source_literal {
e.label_ = Some(errors::InvalidFormatStringLabel { span: fmt_span.from_inner(InnerSpan::new(span.start, span.end)), label } );
}
- if err.should_be_replaced_with_positional_argument {
- let captured_arg_span =
- fmt_span.from_inner(InnerSpan::new(err.span.start, err.span.end));
- if let Ok(arg) = ecx.source_map().span_to_snippet(captured_arg_span) {
- let span = match args.unnamed_args().last() {
- Some(arg) => arg.expr.span,
- None => fmt_span,
- };
- e.sugg_ = Some(errors::InvalidFormatStringSuggestion {
- captured: captured_arg_span,
- len: args.unnamed_args().len().to_string(),
- span: span.shrink_to_hi(),
- arg,
- });
+ match err.suggestion {
+ parse::Suggestion::None => {}
+ parse::Suggestion::UsePositional => {
+ let captured_arg_span =
+ fmt_span.from_inner(InnerSpan::new(err.span.start, err.span.end));
+ if let Ok(arg) = ecx.source_map().span_to_snippet(captured_arg_span) {
+ let span = match args.unnamed_args().last() {
+ Some(arg) => arg.expr.span,
+ None => fmt_span,
+ };
+ e.sugg_ = Some(errors::InvalidFormatStringSuggestion::UsePositional {
+ captured: captured_arg_span,
+ len: args.unnamed_args().len().to_string(),
+ span: span.shrink_to_hi(),
+ arg,
+ });
+ }
+ }
+ parse::Suggestion::RemoveRawIdent(span) => {
+ if is_source_literal {
+ let span = fmt_span.from_inner(InnerSpan::new(span.start, span.end));
+ e.sugg_ = Some(errors::InvalidFormatStringSuggestion::RemoveRawIdent { span })
+ }
}
}
ecx.emit_err(e);