Rollup merge of #59697 - euclio:label-fixes, r=zackmdavis
tweak unresolved label suggestion Only suggest label names in the same hygiene context, and use a structured suggestion. Question for reviewer: Is this the right way to check for label hygiene?
This commit is contained in:
commit
a552bebaf6
6 changed files with 32 additions and 9 deletions
|
@ -364,7 +364,12 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver<'_>,
|
|||
"use of undeclared label `{}`",
|
||||
name);
|
||||
if let Some(lev_candidate) = lev_candidate {
|
||||
err.span_label(span, format!("did you mean `{}`?", lev_candidate));
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"a label with a similar name exists in this scope",
|
||||
lev_candidate.to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
err.span_label(span, format!("undeclared label `{}`", name));
|
||||
}
|
||||
|
@ -4280,7 +4285,13 @@ impl<'a> Resolver<'a> {
|
|||
// Picks the first label that is "close enough", which is not necessarily
|
||||
// the closest match
|
||||
let close_match = self.search_label(label.ident, |rib, ident| {
|
||||
let names = rib.bindings.iter().map(|(id, _)| &id.name);
|
||||
let names = rib.bindings.iter().filter_map(|(id, _)| {
|
||||
if id.span.ctxt() == label.ident.span.ctxt() {
|
||||
Some(&id.name)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
find_best_match_for_name(names, &*ident.as_str(), None)
|
||||
});
|
||||
self.record_def(expr.id, err_path_resolution());
|
||||
|
|
|
@ -2,7 +2,7 @@ error[E0426]: use of undeclared label `'x`
|
|||
--> $DIR/hygienic-label-1.rs:2:19
|
||||
|
|
||||
LL | () => { break 'x; }
|
||||
| ^^ did you mean `'x`?
|
||||
| ^^ undeclared label `'x`
|
||||
...
|
||||
LL | 'x: loop { foo!() }
|
||||
| ------ in this macro invocation
|
||||
|
|
|
@ -2,7 +2,7 @@ error[E0426]: use of undeclared label `'x`
|
|||
--> $DIR/hygienic-label-2.rs:6:16
|
||||
|
|
||||
LL | foo!(break 'x);
|
||||
| ^^ did you mean `'x`?
|
||||
| ^^ undeclared label `'x`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ error[E0426]: use of undeclared label `'x`
|
|||
--> $DIR/hygienic-label-3.rs:2:19
|
||||
|
|
||||
LL | () => { break 'x; }
|
||||
| ^^ did you mean `'x`?
|
||||
| ^^ undeclared label `'x`
|
||||
...
|
||||
LL | foo!()
|
||||
| ------ in this macro invocation
|
||||
|
|
|
@ -2,7 +2,7 @@ error[E0426]: use of undeclared label `'x`
|
|||
--> $DIR/hygienic-label-4.rs:6:16
|
||||
|
|
||||
LL | foo!(break 'x);
|
||||
| ^^ did you mean `'x`?
|
||||
| ^^ undeclared label `'x`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -2,19 +2,31 @@ error[E0426]: use of undeclared label `'fo`
|
|||
--> $DIR/suggest-labels.rs:4:15
|
||||
|
|
||||
LL | break 'fo;
|
||||
| ^^^ did you mean `'foo`?
|
||||
| ^^^
|
||||
help: a label with a similar name exists in this scope
|
||||
|
|
||||
LL | break 'foo;
|
||||
| ^^^^
|
||||
|
||||
error[E0426]: use of undeclared label `'bor`
|
||||
--> $DIR/suggest-labels.rs:8:18
|
||||
|
|
||||
LL | continue 'bor;
|
||||
| ^^^^ did you mean `'bar`?
|
||||
| ^^^^
|
||||
help: a label with a similar name exists in this scope
|
||||
|
|
||||
LL | continue 'bar;
|
||||
| ^^^^
|
||||
|
||||
error[E0426]: use of undeclared label `'longlable`
|
||||
--> $DIR/suggest-labels.rs:13:19
|
||||
|
|
||||
LL | break 'longlable;
|
||||
| ^^^^^^^^^^ did you mean `'longlabel1`?
|
||||
| ^^^^^^^^^^
|
||||
help: a label with a similar name exists in this scope
|
||||
|
|
||||
LL | break 'longlabel1;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue