Don't suggest incorrect syntax
This commit is contained in:
parent
6ec1b626ba
commit
70c88e500c
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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}`
|
||||
}
|
||||
}
|
||||
|
@ -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`.
|
||||
|
Loading…
Reference in New Issue
Block a user