Update to rustc master
This commit is contained in:
@@ -2,18 +2,14 @@ use reexport::*;
|
||||
use rustc::hir::*;
|
||||
use rustc::hir::intravisit::FnKind;
|
||||
use rustc::lint::*;
|
||||
use rustc::middle::const_val::ConstVal;
|
||||
use rustc::ty;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc_const_eval::ConstContext;
|
||||
use rustc_const_math::ConstFloat;
|
||||
use syntax::codemap::{ExpnFormat, Span};
|
||||
use utils::{get_item_name, get_parent_expr, implements_trait, in_constant, in_macro, is_integer_literal,
|
||||
iter_input_pats, last_path_segment, match_qpath, match_trait_method, paths, snippet, span_lint,
|
||||
span_lint_and_then, walk_ptrs_ty};
|
||||
use utils::sugg::Sugg;
|
||||
use syntax::ast::{FloatTy, LitKind, CRATE_NODE_ID};
|
||||
use consts::constant;
|
||||
use syntax::ast::{LitKind, CRATE_NODE_ID};
|
||||
use consts::{constant, Constant};
|
||||
|
||||
/// **What it does:** Checks for function arguments and let bindings denoted as
|
||||
/// `ref`.
|
||||
@@ -457,58 +453,10 @@ fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) ->
|
||||
}
|
||||
|
||||
fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool {
|
||||
let parent_item = cx.tcx.hir.get_parent(expr.id);
|
||||
let parent_def_id = cx.tcx.hir.local_def_id(parent_item);
|
||||
let substs = Substs::identity_for_item(cx.tcx, parent_def_id);
|
||||
let res = ConstContext::new(cx.tcx, cx.param_env.and(substs), cx.tables).eval(expr);
|
||||
if let Ok(&ty::Const {
|
||||
val: ConstVal::Float(val),
|
||||
..
|
||||
}) = res
|
||||
{
|
||||
use std::cmp::Ordering;
|
||||
match val.ty {
|
||||
FloatTy::F32 => {
|
||||
let zero = ConstFloat {
|
||||
ty: FloatTy::F32,
|
||||
bits: u128::from(0.0_f32.to_bits()),
|
||||
};
|
||||
|
||||
let infinity = ConstFloat {
|
||||
ty: FloatTy::F32,
|
||||
bits: u128::from(::std::f32::INFINITY.to_bits()),
|
||||
};
|
||||
|
||||
let neg_infinity = ConstFloat {
|
||||
ty: FloatTy::F32,
|
||||
bits: u128::from(::std::f32::NEG_INFINITY.to_bits()),
|
||||
};
|
||||
|
||||
val.try_cmp(zero) == Ok(Ordering::Equal) || val.try_cmp(infinity) == Ok(Ordering::Equal)
|
||||
|| val.try_cmp(neg_infinity) == Ok(Ordering::Equal)
|
||||
},
|
||||
FloatTy::F64 => {
|
||||
let zero = ConstFloat {
|
||||
ty: FloatTy::F64,
|
||||
bits: u128::from(0.0_f64.to_bits()),
|
||||
};
|
||||
|
||||
let infinity = ConstFloat {
|
||||
ty: FloatTy::F64,
|
||||
bits: u128::from(::std::f64::INFINITY.to_bits()),
|
||||
};
|
||||
|
||||
let neg_infinity = ConstFloat {
|
||||
ty: FloatTy::F64,
|
||||
bits: u128::from(::std::f64::NEG_INFINITY.to_bits()),
|
||||
};
|
||||
|
||||
val.try_cmp(zero) == Ok(Ordering::Equal) || val.try_cmp(infinity) == Ok(Ordering::Equal)
|
||||
|| val.try_cmp(neg_infinity) == Ok(Ordering::Equal)
|
||||
},
|
||||
}
|
||||
} else {
|
||||
false
|
||||
match constant(cx, expr) {
|
||||
Some((Constant::F32(f), _)) => f == 0.0 || f.is_infinite(),
|
||||
Some((Constant::F64(f), _)) => f == 0.0 || f.is_infinite(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user