-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type inference suggests correction to non-existent variable __next
#51116
Comments
Well, declining to name the variable in this case would be simple enough— diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs
index 7352c14..25bfb3e 100644
--- a/src/librustc/infer/error_reporting/need_type_info.rs
+++ b/src/librustc/infer/error_reporting/need_type_info.rs
@@ -131,7 +131,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
labels.clear();
labels.push((pattern.span, format!("consider giving this closure parameter a type")));
} else if let Some(pattern) = local_visitor.found_local_pattern {
- if let Some(simple_name) = pattern.simple_name() {
+ // don't put internal desugared-loop identifier in user-facing
+ // message (Issue #51116)
+ let simple_name = pattern.simple_name().filter(|n| n.as_str() != "__next");
+ if let Some(simple_name) = simple_name {
labels.push((pattern.span, format!("consider giving `{}` a type", simple_name)));
} else {
labels.push((pattern.span, format!("consider giving the pattern a type"))); But more fundamentally, this isn't a good label to set on loops: we don't have syntax to type-annotate loop variables. |
The rust/src/librustc/hir/lowering.rs Lines 3355 to 3501 in 5ae5361
Agree, we should check for this case. |
…sakis Do not use desugared ident when suggesting adding a type Re rust-lang#51116.
Fixed in #52418. |
This code: (Playground link)
Fails with this error:
Type inference (rightfully) fails on this code. However, the variable that it suggests fixing is called
__next
and does not actually exist in my code. It is probably some internal variable generated by the compiler.The text was updated successfully, but these errors were encountered: