diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 90680b4156e..59439d80bac 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -187,7 +187,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { out_of_scope_traits, lev_candidate, mode, - .. }) => { let tcx = self.tcx; @@ -264,13 +263,29 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let span = tcx.hir.span(node_id); let snippet = tcx.sess.codemap().span_to_snippet(span) .unwrap(); - err.span_suggestion(span, - &format!("you must specify a type for \ - this binding, like `{}`", - concrete_type), - format!("{}: {}", - snippet, - concrete_type)); + + let parent_node = self.tcx.hir.get( + self.tcx.hir.get_parent_node(node_id), + ); + let msg = format!( + "you must specify a type for this binding, like `{}`", + concrete_type, + ); + match parent_node { + hir_map::NodeLocal(hir::Local { + source: hir::LocalSource::Normal, + .. + }) => { + err.span_suggestion( + span, + &msg, + format!("{}: {}", snippet, concrete_type), + ); + } + _ => { + err.span_label(span, msg); + } + } } } } diff --git a/src/test/ui/suggestions/method-on-ambiguous-numeric-type.rs b/src/test/ui/suggestions/method-on-ambiguous-numeric-type.rs index 9bf74c3875f..42cfdb22c37 100644 --- a/src/test/ui/suggestions/method-on-ambiguous-numeric-type.rs +++ b/src/test/ui/suggestions/method-on-ambiguous-numeric-type.rs @@ -15,4 +15,8 @@ fn main() { let x = y.neg(); //~^ ERROR can't call method `neg` on ambiguous numeric type `{float}` println!("{:?}", x); + for i in 0..100 { + println!("{}", i.pow(2)); + //~^ ERROR can't call method `pow` on ambiguous numeric type `{integer}` + } } diff --git a/src/test/ui/suggestions/method-on-ambiguous-numeric-type.stderr b/src/test/ui/suggestions/method-on-ambiguous-numeric-type.stderr index 68c8be7dff8..417d7e8481d 100644 --- a/src/test/ui/suggestions/method-on-ambiguous-numeric-type.stderr +++ b/src/test/ui/suggestions/method-on-ambiguous-numeric-type.stderr @@ -18,6 +18,14 @@ help: you must specify a type for this binding, like `f32` LL | let y: f32 = 2.0; | ^^^^^^ -error: aborting due to 2 previous errors +error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}` + --> $DIR/method-on-ambiguous-numeric-type.rs:19:26 + | +LL | for i in 0..100 { + | - you must specify a type for this binding, like `i32` +LL | println!("{}", i.pow(2)); + | ^^^ + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0689`.