Skip to content

Commit 76b69a6

Browse files
committed
Auto merge of #53100 - VPashkov:issue-52456-improper_ctypes, r=eddyb
Fix improper_ctypes lint for individual foreign items Fixes #52456. r? @eddyb
2 parents 80caa7f + 70cafec commit 76b69a6

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/librustc_lint/types.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -790,21 +790,18 @@ impl LintPass for ImproperCTypes {
790790
}
791791

792792
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes {
793-
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
793+
fn check_foreign_item(&mut self, cx: &LateContext, it: &hir::ForeignItem) {
794794
let mut vis = ImproperCTypesVisitor { cx: cx };
795-
if let hir::ItemKind::ForeignMod(ref nmod) = it.node {
796-
if nmod.abi != Abi::RustIntrinsic && nmod.abi != Abi::PlatformIntrinsic {
797-
for ni in &nmod.items {
798-
match ni.node {
799-
hir::ForeignItemKind::Fn(ref decl, _, _) => {
800-
vis.check_foreign_fn(ni.id, decl);
801-
}
802-
hir::ForeignItemKind::Static(ref ty, _) => {
803-
vis.check_foreign_static(ni.id, ty.span);
804-
}
805-
hir::ForeignItemKind::Type => ()
806-
}
795+
let abi = cx.tcx.hir.get_foreign_abi(it.id);
796+
if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic {
797+
match it.node {
798+
hir::ForeignItemKind::Fn(ref decl, _, _) => {
799+
vis.check_foreign_fn(it.id, decl);
800+
}
801+
hir::ForeignItemKind::Static(ref ty, _) => {
802+
vis.check_foreign_static(it.id, ty.span);
807803
}
804+
hir::ForeignItemKind::Type => ()
808805
}
809806
}
810807
}

src/test/ui/lint-ctypes.rs

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ extern {
8888
pub fn good15(p: TransparentLifetime);
8989
pub fn good16(p: TransparentUnit<ZeroSize>);
9090
pub fn good17(p: TransparentCustomZst);
91+
#[allow(improper_ctypes)]
92+
pub fn good18(_: &String);
93+
}
94+
95+
#[allow(improper_ctypes)]
96+
extern {
97+
pub fn good19(_: &String);
9198
}
9299

93100
#[cfg(not(target_arch = "wasm32"))]

0 commit comments

Comments
 (0)