diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2018-07-15 20:52:41 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@commure.com> | 2018-07-18 10:02:15 -0700 |
| commit | ed362c07ff95b34b091a6a719c881410e498eeb5 (patch) | |
| tree | 89bf51190ca21d89082b58e28e5f877804dfb245 /src | |
| parent | 29ee65411c46b8f701bd1f241725092cb1b347e6 (diff) | |
Do not use desugared ident when suggesting adding a type
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/hir/lowering.rs | 4 | ||||
| -rw-r--r-- | src/librustc/ich/impls_syntax.rs | 1 | ||||
| -rw-r--r-- | src/librustc/infer/error_reporting/need_type_info.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax_pos/hygiene.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/issue-51116.rs | 24 | ||||
| -rw-r--r-- | src/test/ui/issue-51116.stderr | 14 |
6 files changed, 50 insertions, 2 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 722934ac39a..358c64799d1 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -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, ); diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index fa9c5cefdf3..c9ac6cdedbb 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -412,6 +412,7 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::CompilerDesugaringKind { DotFill, QuestionMark, ExistentialReturnType, + ForLoop, Catch }); diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 773de8912ce..876faadb160 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -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"))); } diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index c7076478332..1531f030127 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -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", }) } } diff --git a/src/test/ui/issue-51116.rs b/src/test/ui/issue-51116.rs new file mode 100644 index 00000000000..0fdc51f29cc --- /dev/null +++ b/src/test/ui/issue-51116.rs @@ -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; +} diff --git a/src/test/ui/issue-51116.stderr b/src/test/ui/issue-51116.stderr new file mode 100644 index 00000000000..f2f116d47d8 --- /dev/null +++ b/src/test/ui/issue-51116.stderr @@ -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`. |
