Skip to content

Commit 84f67a5

Browse files
committed
Downgrade the confident of suggestion available field in format string and optimize expression
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
1 parent 4ec9919 commit 84f67a5

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -753,15 +753,9 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
753753
if self_is_available {
754754
let source_map = self.r.tcx.sess.source_map();
755755
// check if the field is used in a format string, such as `"{x}"`
756-
let field_is_format_named_arg =
757-
source_map.span_to_source(span, |s, start, _| {
758-
if let Some(expanded_expr) = s.get(start - 1..start)
759-
&& expanded_expr.starts_with("{")
760-
{
761-
Ok(true)
762-
} else {
763-
Ok(false)
764-
}
756+
let field_is_format_named_arg = source_map
757+
.span_to_source(span, |s, start, _| {
758+
Ok(s.get(start - 1..start) == Some("{"))
765759
});
766760
if let Ok(true) = field_is_format_named_arg {
767761
err.help(
@@ -772,7 +766,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
772766
span.shrink_to_lo(),
773767
"you might have meant to use the available field",
774768
format!("{pre}self."),
775-
Applicability::MachineApplicable,
769+
Applicability::MaybeIncorrect,
776770
);
777771
}
778772
} else {

0 commit comments

Comments
 (0)