Suggest 'a when given a only when appropriate
When encountering a name `a` that isn't resolved, but a label `'a` is found in the current ribs, only suggest `'a` if this name is the value expression of a `break` statement. Solve FIXME.
This commit is contained in:
@@ -547,15 +547,19 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
for label_rib in &self.label_ribs {
|
||||
for (label_ident, _) in &label_rib.bindings {
|
||||
if format!("'{}", ident) == label_ident.to_string() {
|
||||
let msg = "a label with a similar name exists";
|
||||
// FIXME: consider only emitting this suggestion if a label would be valid here
|
||||
// which is pretty much only the case for `break` expressions.
|
||||
err.span_suggestion(
|
||||
span,
|
||||
&msg,
|
||||
label_ident.name.to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
err.span_label(label_ident.span, "a label with a similar name exists");
|
||||
if let PathSource::Expr(Some(Expr {
|
||||
kind: ExprKind::Break(None, Some(_)),
|
||||
..
|
||||
})) = source
|
||||
{
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"use the similarly named label",
|
||||
label_ident.name.to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user