]> git.lizzy.rs Git - rust.git/commitdiff
less false positives for approx_const and float_cmp
authorllogiq <bogusandre@gmail.com>
Fri, 11 Sep 2015 13:30:08 +0000 (15:30 +0200)
committerllogiq <bogusandre@gmail.com>
Fri, 11 Sep 2015 13:30:08 +0000 (15:30 +0200)
src/approx_const.rs
src/misc.rs

index a132bc90361a56237d18fd8dc71e4916d27ecdd9..9a3d46c14bb10dcca6acec5fa1b378d16a7597f1 100644 (file)
@@ -1,8 +1,9 @@
 use rustc::lint::*;
+use rustc::metadata::cstore::crate_metadata;
 use rustc_front::hir::*;
 use syntax::codemap::Span;
+use std::borrow::Borrow;
 use std::f64::consts as f64;
-
 use utils::span_lint;
 
 declare_lint! {
@@ -31,6 +32,13 @@ fn get_lints(&self) -> LintArray {
 
     fn check_expr(&mut self, cx: &Context, e: &Expr) {
         if let &ExprLit(ref lit) = &e.node {
+            if let Some(res) = cx.tcx.def_map.borrow().get(&e.id) {
+                let krate = res.def_id().krate;
+                let cdata = &cx.sess().cstore.get_crate_data(krate);
+                let crate_data : &crate_metadata = cdata.borrow();
+                let name = &crate_data.name;
+                if name == "f32" || name == "f64" { return; }
+            }
             check_lit(cx, lit, e.span);
         }
     }
index 8891b000b59237e4a23bbec4bf89e502562a1f10..2cd6babb9c5902e32d4203fa021eca135d3759c4 100644 (file)
@@ -93,7 +93,7 @@ fn check_expr(&mut self, cx: &Context, expr: &Expr) {
                     return;
                 }
                 if let Some(name) = get_item_name(cx, expr) {
-                    if name == "eq" || name == "ne" ||
+                    if name == "eq" || name == "ne" || name == "is_nan" ||
                             name.as_str().starts_with("eq_") ||
                             name.as_str().ends_with("_eq") {
                         return;