Skip to content

Commit 4c96932

Browse files
author
Esteban Küber
committed
Change label span to point at iterator instead of iter item
1 parent ed362c0 commit 4c96932

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/librustc/hir/lowering.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,10 +4011,12 @@ impl<'a> LoweringContext<'a> {
40114011
let iter = self.str_to_ident("iter");
40124012

40134013
let next_ident = self.str_to_ident("__next");
4014-
let sp = self.allow_internal_unstable(CompilerDesugaringKind::ForLoop,
4015-
pat.span);
4014+
let next_sp = self.allow_internal_unstable(
4015+
CompilerDesugaringKind::ForLoop,
4016+
head_sp,
4017+
);
40164018
let next_pat = self.pat_ident_binding_mode(
4017-
sp,
4019+
next_sp,
40184020
next_ident,
40194021
hir::BindingAnnotation::Mutable,
40204022
);

src/librustc/infer/error_reporting/need_type_info.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use hir::intravisit::{self, Visitor, NestedVisitorMap};
1313
use infer::InferCtxt;
1414
use infer::type_variable::TypeVariableOrigin;
1515
use ty::{self, Ty, TyInfer, TyVar};
16+
use syntax::codemap::CompilerDesugaringKind;
1617
use syntax_pos::Span;
1718
use errors::DiagnosticBuilder;
1819

@@ -132,12 +133,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
132133
labels.push((pattern.span, format!("consider giving this closure parameter a type")));
133134
} else if let Some(pattern) = local_visitor.found_local_pattern {
134135
if let Some(simple_ident) = pattern.simple_ident() {
135-
labels.push((
136-
pattern.span,
137-
match pattern.span.compiler_desugaring_kind() {
138-
None => format!("consider giving `{}` a type", simple_ident),
139-
_ => "consider giving this a type".to_string(),
140-
}));
136+
match pattern.span.compiler_desugaring_kind() {
137+
None => labels.push((pattern.span,
138+
format!("consider giving `{}` a type", simple_ident))),
139+
Some(CompilerDesugaringKind::ForLoop) => labels.push((
140+
pattern.span,
141+
"the element type for this iterator is not specified".to_string(),
142+
)),
143+
_ => {}
144+
}
141145
} else {
142146
labels.push((pattern.span, format!("consider giving the pattern a type")));
143147
}

src/test/ui/issue-51116.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ fn main() {
1212
let tiles = Default::default();
1313
for row in &mut tiles {
1414
for tile in row {
15-
//~^ NOTE consider giving this a type
15+
//~^ NOTE the element type for this iterator is not specified
1616
*tile = 0;
1717
//~^ ERROR type annotations needed
1818
//~| NOTE cannot infer type for `_`
1919
//~| NOTE type must be known at this point
2020
}
2121
}
22-
22+
2323
let tiles: [[usize; 3]; 3] = tiles;
2424
}

src/test/ui/issue-51116.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ error[E0282]: type annotations needed
22
--> $DIR/issue-51116.rs:16:13
33
|
44
LL | for tile in row {
5-
| ---- consider giving this a type
6-
LL | //~^ NOTE consider giving this a type
5+
| --- the element type for this iterator is not specified
6+
LL | //~^ NOTE the element type for this iterator is not specified
77
LL | *tile = 0;
88
| ^^^^^ cannot infer type for `_`
99
|

0 commit comments

Comments
 (0)