mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-26 22:50:56 +00:00
Cleanup calls to layout_of
This commit is contained in:
parent
ce47e529d2
commit
503a63390d
2 changed files with 6 additions and 13 deletions
|
@ -1,10 +1,10 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::ty::{self, Ty};
|
||||
use rustc::hir::*;
|
||||
use rustc::ty::layout::LayoutOf;
|
||||
use std::borrow::Cow;
|
||||
use syntax::ast;
|
||||
use utils::{last_path_segment, match_def_path, paths, snippet, span_lint, span_lint_and_then,
|
||||
alignment};
|
||||
use utils::{last_path_segment, match_def_path, paths, snippet, span_lint, span_lint_and_then};
|
||||
use utils::{opt_def_id, sugg};
|
||||
|
||||
/// **What it does:** Checks for transmutes that can't ever be correct on any
|
||||
|
@ -220,8 +220,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||
e.span,
|
||||
&format!("transmute from a type (`{}`) to itself", from_ty),
|
||||
),
|
||||
_ if alignment(cx, from_ty).map(|a| a.abi())
|
||||
< alignment(cx, to_ty).map(|a| a.abi())
|
||||
_ if cx.layout_of(from_ty).ok().map(|a| a.align.abi())
|
||||
< cx.layout_of(to_ty).ok().map(|a| a.align.abi())
|
||||
=> span_lint(
|
||||
cx,
|
||||
MISALIGNED_TRANSMUTE,
|
||||
|
|
|
@ -9,7 +9,7 @@ use rustc::lint::{LateContext, Level, Lint, LintContext};
|
|||
use rustc::session::Session;
|
||||
use rustc::traits;
|
||||
use rustc::ty::{self, Ty, TyCtxt};
|
||||
use rustc::ty::layout::Align;
|
||||
use rustc::ty::layout::LayoutOf;
|
||||
use rustc_errors;
|
||||
use std::borrow::Cow;
|
||||
use std::env;
|
||||
|
@ -1041,7 +1041,7 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
|
|||
}
|
||||
|
||||
pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Option<u64> {
|
||||
cx.tcx.layout_of(cx.param_env.and(ty))
|
||||
cx.layout_of(ty)
|
||||
.ok()
|
||||
.map(|layout| layout.size.bytes())
|
||||
}
|
||||
|
@ -1060,10 +1060,3 @@ pub fn get_arg_name(pat: &Pat) -> Option<ast::Name> {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns alignment for a type, or None if alignment is undefined
|
||||
pub fn alignment<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Option<Align> {
|
||||
cx.tcx.layout_of(cx.param_env.and(ty))
|
||||
.ok()
|
||||
.map(|layout| layout.align)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue