]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/ty/error.rs
wherein we suggest float for integer literals where a float was expected
[rust.git] / src / librustc / ty / error.rs
index bcbd8a529f6a7e9f87e6586e459c9ed1f92267a5..49fffaa375b2f705c91f891cdbdb24d38cb57433 100644 (file)
@@ -13,7 +13,7 @@
 use std::fmt;
 use rustc_target::spec::abi;
 use syntax::ast;
-use errors::DiagnosticBuilder;
+use errors::{Applicability, DiagnosticBuilder};
 use syntax_pos::Span;
 
 use hir;
@@ -250,6 +250,21 @@ pub fn note_and_explain_type_err(self,
                     db.note("no two closures, even if identical, have the same type");
                     db.help("consider boxing your closure and/or using it as a trait object");
                 }
+                match (&values.found.sty, &values.expected.sty) { // Issue #53280
+                    (ty::TyInfer(ty::IntVar(_)), ty::TyFloat(_)) => {
+                        if let Ok(snippet) = self.sess.codemap().span_to_snippet(sp) {
+                            if snippet.chars().all(|c| c.is_digit(10) || c == '-' || c == '_') {
+                                db.span_suggestion_with_applicability(
+                                    sp,
+                                    "use a float literal",
+                                    format!("{}.0", snippet),
+                                    Applicability::MachineApplicable
+                                );
+                            }
+                        }
+                    },
+                    _ => {}
+                }
             },
             OldStyleLUB(err) => {
                 db.note("this was previously accepted by the compiler but has been phased out");