@@ -215,20 +215,43 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
215
215
item_name,
216
216
ty_string
217
217
) ;
218
- let snippet = tcx. sess . codemap ( ) . span_to_snippet ( expr. span )
219
- . unwrap_or ( "4" . to_string ( ) ) ;
220
218
let concrete_type = if actual. is_integral ( ) {
221
- "u32 "
219
+ "i32 "
222
220
} else {
223
221
"f32"
224
222
} ;
225
- err. span_suggestion ( expr. span ,
226
- & format ! ( "you must specify a concrete type for \
227
- this numeric value, like `{}`",
228
- concrete_type) ,
229
- format ! ( "({} as {})" ,
230
- snippet,
231
- concrete_type) ) ;
223
+ match expr. node {
224
+ hir:: ExprLit ( _) => { // numeric literal
225
+ let snippet = tcx. sess . codemap ( ) . span_to_snippet ( expr. span )
226
+ . unwrap_or ( "<numeric literal>" . to_string ( ) ) ;
227
+ // FIXME: use the literal for missing snippet
228
+
229
+ err. span_suggestion ( expr. span ,
230
+ & format ! ( "you must specify a concrete type for \
231
+ this numeric value, like `{}`",
232
+ concrete_type) ,
233
+ format ! ( "{}_{}" ,
234
+ snippet,
235
+ concrete_type) ) ;
236
+ }
237
+ hir:: ExprPath ( ref qpath) => { // local binding
238
+ if let & hir:: QPath :: Resolved ( _, ref path) = & qpath {
239
+ if let hir:: def:: Def :: Local ( node_id) = path. def {
240
+ let span = tcx. hir . span ( node_id) ;
241
+ let snippet = tcx. sess . codemap ( ) . span_to_snippet ( span)
242
+ . unwrap ( ) ;
243
+ err. span_suggestion ( span,
244
+ & format ! ( "you must specify a type for \
245
+ this binding, like `{}`",
246
+ concrete_type) ,
247
+ format ! ( "{}: {}" ,
248
+ snippet,
249
+ concrete_type) ) ;
250
+ }
251
+ }
252
+ }
253
+ _ => { }
254
+ }
232
255
err. emit ( ) ;
233
256
return ;
234
257
} else {
0 commit comments