about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@commure.com>2018-07-16 14:05:42 -0700
committerEsteban Küber <esteban@commure.com>2018-07-18 10:02:15 -0700
commit4c96932da75f46fe928959fba7e11cdd96de720e (patch)
tree7267a378b8a9bd7cb3e918f3551e81240b84428a
parented362c07ff95b34b091a6a719c881410e498eeb5 (diff)
downloadrust-4c96932da75f46fe928959fba7e11cdd96de720e.tar.gz
rust-4c96932da75f46fe928959fba7e11cdd96de720e.zip
Change label span to point at iterator instead of iter item
-rw-r--r--src/librustc/hir/lowering.rs8
-rw-r--r--src/librustc/infer/error_reporting/need_type_info.rs16
-rw-r--r--src/test/ui/issue-51116.rs4
-rw-r--r--src/test/ui/issue-51116.stderr4
4 files changed, 19 insertions, 13 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 358c64799d1..93fb282546b 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -4011,10 +4011,12 @@ impl<'a> LoweringContext<'a> {
                 let iter = self.str_to_ident("iter");
 
                 let next_ident = self.str_to_ident("__next");
-                let sp = self.allow_internal_unstable(CompilerDesugaringKind::ForLoop,
-                                                      pat.span);
+                let next_sp = self.allow_internal_unstable(
+                    CompilerDesugaringKind::ForLoop,
+                    head_sp,
+                );
                 let next_pat = self.pat_ident_binding_mode(
-                    sp,
+                    next_sp,
                     next_ident,
                     hir::BindingAnnotation::Mutable,
                 );
diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs
index 876faadb160..04d14f40b85 100644
--- a/src/librustc/infer/error_reporting/need_type_info.rs
+++ b/src/librustc/infer/error_reporting/need_type_info.rs
@@ -13,6 +13,7 @@ use hir::intravisit::{self, Visitor, NestedVisitorMap};
 use infer::InferCtxt;
 use infer::type_variable::TypeVariableOrigin;
 use ty::{self, Ty, TyInfer, TyVar};
+use syntax::codemap::CompilerDesugaringKind;
 use syntax_pos::Span;
 use errors::DiagnosticBuilder;
 
@@ -132,12 +133,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
             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_ident) = pattern.simple_ident() {
-                labels.push((
-                    pattern.span,
-                    match pattern.span.compiler_desugaring_kind() {
-                        None => format!("consider giving `{}` a type", simple_ident),
-                        _ => "consider giving this a type".to_string(),
-                    }));
+                match pattern.span.compiler_desugaring_kind() {
+                    None => labels.push((pattern.span,
+                                         format!("consider giving `{}` a type", simple_ident))),
+                    Some(CompilerDesugaringKind::ForLoop) => labels.push((
+                        pattern.span,
+                        "the element type for this iterator is not specified".to_string(),
+                    )),
+                    _ => {}
+                }
             } else {
                 labels.push((pattern.span, format!("consider giving the pattern a type")));
             }
diff --git a/src/test/ui/issue-51116.rs b/src/test/ui/issue-51116.rs
index 0fdc51f29cc..34217c6236c 100644
--- a/src/test/ui/issue-51116.rs
+++ b/src/test/ui/issue-51116.rs
@@ -12,13 +12,13 @@ fn main() {
     let tiles = Default::default();
     for row in &mut tiles {
         for tile in row {
-            //~^ NOTE consider giving this a type
+            //~^ NOTE the element type for this iterator is not specified
             *tile = 0;
             //~^ ERROR type annotations needed
             //~| NOTE cannot infer type for `_`
             //~| NOTE type must be known at this point
         }
     }
-    
+
     let tiles: [[usize; 3]; 3] = tiles;
 }
diff --git a/src/test/ui/issue-51116.stderr b/src/test/ui/issue-51116.stderr
index f2f116d47d8..0c38688340b 100644
--- a/src/test/ui/issue-51116.stderr
+++ b/src/test/ui/issue-51116.stderr
@@ -2,8 +2,8 @@ error[E0282]: type annotations needed
   --> $DIR/issue-51116.rs:16:13
    |
 LL |         for tile in row {
-   |             ---- consider giving this a type
-LL |             //~^ NOTE consider giving this a type
+   |                     --- the element type for this iterator is not specified
+LL |             //~^ NOTE the element type for this iterator is not specified
 LL |             *tile = 0;
    |             ^^^^^ cannot infer type for `_`
    |