Fix invalid_upcast_comparisons lint for same size sign casts

This commit is contained in:
Oliver Schneider
2017-03-02 10:41:20 +01:00
parent 7bfa53f504
commit 51295960bf
6 changed files with 243 additions and 84 deletions

View File

@@ -9,6 +9,7 @@ use rustc::traits::Reveal;
use rustc::traits;
use rustc::ty::subst::Subst;
use rustc::ty;
use rustc::ty::layout::TargetDataLayout;
use rustc_errors;
use std::borrow::Cow;
use std::env;
@@ -972,3 +973,9 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
None
}
pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>) -> Option<u64> {
cx.tcx.infer_ctxt((), Reveal::All).enter(|infcx|
ty.layout(&infcx).ok().map(|lay| lay.size(&TargetDataLayout::parse(cx.sess())).bytes())
)
}