Skip to content

Commit 693687a

Browse files
committed
improper_ctypes: extract some functions
1 parent d3aec9f commit 693687a

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/librustc_lint/types.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -640,27 +640,31 @@ impl LintPass for ImproperCTypes {
640640
}
641641
}
642642

643-
impl LateLintPass for ImproperCTypes {
644-
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
645-
fn check_ty(cx: &LateContext, ty: &hir::Ty) {
646-
let mut vis = ImproperCTypesVisitor { cx: cx };
647-
vis.visit_ty(ty);
648-
}
643+
fn check_ty(cx: &LateContext, ty: &hir::Ty) {
644+
let mut vis = ImproperCTypesVisitor { cx: cx };
645+
vis.visit_ty(ty);
646+
}
649647

650-
fn check_foreign_fn(cx: &LateContext, decl: &hir::FnDecl) {
651-
for input in &decl.inputs {
652-
check_ty(cx, &*input.ty);
653-
}
654-
if let hir::Return(ref ret_ty) = decl.output {
655-
let tty = ast_ty_to_normalized(cx.tcx, ret_ty.id);
656-
if !tty.is_nil() {
657-
check_ty(cx, &ret_ty);
658-
}
659-
}
648+
fn check_foreign_fn(cx: &LateContext, decl: &hir::FnDecl) {
649+
for input in &decl.inputs {
650+
check_ty(cx, &*input.ty);
651+
}
652+
if let hir::Return(ref ret_ty) = decl.output {
653+
let tty = ast_ty_to_normalized(cx.tcx, ret_ty.id);
654+
if !tty.is_nil() {
655+
check_ty(cx, &ret_ty);
660656
}
657+
}
658+
}
661659

660+
fn should_check_abi(abi: abi::Abi) -> bool {
661+
![abi::RustIntrinsic, abi::PlatformIntrinsic].contains(&abi)
662+
}
663+
664+
impl LateLintPass for ImproperCTypes {
665+
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
662666
if let hir::ItemForeignMod(ref nmod) = it.node {
663-
if nmod.abi != abi::RustIntrinsic && nmod.abi != abi::PlatformIntrinsic {
667+
if should_check_abi(nmod.abi) {
664668
for ni in &nmod.items {
665669
match ni.node {
666670
hir::ForeignItemFn(ref decl, _) => check_foreign_fn(cx, &**decl),

0 commit comments

Comments
 (0)