Skip to content

improper_ctypes lint unaffected by lint attributes on the foreign items themselves. #52456

Closed
@eddyb

Description

@eddyb
// The attribute around the whole FFI block works.
#[allow(improper_ctypes)]
extern {
    // But this one on an individual FFI item doesn't.
    #[allow(improper_ctypes)]
    fn exit(_: &String);
}

The problem arises because the lint iterates over the children of ForeignMod (extern {...}):

fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
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 {

and it does so through check_item, but only check_foreign_item would be affected by attributes on the individual foreign fn / static / type children of the extern {...} block.
check_foreign_item could be used instead, with the small change that the abi has to be obtained from cx.tcx.hir.get_foreign_abi(ni.id), instead of nmod's field (as nmod would be gone).

cc @nikomatsakis @Manishearth

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions