about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
diff options
context:
space:
mode:
authorxizheyin <xizheyin@smail.nju.edu.cn>2025-05-21 16:19:51 +0800
committerxizheyin <xizheyin@smail.nju.edu.cn>2025-05-21 16:23:52 +0800
commit84f67a5e51bf1695a0c368a9f44a15f15cdf6b9e (patch)
treea8e83591637aeb0acb9209590a9c2ded076fef3d /compiler/rustc_resolve/src
parent4ec991989af4662104fdbafc43b12232887fa0b4 (diff)
downloadrust-84f67a5e51bf1695a0c368a9f44a15f15cdf6b9e.tar.gz
rust-84f67a5e51bf1695a0c368a9f44a15f15cdf6b9e.zip
Downgrade the confident of suggestion `available field in format string` and optimize expression
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Diffstat (limited to 'compiler/rustc_resolve/src')
-rw-r--r--compiler/rustc_resolve/src/late/diagnostics.rs14
1 files changed, 4 insertions, 10 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs
index 30c2125d0b6..80d7a4dd47a 100644
--- a/compiler/rustc_resolve/src/late/diagnostics.rs
+++ b/compiler/rustc_resolve/src/late/diagnostics.rs
@@ -753,15 +753,9 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
                         if self_is_available {
                             let source_map = self.r.tcx.sess.source_map();
                             // check if the field is used in a format string, such as `"{x}"`
-                            let field_is_format_named_arg =
-                                source_map.span_to_source(span, |s, start, _| {
-                                    if let Some(expanded_expr) = s.get(start - 1..start)
-                                        && expanded_expr.starts_with("{")
-                                    {
-                                        Ok(true)
-                                    } else {
-                                        Ok(false)
-                                    }
+                            let field_is_format_named_arg = source_map
+                                .span_to_source(span, |s, start, _| {
+                                    Ok(s.get(start - 1..start) == Some("{"))
                                 });
                             if let Ok(true) = field_is_format_named_arg {
                                 err.help(
@@ -772,7 +766,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
                                     span.shrink_to_lo(),
                                     "you might have meant to use the available field",
                                     format!("{pre}self."),
-                                    Applicability::MachineApplicable,
+                                    Applicability::MaybeIncorrect,
                                 );
                             }
                         } else {