Skip to content

Commit 7b9ee11

Browse files
sasurau4lcnr
andcommitted
Enhance error message when misspelled label to value in break expression
Apply suggestions from code review Co-authored-by: lcnr <[email protected]>
1 parent e99a89c commit 7b9ee11

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,26 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
542542
err.span_label(base_span, fallback_label);
543543
}
544544
}
545+
if let Some(err_code) = &err.code {
546+
if err_code == &rustc_errors::error_code!(E0425) {
547+
for label_rib in &self.label_ribs {
548+
for (label_ident, _) in &label_rib.bindings {
549+
if format!("'{}", ident) == label_ident.to_string() {
550+
let msg = "a label with a similar name exists";
551+
// FIXME: consider only emitting this suggestion if a label would be valid here
552+
// which is pretty much only the case for `break` expressions.
553+
err.span_suggestion(
554+
span,
555+
&msg,
556+
label_ident.name.to_string(),
557+
Applicability::MaybeIncorrect,
558+
);
559+
}
560+
}
561+
}
562+
}
563+
}
564+
545565
(err, candidates)
546566
}
547567

0 commit comments

Comments
 (0)