Do not use desugared ident when suggesting adding a type
This commit is contained in:
parent
29ee65411c
commit
ed362c07ff
@ -4011,8 +4011,10 @@ 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_pat = self.pat_ident_binding_mode(
|
||||
pat.span,
|
||||
sp,
|
||||
next_ident,
|
||||
hir::BindingAnnotation::Mutable,
|
||||
);
|
||||
|
@ -412,6 +412,7 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::CompilerDesugaringKind {
|
||||
DotFill,
|
||||
QuestionMark,
|
||||
ExistentialReturnType,
|
||||
ForLoop,
|
||||
Catch
|
||||
});
|
||||
|
||||
|
@ -132,7 +132,12 @@ 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, format!("consider giving `{}` a type", 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(),
|
||||
}));
|
||||
} else {
|
||||
labels.push((pattern.span, format!("consider giving the pattern a type")));
|
||||
}
|
||||
|
@ -602,6 +602,7 @@ pub enum CompilerDesugaringKind {
|
||||
/// `impl Trait` with `Foo`.
|
||||
ExistentialReturnType,
|
||||
Async,
|
||||
ForLoop,
|
||||
}
|
||||
|
||||
impl CompilerDesugaringKind {
|
||||
@ -612,6 +613,7 @@ impl CompilerDesugaringKind {
|
||||
CompilerDesugaringKind::QuestionMark => "?",
|
||||
CompilerDesugaringKind::Catch => "do catch",
|
||||
CompilerDesugaringKind::ExistentialReturnType => "existential type",
|
||||
CompilerDesugaringKind::ForLoop => "for loop",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
24
src/test/ui/issue-51116.rs
Normal file
24
src/test/ui/issue-51116.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
let tiles = Default::default();
|
||||
for row in &mut tiles {
|
||||
for tile in row {
|
||||
//~^ NOTE consider giving this a type
|
||||
*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;
|
||||
}
|
14
src/test/ui/issue-51116.stderr
Normal file
14
src/test/ui/issue-51116.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
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
|
||||
LL | *tile = 0;
|
||||
| ^^^^^ cannot infer type for `_`
|
||||
|
|
||||
= note: type must be known at this point
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
Loading…
Reference in New Issue
Block a user