From 503a63390df10c6c025f1c1c514a232a0a163c38 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 5 Feb 2018 11:28:09 +0100 Subject: [PATCH] Cleanup calls to `layout_of` --- clippy_lints/src/transmute.rs | 8 ++++---- clippy_lints/src/utils/mod.rs | 11 ++--------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 090f9397472..2be5f4764f4 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -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, diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 161ce866fd7..75aa235ed3c 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -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 { - 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 { _ => 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 { - cx.tcx.layout_of(cx.param_env.and(ty)) - .ok() - .map(|layout| layout.align) -}