Skip to content

Commit 503a633

Browse files
committed
Cleanup calls to layout_of
1 parent ce47e52 commit 503a633

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

clippy_lints/src/transmute.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use rustc::lint::*;
22
use rustc::ty::{self, Ty};
33
use rustc::hir::*;
4+
use rustc::ty::layout::LayoutOf;
45
use std::borrow::Cow;
56
use syntax::ast;
6-
use utils::{last_path_segment, match_def_path, paths, snippet, span_lint, span_lint_and_then,
7-
alignment};
7+
use utils::{last_path_segment, match_def_path, paths, snippet, span_lint, span_lint_and_then};
88
use utils::{opt_def_id, sugg};
99

1010
/// **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 {
220220
e.span,
221221
&format!("transmute from a type (`{}`) to itself", from_ty),
222222
),
223-
_ if alignment(cx, from_ty).map(|a| a.abi())
224-
< alignment(cx, to_ty).map(|a| a.abi())
223+
_ if cx.layout_of(from_ty).ok().map(|a| a.align.abi())
224+
< cx.layout_of(to_ty).ok().map(|a| a.align.abi())
225225
=> span_lint(
226226
cx,
227227
MISALIGNED_TRANSMUTE,

clippy_lints/src/utils/mod.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc::lint::{LateContext, Level, Lint, LintContext};
99
use rustc::session::Session;
1010
use rustc::traits;
1111
use rustc::ty::{self, Ty, TyCtxt};
12-
use rustc::ty::layout::Align;
12+
use rustc::ty::layout::LayoutOf;
1313
use rustc_errors;
1414
use std::borrow::Cow;
1515
use std::env;
@@ -1041,7 +1041,7 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
10411041
}
10421042

10431043
pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Option<u64> {
1044-
cx.tcx.layout_of(cx.param_env.and(ty))
1044+
cx.layout_of(ty)
10451045
.ok()
10461046
.map(|layout| layout.size.bytes())
10471047
}
@@ -1060,10 +1060,3 @@ pub fn get_arg_name(pat: &Pat) -> Option<ast::Name> {
10601060
_ => None,
10611061
}
10621062
}
1063-
1064-
/// Returns alignment for a type, or None if alignment is undefined
1065-
pub fn alignment<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Option<Align> {
1066-
cx.tcx.layout_of(cx.param_env.and(ty))
1067-
.ok()
1068-
.map(|layout| layout.align)
1069-
}

0 commit comments

Comments
 (0)