Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix improper_ctypes lint for individual foreign items #53100

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,21 +790,18 @@ impl LintPass for ImproperCTypes {
}

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
fn check_foreign_item(&mut self, cx: &LateContext, it: &hir::ForeignItem) {
let mut vis = ImproperCTypesVisitor { cx: cx };
if let hir::ItemKind::ForeignMod(ref nmod) = it.node {
if nmod.abi != Abi::RustIntrinsic && nmod.abi != Abi::PlatformIntrinsic {
for ni in &nmod.items {
match ni.node {
hir::ForeignItemKind::Fn(ref decl, _, _) => {
vis.check_foreign_fn(ni.id, decl);
}
hir::ForeignItemKind::Static(ref ty, _) => {
vis.check_foreign_static(ni.id, ty.span);
}
hir::ForeignItemKind::Type => ()
}
let abi = cx.tcx.hir.get_foreign_abi(it.id);
if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic {
match it.node {
hir::ForeignItemKind::Fn(ref decl, _, _) => {
vis.check_foreign_fn(it.id, decl);
}
hir::ForeignItemKind::Static(ref ty, _) => {
vis.check_foreign_static(it.id, ty.span);
}
hir::ForeignItemKind::Type => ()
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/lint-ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ extern {
pub fn good15(p: TransparentLifetime);
pub fn good16(p: TransparentUnit<ZeroSize>);
pub fn good17(p: TransparentCustomZst);
#[allow(improper_ctypes)]
pub fn good18(_: &String);
}

#[allow(improper_ctypes)]
extern {
pub fn good19(_: &String);
}

#[cfg(not(target_arch = "wasm32"))]
Expand Down