Change label span to point at iterator instead of iter item
This commit is contained in:
parent
ed362c07ff
commit
4c96932da7
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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")));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 `_`
|
||||
|
|
||||
|
|
Loading…
Reference in New Issue